ESP8266 NodeMCU - Getting started (Hello World)

ESP8266 NodeMCU - Getting started (Hello World)

Thanks to a bit of donated funds I was finally ready to play around with the ESP8266 1, a tiny and inexpensive wifi system on a chip (SoC), which you can use to read data from sensors, connect to the internet or even act as a webserver!

A tiny Wifi SoC

This post describes how to get the parts and getting everything up and running using OS X. I will use an ESP8266 running open source firmware called NodeMCU. This allows easy programming of the device using Lua scripts. Since the tools used in this post are cross-platform compatible, you should be able to use this guide even when running Windows or Linux.

Disclaimer

This post contains links to Amazon where I get a small commission if you purchase anything after clicking on these links - at no extra cost to you! I have purchased all the mentioned products myself and I only link to products that I believe are the best for my readers. If you want to help out even more, take a look here.

Parts

There are many ways to getting started, but using a development kit is the easiest in my opinion. I bought the Seeedstudio NodeMCU v2 - Lua based ESP8266 development kit, but I quickly found out that you can get them at a bargain at AliExpress. For around 3.5 USD you can get started and as long as you only buy one at a time the shipping is free (but very slow shipping)! I use these boards from AliExpress now. Make sure you get the NodeMCU development kit v1.0 (a.k.a V2).

Connecting the ESP8266

  1. Install the CP2102 driver from here. If using a different ESP8266 development board you might need different drivers. If you are lucky like me, the instructions will be printed on the back of the board
Seeedstudio was nice enough to leave some instructions on the back
  1. Plugin the USB cable to the ESP8266 and then to the computer
  2. Open a terminal and type ls -l /dev/tty.*. If everything went well you should see an entry similar to /dev/tty.SLAB_USBtoUART. Make sure you are using a USB data cable. I was using a purely USB charging cable which prevented the device showing up. Switching to another cable worked
  3. Download ESPlorer from here
  4. In Finder, click the ESPlorer.jar to run the program (requires Java). If you get the message: ““ESPlorer.jar” can’t be opened because it is from an unidentified developer” then go to System Preferences --> Security & Privacy and click “Open anyway”
  5. Select the /dev/cu.SLAB_USBtoUART and set the bad rate to 9600. Then click the “Open” button
  1. Push the RST button on the ESP8266, it is right next to the micro-usb port
  2. You should now see a message similar to NodeMCU 0.9.5 build 20150403 powered by Lua 5.1.4

Thats it! We are now ready for programming the device

Programming the ESP8266

The ESP8266 with the NodeMCU firmware executes Lua files. When booting the device it will look for a file called init.lua and execute this file. But first we will clear the device of every file

  1. In ESPlorer, click the format button to delete all files
  2. Next copy / paste the following code into the left hand box in ESPlorer (taken from http://esp8266.co.uk/recipes/blink-demo/, but the site is currently offline)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- Config
local pin = 4            --> GPIO2
local value = gpio.LOW
local duration = 1000    --> 1 second


-- Function toggles LED state
function toggleLED ()
    if value == gpio.LOW then
        value = gpio.HIGH
    else
        value = gpio.LOW
    end

    gpio.write(pin, value)
end


-- Initialise the pin
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, value)

-- Create an interval
tmr.alarm(0, duration, 1, toggleLED)
  1. Save the file as init.lua. This will automatically upload the file to the ESP8266
  1. Now the blue onboard LED should blink on and off every second. If you restart the device, it will load the init.lua file and keep on blinking

Conclusion

I have yet to explore the possibility of this little nifty device, but it looks promising. Using the development kit is much easier, but more expensive. The ESP8266 chips alone are less than half the price of the development kit, but worth it for me. Check out my post on how to update to the newest NodeMCU here. Stay tuned for more posts!

  1. The ESP8266 is a low-cost Wi-Fi chip with full TCP/IP stack and MCU (microcontroller unit) capability 

Enjoyed this Content?

Help keep it free by sending a donation or purchase something using my affiliate links. You can also subscribe to various site feeds to get notified of new posts, follow me on social media, and more.

5 Comments

Feroz Ahmad

when i do >
ls -l /dev/tty.*
I get :
ls: cannot access /dev/tty.*: No such file or directory

I am sure device is connected!, the blue lights are binking.

please reply soon.
Thank You

Poul Serek

Hi Feroz

It seems that the drivers might not be installed at all or somehow not detected. Which ESP8266 device do you have? In my post I needed to install the CP2102 driver, but you might need to install a different one. It should say on the back of the ESP8266.

/Poul

Lotus49

I just checked on AliExpress and a bare ESP12F is £1.60. A NodeMCU V3 is £2.06. 46p is good value considering how much easier the NodeMCU is to use for breadboarding and general playing around with.

Poul Serek

Hi Lotus49

Yes, the prices have really gone down to nothing on AliExpress! I already have 5 ESP8266 Development boards from there and I keep finding uses for them all the time. For breadboarding they are perfect, the only reason I can see for getting the bare chips is if you want to make your own energy efficient battery powered setup. AliExpress has been my favourite place for inexpensive electronics for the past year.

/Poul

Renan

I already connected to AMICA board, but I have to use 115200 at Baud Rate field if I use 9600 it doesn’t work. I already try to change the baud rate at serial Driver but it still only communicating at 115200. Anyway when I send to ESP it show “ERROR” every line of the programam… Anyone knows what is happening? Sorry my english.

Leave a reply