Trying to give an MCU WiFi capability to connect it to the IoT to use a smartphone app. What would be easiest or the most common way to achieve this?

Thread Starter

BrettC

Joined Mar 19, 2022
7
I am new to MCU technology and am trying to use an app for a smartphone that would allow it to be connected to the MCU through the IoT. I think I understand that I can connect my MCU to my home network using a WiFi module, but I am still confused on how I would then allow it to be used by the smartphone app from anywhere. The MCUs I have been looking to do this project with are the Arduino Mega 2560 Rev3, and MSP4306989. Would I have to host a website/domain where the connection could occur?
 

Jon Chandler

Joined Jun 12, 2008
191
Look for tutorials on using ESP8266 or ESP32 modules for IoT apps. They are an MCU with WiFi (and Bluetooth for the ESP32) built-in and are the basis of many commercial IoT devices.


They can be programed using the Arduino IDE if you add the needed libraries – again, many tutorials explain how to do this.
 

BobTPH

Joined Jun 5, 2013
4,899
I am using an ESP8266 module wit a PIC24 MCU. Quite satisfied with it for my low bandwidth application. They communicate via UART, so you won’t get megabits with that setup.

The interface is simple text commands. Arduino has libraries for these.

Bob
 

BobTPH

Joined Jun 5, 2013
4,899
In answer to the last part of your post. The MCU hosts a web site and the phone communicates with the browser. There are other ways to do it, but this is the simplest.

Bob
 

GetDeviceInfo

Joined Jun 7, 2009
2,095
Your Ethernet enabled device can communicate with your phone directly, as a server, or, through your router, as a node in your local network. Beyond your local network, you can address the device if you can address your router. There in lies a problem. If you are assigned a static address by your service provider, you know where to go. If it’s dynamic, which it typically is for residential serviced, your address is constantly changing, making access a challenge.
 

Thread Starter

BrettC

Joined Mar 19, 2022
7
I am using an ESP8266 module wit a PIC24 MCU. Quite satisfied with it for my low bandwidth application. They communicate via UART, so you won’t get megabits with that setup.

The interface is simple text commands. Arduino has libraries for these.

Bob
I think I am going to use the MSP430 for this project with the CC3100 module. I am only going to be issuing simple commands to the device. I would also want to put this onto a PCB, would that be an issue?
 
Along the lines of access outside your home network... Cable modems (that I have used) tend to keep the same address as long as it doesn't loose power. I was on a DSL connection for a while where the address was a local address within the ISP's network. No simple way to connect from the outside on that one.
 

Ya’akov

Joined Jan 27, 2019
5,659
I am new to MCU technology and am trying to use an app for a smartphone that would allow it to be connected to the MCU through the IoT. I think I understand that I can connect my MCU to my home network using a WiFi module, but I am still confused on how I would then allow it to be used by the smartphone app from anywhere. The MCUs I have been looking to do this project with are the Arduino Mega 2560 Rev3, and MSP4306989. Would I have to host a website/domain where the connection could occur?
Welcome to AAC.

MCUs are a great area to learn, it opens up a world of possibility and simplifies so many things. How much have you already learned? Have you used the Arduino ecosystem? What do you know about circuits, are you comfortable with designing the connections to sensor and peripherals that might need to interface to the MCU?

Without the answers to those questions, I will answer as if you are a complete neophyte. The project you've described is trivial if you have the knowledge of the parts but cold become quite a morass to a beginner if you don't have the help of already written code and and an easy tool chain.

That in mind, my best advice is, first, to start with the Arduino IDE whatever MCU you choose. So, of course that means choosing something compatible with it. There are many choices beyond the Arduino designed boards and their clones. Some of which make more sense than others.

If you are not an accomplished C/C++ programmer, jumping into a traditional MCU toolchain means a lot more to learn. Not only the language but the nitpicking housekeeping of all the moving parts. The Arduino environment hides most of that and lets you simply write programs for your MCU.

At the highest level of abstraction you will need to know very little that is toolchain-specific to make an Arduino compatible MCU "work" using the IDE. This is a great learning curve flattener. But, nothing prevents you from progressively digging deeper into the internals and eventually even jumping to a less "friendly" toolchain. What is hidden in the Arduino environment is only behind some curtains, easily pushed aside, and so you can touch anything you want.

As far as specific MCU selection since you have a need for WiFi connectivity, it makes sense to choose an MCU which has that capability on-board. Considering this and other factors, my first suggestion is the Wemos D1 Mini. It's low cost, well supported in the Arduino IDE, and capable enough for most things. It's based on the Espressif ESP-8266 which is very flexible and very popular with a lot of resources for help.

The D1 Mini has fewer IO pins installed and so the only reason I would choose something else is if you needed a lot of IO, but my impression is that is not the case. You can buy the D1 Mini directly or one of the many clones. Amazon has some listed, but it is my practice to buy at least some from the designers (in this case LOLIN) to help support their work. I usually buy both direct and clones in practice.

As far as apps and connectivity is concerned you have quite a large area of possibility there. The most straightforward from a self-service point of view is to run an httpd (web server) on the MCU (there are many examples for the ESP-8266) and use your phone's we browser to talk to it. But, it's not the only choice as I will discuss in a bit.

As far as remote access in the case of the web-based approach, you must have some way to talk to the device on your network from somewhere else. You could use an external web server as a gateway by having the remote user talk to it, and the MCU connected to it via web sockets or some other persistent connection and have realtime commiunication. This is only needed if you need fast response times. These methods can be called push, that is, the data is pushed to your device.

On the other hand pull methods are a possibility. In this case your program periodically requests a URL from the outside web server which delivers outstanding requests from the phone client. It can, in turn send back data via the web server to the client. This will work, but it can be awkward if response times become too long. If the polling interval is very short, it will make things more responsive but be very "noisy" in terms of packets. It will not exchange much data, though, and would be nothing to worry about with a modern broadband connection.

I said I would discuss alternatives and the suggestion on the top of that list for you is Blynk. Blynk offers a way to create native apps for iOS or Android, and to connect your device to a cloud service without you worrying about where it is connected to WiFi. They have a very slick product and a free tier. Even if you wanted to try the more self-reliant method, starting with Blynk would greatly simplify your project and get it on the air much more quickly. It is a great product.

If you have any questions about the foregoing please don't hesitate to ask. If you have any questions about other methods or choices, they are also welcome. Good luck with MCUs, and have fun.
 

jayanthd

Joined Jul 4, 2015
945
I think I am going to use the MSP430 for this project with the CC3100 module. I am only going to be issuing simple commands to the device. I would also want to put this onto a PCB, would that be an issue?
The better modules are Arduino Nano 33 BLE SENSE, Arduino Nano 33 IoT, Arduino RP2040. All with built-in WiFi and BLE. 33 BLE board running at 48 to 84 mhz and RP2040 board running at 133mhz.

Another board with WiFi and BLE is Arduino MKR 1010.
 
Top