I’ve been playing around with Arduino’s and things now for a few years on and off. Although I’ve dabbled in electronics before, I was completely new to the world of micro-controllers and C++.
Initially, very cool.. you could have a bit of logic behind some buttons, lights and sensors etc without having to be an electronics guru. And with the thousands of libraries and example of Arudino sketches that do everything from talking to cars via CANBUS to controlling motors and reading sensors, this is a great way to get started in the world of IoT. Even if you’re knowledge of C++ is VERY limited like when I started, the scripts you can get show you a lot on the way of how things work,.. and you can generally google a question and someone has an answer…
A lot of what I wanted to do relies on communicating with other things, so pretty early in to playing around with it all, I wanted to get some WiFi working and get these Arduino boards collecting some data and maybe uploading it to a database over the web.
I discovered the ESP8266 WIFI Chip.
I am really interested in what could be done with these super low cost chips, because of just that – they are a few dollars, not $50+ just for some comms.
I know people are all over Raspberry PI’s, but to me they are just a computer from 10 years ago running Linux. Sure, they have their places for media players and all sorts of more advanced IoT bits and pieces where all that computing power is needed, but for low cost little things that do a simple job like controlling a relay or measuring a temperature, they seem over kill and are expensive.
When I first started with it all, these ESP8266 WiFi Chips that retail for a few dollars had just come out. Initially I spent hours wiring these things up to pins on an Arduino board and sending AT commands to the chip to get responses and things.. and when I say hours, I mean HOURS. No matter what I did though, I always found them a bit flaky, I could get basic things to work but if I left them running overnight or for a few days, the WiFi chip would have locked up or dropped off, or reset.. The alternative was chips like Ti C3300 but they are all a lot more expensive…
I kind of gave up on it all for a while as I didn’t think you could ever really make anything serious with them.
I’m glad I did to be honest. Because, when I came back to it 7-8 months later, the game had changed, significantly…
The first and foremost thing that happened is that some clever people got the actual Arduino concept (C++, Arduino IDE to code in, whole stack of cool libraries that do cool stuff) running directly on the ESP8266 chips themselves, so you didn’t have to wire up an Arduino to and ESP8266 over serial (or software serial), you just wrote code and uploaded to the one ESP8266 chip.
The ESP8266 has a much faster processor (80mhz) than the Atmel processors on the Arduino’s + a lot more memory to run your sketches in.
Also, boards like the NodeMCU had come out that were essentially an ESP8266 on a nice little development board with a USB <> RS232 adapter baked in, all the voltages right etc. (as Arduino was 5v and ESP8266 is 3.3v so you had to mess about with level shifters etc..) – just plug in to your USB port and go without having to build a circuit with Arduino, ESP8266 (that was not friendly to mount on a breadboard – some of them anyway), voltage dividers to step voltage down on data pins, blah blah.. etc etc..
The second thing, was that no more did you need to use AT commands like your talking to some modem from the 1980’s. Someone had written some nice ESP8266 libraries you can just include in your sketches and get going with just a few lines of code. I’d ordered a bunch of NodeMCU boards from Aliexpress but still found that they would do funny things and not be reliable.
Then in my sniffing around the internet, I discovered the smaller Wemos boards that also had an ESP8266 but they were the ones with the nice metal can over the wifi chip to make them more compliant and the whole package is quite a bit smaller.
Since working with these modules now, things are solid. I don’t know if the NodeMCU boards I had just had flaky ESP8266 chips or power supply components.. but finally after messing about with this stuff for a couple of years, I had a reliable setup..
So if anyone wants to fast forward the messing about I’ve done and get stuck in to building something small and Wifi capable using the Arduino community and libraries, here is a list of things I have learnt messing about with all the different versions of this stuff.
I also found this great tool that gives you a ready to go WiFi Setup system for your widget.. from a phone, you just connect to the Ad-Hoc network your board creates and it automatically brings up a page to join your main WiFi Network – then device reboots and connects to said network.. makes it so easy!
This is a good place to start your development.
- Get yourself the latest Arduino IDE
- Get your self a WeMOS board – $4.00 US!! – $5.76 delivered to your door here in NZ.
- Maybe get your self a Wemos Shield – they stack on WeMOS without any wiring, there are things like temperature sensors, little OLED screens, relays etc:
Install Arduino IDE
Go in to Board Manager in IDE and search for Wemos – Install the esp8266 board pack that includes setup for the Wemos board
From the top menu – Sketch > Include Libraries – Manage Library – go and find and install WiFiManager
Just to test things are working end to end, load the Example Project Blink from the ESP8266 sub menu in the File > Examples menu
Plugin your Wemos board.. On Windows it should plug and play the serial driver and appear as a new com port.
From the Tools menu, select the Wemos board and select the COM port your Wemos is on.
Upload the sketch to the WeMos just like you would an Arduino and confirm the light starts blinking!!
One thing to note here, i had a lot of faffing around with sketches intermittently not uploading to the Wemos.. the process just saying failed.
What i figured out is that you are mean to ground Pin D3 on the Wemos to put it in to flash mode.Sometimes it will upload/flash without you having to ground this pin, but once you get a sketch on there and you’re recompiling and uploading, it can get a bit finiky.
So remember to short between D3 and Ground when uploading sketch, and then take the short off to run.
If you’ve got to here, great!!
Now, lets get some basic WiFi happening and the WiFi Manager which manages setting up the WiFi connection simply without hard coding into sketches.
In the Examples, find WiFi Manager (should be there if you installed it earlier from the library). Maybe restart the IDE if you dont see it.
Load the AutoConnectWithFeedbackLED sketch and upload this to your Wemos.
Once the project is uploaded successfully, power off and on the Wemos.
Give it 20 seconds or so to start and look for Wifi networks. Then open up your phone (in my case iPhone). go to your WiFi networks and choose the ESP….. – whatever your chip is called by default. You will then see the browser on the phone pop and navigate to http://192.168.4.1 – the default IP of the ESP8266. It will DHCP your phone/device an address and auto-pop up a config page. How cool is that! From here you can find your home Wifi network and connect with SSID/Pass. Once you save, the device reboots and connects to the AP. If it fails, it connects back to this setup config mode
If you have a console connected to the serial port the Wemos is on (default 115,200 baud rate), you will see the chip start, connect to your network and get an IP Address.
From here, the world is your oyster as they say. You can measure sensors, send results to web services etc etc..
I thought this was a pretty cool place to start off though.. it has taken years of messing around with different aspects of this, but this above process is now the basis for any of my IoT ideas now.
How i’d wish it had been this easy a couple of years ago back in the day of soldering up boards with level shifters and connecting arduino nano’s to ESP8266 chips through level shifters and then sending a whole bunch of AT commands just to get something to happen….hours of messing around can now be sorted in less than 5 minutes once you are all setup.
The little Wemos shields too instantly give you temp sensors, relays, screens and all sorts of other things you can interact with.. like arudino shields but nice and small
Hope that helps someone get started in the wonderful world of IoT.