Friday 13 April 2018

Downloading code to ESP8266 in Ubuntu

In last article I talked about setting up the SDK in Ubuntu, if everything goes well, you may can compile the code and got the binary code generated.

To download in Ubuntu is every simple, you just need to install the downloading tool and run it. There is a folder in the esp-open-sdk, which is the open source part of the whole SDK, named 'esptool'. inside the folder there's a Python program 'esptool.py'. If you have Python installed on your computer, you probably can use this tool. But for me sometimes it gives me confusing error message. I have two laptops both with Ubuntu 16.04, it runs well on one of them but on the other it says 'ImportError: No module named serial'. I don't know Python so I'm not able to figure out the problem. I hope you don't encounter this.

There is another way to do it. Since Ubuntu 12, the 'esptool' has been in the official repository and it's still there in Ubuntu 16. All you need to do is install it using the 'apt install' command.

$sudo apt install esptool

Yes, it's that simple. After this you'll have the ESP8266 downloading tool installed on your computer and that's a binary code you don't even need Python environment.


There are more functions than downloading in this esptool, you can find them out using 'man', Yes! yet another benefit to install esptool from the Ubuntu repository. To see the user manual, type :

$man esptool

Briefly, the command format is:
esptool -cp 'serial port' -ca 'address1' -cf 'file1' -ca 'address2' -cf 'file2' ....  (without the quote character)

For connecting the ESP8266, please see this article : Connect ESP8266 in Ubuntu

If you have multiple USB tty devices connected, it would be difficult to know which is which by just seeing the /dev/ttyUSB* list. A shortcut to sort it out is to use the 'dmesg' command. It will output all the system messages since the computer was been turned on, but a grep will filter unwanted out. Unplug your ESP8266 and connect again, then type:

$dmesg | grep tty

The latest message about tty device will be your ESP8266 and you'll know which ttyUSB number it's at.

A real download command would look like this:

esptool -cp /dev/ttyUSB0 -ca 0 -cf eagle.flash.bin -ca 0x10000 -cf eagle.irom0text.bin -ca 0x3fc000 -cf esp_init_data_default_v08.bin -ca 0x3fe000 -cf blank.bin

No comments:

Post a Comment