This page looks best with JavaScript enabled

Getting Started With NodeMCU Development on Ubuntu

 ·   ·  β˜• 5 min read

Introduction

At the time I’m writing this post, the Internet of Things is not a new thing. If you own a vehicle, and it connects to the internet in some manner, your vehicle manufacturer is already gathering so much data with planted sensors in the vehicle.

It’s not only about your vehicle or your phone. IoT is used in tracking the orders you have booked at your favorite e-commerce site. You as an enthusiast can also automate certain aspects of your house.

Automating my home was my motivation to get started start digging around IoT. I own a raspberry pi already. But Raspberry is best suited for being the central server of your entire house. It’s more like a mini-computer.

While you can learn to work with sensors and actuators on a Raspberry Pi, there will come a time when you’ll have to explore MCUs aka micro-controllers. ESP8266 is one such popular MCUs in the market. It is popular among IoT enthusiasts and is pretty cheap compared to raspi. These ESPs are a good compliment to raspis. It is developed by Espressif Systems.

One of the most popular selling points of ESP8266 is its connectivity. It comes with a WiFi chip onboard. So where does NodeMCU fits in? NodeMCU is a firmware for ESP8266. It is analogous to the operating system on a fully-fledged computer.

From now onwards, I am assuming you have an ESP8266 and you have a computer running Ubuntu already.

Download Arduino IDE

Now the first step to download Arduino IDE is to head over to https://www.arduino.cc/en/software.

At the moment I’m writing this, I can see two options:

Linux AppImage 64 bits (X86-64)
Linux ZIP file 64 bits (X86-64)

Click on the first option. You will be taken to the donate page where you can see a link to download the AppImage file.

Spin up your terminal and navigate to the download directory.

Rename the file to arduino-ide.

Make the file executable.

Move it to ~/.local/bin.

Here is me doing all the above steps in the terminal:

santosh at kubuntu in ~
$ cd ~/Downloads/

santosh at kubuntu in ~/Downloads 
$ ls -l *appimage
-rw-rw-r-- 1 santosh santosh 203484377 Mar 31 00:42 arduino-ide_2.0.4_Linux_64bit.appimage

santosh at kubuntu in ~/Downloads 
$ mv arduino-ide_2.0.4_Linux_64bit.appimage arduino-ide
renamed 'arduino-ide_2.0.4_Linux_64bit.appimage' -> 'arduino-ide'

santosh at kubuntu in ~/Downloads 
$ chmod +x arduino-ide 

santosh at kubuntu in ~/Downloads
$ mv arduino-ide ~/.local/bin/
renamed 'arduino-ide' -> '/home/santosh/.local/bin/arduino-ide'

santosh at kubuntu in ~/Downloads 
$ ls -l ~/.local/bin/arduino-ide 
-rwxrwxr-x 1 santosh santosh 203484377 Mar 31 00:43 /home/santosh/.local/bin/arduino-ide*

You should be able to execute arduino-ide from the terminal. If at this point you are not able to call the executable, you might have to update your path. Stick the following line inside your ~/.bashrc file. Your shell rc file will be different if you are using another shell such as zsh or fish.

PATH=$HOME/.local/bin:$PATH

Configure Arduino IDE to work with ESP8266

As the name ‘Arduino IDE’ suggests, it was originally an IDE for Arduino boards. But the community has grown and it now supported more than Arduino boards. This section is about configuring Arduino IDE to make it aware of the ESP board we are going to use with it.

We do so by going to File > Preferences. And then add the following URL in the textarea labeled as Additional boards manager URLs. Hit OK when you are done.

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

The above URL is not the actual firmware, instead, it is a list of all firmware that is based on ESP8266.

Additonal Boards Manager
Additonal Boards Manager

The next step is to install the actual firmware.

You can do this by going to: Tools > Boards Manager > Search 8266 > Install

Configure your system to work with USB

Let’s take a step back to configure ubuntu properly. It was a problem for me, so there is a good chance that it will be a problem for you too.

Your current user needs to be in the dialout group, otherwise uploading the code to NodeMCU will fail. On the next line is the command to add your logged-in user to the dialout group.

sudo usermod -a -G dialout $USER

When you are done running that command, make sure you log out and log in again.

Hello World

This blog post is incomplete without a hello world sketch. By the way, a sketch is a code or program which you upload to the MCU. Let’s do our legendary project, the hello world.

At this point, you should plug your MCU into the USB on your system.

Next, you will be seeing a “Select Board” dropdown. Click on that and type NodeMCU. Click OK. Select the MCU to upload the code to.

Here is a sketch that will print hello world at 5 seconds intervals.

1
2
3
4
5
6
7
8
void setup() {
    Serial.begin(115200); // Set the baud rate to 115200, same as the software settings
}

void loop() {
    Serial.println("Hello World!"); // Print character string "Hello World!" on the serial
    delay(5000); // Delay 5 second
}

Conventionally, there are two functions in each sketch. setup is run initially when the chip is powered on. The loop keeps running infinitely until and unless power is still on.

Click the Upload button and while the code is sent to the MCU, open up the Serial Monitor from the Tools menu.

Enjoy the hello world program.

Conclusion

This is the start of something big. There is a whole lot that can be done with ESP8266. In upcoming posts, I’ll be coming up with exciting projects which are fun to do on this mini-board.

Share on

Santosh Kumar
WRITTEN BY
Santosh Kumar
Santosh is a Software Developer currently working with NuNet as a Full Stack Developer.