My intro into IoT – 03

In my previous intro article, you setup the drivers for the ESP module. Next:

Firmware

Next, you’ll need to install the firmware on the NodeMCU board. Go to NodeMCU build side – https://nodemcu-build.com/ leave the master branch selected and, for required modules, what’s selected should be enough. If you’ll need more, try to select only what’s needed, in order to keep your firmware as small as possible. Flashing too many modules can sometimes lead to booting issues.

On my projects, besides what’s standard, I’ve also used am2320 and dht (for temperature and humidity sensors), the http module (provides an interface to do GET/POST/PUT/DELETE) and in the end, for communication, I switched to using the mqtt module.

So, once you select your modules, enter your email address, scroll to the bottom of the page and click “Start your build”. You should receive an email, letting you know that the build started, and, after a few minutes, another one with your build.

There will be options to download two versions: an integer one (that’s smaller and faster, but with some issues) or a float one. According to NodeMCU docs: “Our integer builds have a smaller Flash footprint and execute faster, but working in integer also has a number of pitfalls, so our general recommendation is to use floating point builds.” – so we’ll just use the floating point version.

After downloading, we’ll have to flash that on to the board. Use Python and pip to install esptool:

sudo pip install esptool

Connect your board to the computer, you’ll see the blue light flash right after connection and run the following command to upload the firmware

esptool.py --port=/dev/cu.SLAB_USBtoUART write_flash -fm=dio -fs=32m 0x00000 nodemcu-master-10-modules-2018-06-22-02-40-34-float.bin

The port should be “/dev/cu.SLAB_USBtoUART” for CP2102 driver or “/dev/cu.wchusbserial1420” for CH340G. If you’re unsure, go to the terminal, type “ls /dev/cu.” and press TAB, you should see what device is connected. The .bin file should be the one that you’ve just generated on NodeMCU custom build website and downloaded from your email.

About coding 🙂

arduino ide

Programming the NodeMCU can be done in two ways: using the default scripting language, Lua, that’s somehow similar to Node.js OR use C++ and Arduino IDE for writing code. I personally liked more using Arduino IDE, and I sticked to that.

So, download and install Arduino IDE. Next, we’ll need to instruct the IDE of our board, so open Arduino menu, select Preferences and in the field “Additional Boards Manager URLs copy and paste the following link

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Click OK and restart the Arduino IDE. After restart, when going to “Tools” menu, in “Board” you should be able to select “Generic ESP8266 Module”.

Depending on your sensors, you could find lots of code examples in “File” – “Examples” menu, under the section “Examples for Generic ESP8266 Module”.

That should be it… to get you started 🙂 Follow up, to see about the Raspberry Pi setup as a hub.

Leave a Reply

Your email address will not be published. Required fields are marked *