Sunday, November 15, 2015

Flashing the ESP8266

Once you have bought your first ESP8266 modules you will want to start some projects with them.

Now if you have bought the NodeMCU version you are in luck as there is probably the LUA language build in. However if you bought the ESP8266-01 or any other member of this family there is likely to be the AT-command firmware in this module.

The AT-command firmware can be used to communicate with an Arduino. The Arduino does all the I/O and calculations and just sends the results to the ESP which then can send these results over Wifi. Or you can send commands to the ESP which will pass them through to the Arduino that can execute them.

Fun but not very easy to use for novice ESP users like me.

The Lua language is much more easy to understand. It is a high level language which is easy to learn.

And there is more. Not only Lua is available. In the past year a lot of languages have been devellopped for the ESP8266 family. There is Python, Javascript, Lisp and even Basic !!!

At the end of this story I will provide you with links to all the different firmwares that are available for the ESP8266.

Flashing the NodeMCU

To flash the NodeMCU with new firmware you just have to connect the USB cable to your computer, start the NodeMCU Flasher. Get the firmware and instruct the NodeMCU flasher to use that and Push the Flash button.

Flashing the ESP8266-01

This is a bit more tricky. First you will need to build the ESP8266 programming board. You can find it in this post.

Next you will need to load the NodeMCU flasher. You can find the latest version here on the NodeMCU github page: https://github.com/nodemcu/nodemcu-flasher

After you have downloaded and Unzipped it it is ready to flash the latest version of the Lua firmware in your ESP8266.



As you can see the flasher immediately recognizes on wich com-port the ESP8266 is located.




In the config menu you can see that NODEMCU (the LUA firmware) is activated and ready to be flashed.

Now if you press the Flash button nothing will happen. Flashing will not start.
To start flashing you will need to press the Program button (the rightside button on the programmer) and keep it pressed. Then press the Reset button (the leftside button on the programming board).


Now the QR code will be made visible. So will the Mac adresses for the AP (Access point) and STA (Station) be shown. You can write these down or use your Android Phone with a QR code scanner (or your PC with a webcam) for memorising them.


Keep pressing the Program Button (the rightside button) and you will see that the module is slowly being flashed.

When finshed a green circle at the right side of the window will appear with the word Ready next to it. And you're done.

Flashing other firmware.

As stated above there are many firmwares available for the ESP8266: AT-commands, Basic, Java, Lisp, Lua and Python.


To use any of these first click the config tab and choose any free line where it says 'Path of Binary file'. Next to this line is a button. Click that and the fileselector will open. Choose the firmware you want and it will be displayed on that line.


Now choose the right offset in memory. Dont worry normally it is 0x00000 which is already filled in.


Next check which firmware you want to flash and make sure the other lines are unchecked. Now go back to the Operation Tab and proceed as described above and flash your desired firmware.

You're done !!!

To make sure the firmware starts press the reset button on the programming board (the left button).

The links to the available firmwares

First the flash software itself:
https://github.com/nodemcu/nodemcu-flasher

Original AT command set
http://bbs.espressif.com/viewtopic.php?f=46&t=1123&sid=a5a84b6f154226729c6a573fe64e54e4#p3755

Basic:
http://www.esp8266basic.com/flashing-instructions.html

Javascript for ESP8266
https://github.com/espruino/Espruino

Lisp
https://github.com/yesco/esp-lisp

Micro Python
https://github.com/micropython/micropython

Till next time.
Have fun


Luc Volders

Sunday, November 1, 2015

ESP8266-01 Programming board

For those of you who have lived under a rock I will first explain what an ESP 8266 is.

Most of you know what an Arduino is. It is a small processor which runs at 16Mhz has 32K of memory and a lot of I/O pins. This all for a great value for the money.

Now about a year ago a new processor came on the market. Actually it has been around longer but last year it became very affordable , we are talking 4 dollar, and had an accompaning programming environment. Not only that, it runs at 80Mhz and has loads of memory and depending on what version you purchase lots of I/O pins. Best of all: it has wifi on board. And this last feature makes it interesting for many projects and IOT (Internet of Things) gadgets.

