In Part 1 of this article we looked at preparation and IoT tool selection, getting all tools ready. In this post will set up our development environment and make NodeMCU alive with some code.
NodeMCU is an open-source firmware and development kit that helps you to prototype or build IoT products. It is based on the lowest cost WI-FI MCU ESP8266, ESP8266 is about $2 and once it comes as NodeMCU easy to prototype development kit you can purchase for about $4 something you can connect to your USB and start playing with it. Working with ESP8266 and NodeMCU can be very easy, or very challenging! I've been fortunate to have good luck but I've fielded may questions from people that have been having trouble. If you are on a Mac (or Linux), unfortunately there are not as many GUI options as there are on Windows. There is however one solid option that has been my go to method.
I will use ready NodeMCU unit with mini USB connector to link this to my MAC. But before that we need to do some configuration.
To locate the drivers you want to install for a device, select which of the driver types you wish to use (VCP or D2XX) and then locate the appropriate operating systems. With the exception of Windows 98 and Windows ME, all devices are supported in each driver package. If a VCP driver is required for Android please refer to the following.
- Install and configure Arduino IDE
- Add Arduino ESP8266 extension to IDE
- Install USB drivers
- Test the unit commnication with IDE
- Load some code to test
Install Arduino IDE download can be found here, download and install the version you need, I use MAC OSX version. Once you launch the IDE it will typically launch with sample loaded Sketch program for popular LED Blink code. A simple Sketch makes LED on/off blinking with some delay.
When I connected my NodeMCU unit to USB it has on board blue LED and it strated blinking before I loaded anythnig. The maker of this unit Oddwires have preloaded that script on NodeMCU and that is ok. Good test to know device is working or not.
Next step we need to add Arduino ESP8266 extension to our IDE for development. Select IDE Arduino > Preferences from menu and enter http://arduino.esp8266.com/stable/package_esp8266com_index.json
into the Additional Board Manager URLs field. This will add number of selections to IDE's Tools->Board menu options
Vcp Driver Nodemcu For Mac Download
Open Boards Manager from Tools -> Board menu and install esp8266 platform and select NodeMCU 1.0(ESP-12E Module) from Tools > Board menu, after installation. This module corresponds to new NodeMCU development kit 2.0.
Vcp Driver Nodemcu For Mac Windows 10
Now we need to add USB communictaion to IDE to flash code to NodeMCU. In last post I have mentioned that this dev-kit was built based on CP2102 USB UART chip. We need to install signed drivers for Mac OSX from Silicon Labs CP210x USB to UART Bridge VCP Drivers. You will need to restart MAC OSX for this to take effect after install.Connect NodeMCU unit with mini USB cable to MAC the LED will start blinking indicating normall power and working unit. In the IDE Tools -> Port menu select the Port for your device. In my case I made following selection depending on device:
- Upload Speed 115200 fo this unit
- Flash Size: 4M (3M SPIFFS)
- Port: /dev/cu.SLAB_USBtoUART
Note that Port will not show if device is not connected. Also if you do not see this or similar port selection this means that you do not have correct USB drivers. I had to tinker with this a little by reinstalling USB driver and restarting MAC and reconnecting unit. At this point these selectinos should be all good. Try to change delay(2000);
compile Blink sketch.
Now lets try loading this sketch on our device.
After this code loaded, NodeMCU blue LED will start blinking with delay that we set in the code.While this is successful test we can agree blinking LED is not very exciting.
Lets try something more interesting like connect NodeMCU to WiFi and send remote commands to this device. Will make 2 endpoints to turn our LED On/Off on URL command. We can use one of examples provided with ESP8266 extensions, open File > Eamples > ESP8266WebServer
select HelloServer
. This is a simple HTTP sever example code to setup our commands. Here is a full source code:
Note that on-board LED is contrlled with simple commands
Vcp Driver Nodemcu For Mac Installer
We have added 2 small methods mapped to URL path /on & /off
to control LED switching.
Open serial monitor window Tools > Serial Monitor
and upload this code to NodeMCU, you will see load progress. If you doing this first time after this load we need ot restart NodeMCU device by disconnect power/unplug MCU. After upload the server will start on device. The Monitor window will print a welcome message along with IP address that we can use to send command to our new IoT device.
I will use ready NodeMCU unit with mini USB connector to link this to my MAC. But before that we need to do some configuration.
To locate the drivers you want to install for a device, select which of the driver types you wish to use (VCP or D2XX) and then locate the appropriate operating systems. With the exception of Windows 98 and Windows ME, all devices are supported in each driver package. If a VCP driver is required for Android please refer to the following.
- Install and configure Arduino IDE
- Add Arduino ESP8266 extension to IDE
- Install USB drivers
- Test the unit commnication with IDE
- Load some code to test
Install Arduino IDE download can be found here, download and install the version you need, I use MAC OSX version. Once you launch the IDE it will typically launch with sample loaded Sketch program for popular LED Blink code. A simple Sketch makes LED on/off blinking with some delay.
When I connected my NodeMCU unit to USB it has on board blue LED and it strated blinking before I loaded anythnig. The maker of this unit Oddwires have preloaded that script on NodeMCU and that is ok. Good test to know device is working or not.
Next step we need to add Arduino ESP8266 extension to our IDE for development. Select IDE Arduino > Preferences from menu and enter http://arduino.esp8266.com/stable/package_esp8266com_index.json
into the Additional Board Manager URLs field. This will add number of selections to IDE's Tools->Board menu options
Vcp Driver Nodemcu For Mac Download
Open Boards Manager from Tools -> Board menu and install esp8266 platform and select NodeMCU 1.0(ESP-12E Module) from Tools > Board menu, after installation. This module corresponds to new NodeMCU development kit 2.0.
Vcp Driver Nodemcu For Mac Windows 10
Now we need to add USB communictaion to IDE to flash code to NodeMCU. In last post I have mentioned that this dev-kit was built based on CP2102 USB UART chip. We need to install signed drivers for Mac OSX from Silicon Labs CP210x USB to UART Bridge VCP Drivers. You will need to restart MAC OSX for this to take effect after install.Connect NodeMCU unit with mini USB cable to MAC the LED will start blinking indicating normall power and working unit. In the IDE Tools -> Port menu select the Port for your device. In my case I made following selection depending on device:
- Upload Speed 115200 fo this unit
- Flash Size: 4M (3M SPIFFS)
- Port: /dev/cu.SLAB_USBtoUART
Note that Port will not show if device is not connected. Also if you do not see this or similar port selection this means that you do not have correct USB drivers. I had to tinker with this a little by reinstalling USB driver and restarting MAC and reconnecting unit. At this point these selectinos should be all good. Try to change delay(2000);
compile Blink sketch.
Now lets try loading this sketch on our device.
After this code loaded, NodeMCU blue LED will start blinking with delay that we set in the code.While this is successful test we can agree blinking LED is not very exciting.
Lets try something more interesting like connect NodeMCU to WiFi and send remote commands to this device. Will make 2 endpoints to turn our LED On/Off on URL command. We can use one of examples provided with ESP8266 extensions, open File > Eamples > ESP8266WebServer
select HelloServer
. This is a simple HTTP sever example code to setup our commands. Here is a full source code:
Note that on-board LED is contrlled with simple commands
Vcp Driver Nodemcu For Mac Installer
We have added 2 small methods mapped to URL path /on & /off
to control LED switching.
Open serial monitor window Tools > Serial Monitor
and upload this code to NodeMCU, you will see load progress. If you doing this first time after this load we need ot restart NodeMCU device by disconnect power/unplug MCU. After upload the server will start on device. The Monitor window will print a welcome message along with IP address that we can use to send command to our new IoT device.
Open browser and type URL http://192.168.1.12/on
will turn LED light up with blue light. Similar URL http://192.168.1.12/off
will switch LED off.
Now lets summ our acomplishments, so far we set up our development system with Arduino IDE for NodeMCU, connected our IoT device and tested it, made connection to our WiFi notwork and started to control NodeMCU from our browser. Very good starting point for IoT development. In the next post will explore how to collect some data and send this to our Cloud API server Part 3 - Sensors with NodeMCU.