Just think about a small, 4 dollar costing module that enables you to put the lights in your home (or coffeemachine, or blinds or sprinkler or whatever) on or off from any place in the world......

So the version which is the cheapest and therefore has the lowest specifications is the ESP-8266-01. It has all the memory, the fast processor and Wifi but just 2 I/O pins.
Now 2 I/O pins is not a lot. However sufficient to put a sensor on or some buttons or a bunch of Neopixels (WS2812 leds). Even with this limited amount of I/O pins there are numerous projects to build with this little marvel.

But how do you program it......

How to program the ESP-8266-01





This is the actual module. On the left you can see there are 8 pins. 2 Pins for the power supply (3.3 Volts), 2 pins for I/O, 2 pins for TX and RX serial communication, a Reset pin and a chip select pin.

So directly connecting it to your computer is out of the question. So what you'll need is a serial to USB adapter and that is called an FTDI.

For your information: there is a special version of the ESP8266 that includes an USB port and has the full I/O pins available. It is called NodeMCU. You will find more information on this version on this weblog.

Now besides the need for a FTDI there is another problem.







As you can see the ESP 8266-01 is not exactly breadboard friendly.

The first picture shows that you can not put the ESP8266-01 on the breadboard in this way because all pins would short-circuit. The second picture is the normal way we would put a circuit on the breadboard. However the ESP 8266-01 has 2 rows of pins. So that's no option either.




So a while ago I bought some female breadboard cables. These can be attached to the ESP 8266-01.





That looks good, but how am I going to attach that on a breadboard. Well you can plug a male cable into the female ones like this.





And now we can complete the circuit.




As you can see it works. However I had some issues. Sometimes it would not work. The led on the ESP would not turn on or was very faint. And I saw power consumption run high. What could be wrong.....




Just look at the mess in the picture above. Loose connections and short circuits are definitely going to happen.


As I am planning to use the ESP 8266-01 in many projects I need a proper solution. And that is easily made by putting the complete circuit on a breadboard. This also gave me some extra possibillities. Lets look at the circuit first.




The top 4 pins of the ESP-8266-01 are from left to right:
Ground, I/O 2, I/O 0 and RX

The bottom 4 pins are from left to right:
TX, Chip-select, Reset and VCC

So the circuit connects the ground and VCC to the FTDI module. The TX of the ESP to the RX of the FTDI and vice-versa. 

The Chip Select pin is permanently wired to the VCC (+3.3volt) line. And the VCC, Ground and both I/O pins are connected to a female header. This makes it easy to connect the program,ming board to a breadboard for further expansion and use of the I/O ports.

The extra options are a Reset button and a Program button which are both connected to ground.

The only tricky thing here is that the Program button is connected to ground and to I/O 0. So we can use the I/O pins as a normal I/O pin. But when we need to flash the ESP 8266-01 with a new operating system you'll press the program button at boot time.

Why would you reprogram the ESP 8266-01. Well just have a look at the extended list of  'operating systems we have for this chip'. We can use it with the standard AT set of commands, you can use it with the LUA programming language. You can use it with the Arduino IDE, there is a Python version available and there is ESP-Basic. 
So if you want to use any of these you will need to reflash the operating system and therefore you will need the program button.

I used a strip PCB for making my programming board and put female headers on it so I can easily switch the FTDI and ESP8266-01 and have headers for connecting the I/O ports with a breadboard.

As there are multiple kinds of stripboards available I will not show you how I made mine. However by following the circuit above you will surely have no trouble in designing your own. I just present you here the looks of mine.






So this last picture shows you how my ESP8266-01 programming board is actually used. Is is attached to a string of Neopixels (WS2812 leds) of which you can control loads with just 1 pin of your controller. Compare that to the mess with female and male cables above and you'll immediately know why making this programming board is worth the effort.

So make this board. You are definitely going to have much profit of it as we'll be using this little processor for many projects in the future.

Till next time
Have fun


Luc Volders