ESP8266: flashing the lua firmware and running some code

ESP32 Development Board WiFi+Bluetooth Ultra-Low Power Consumption Dual Cores ESP-32 ESP-32S Board
Integrated antenna and RF balun, power amplifier, low-noise amplifiers, filters, and power management module. The entire solution takes up the least amount of printed circuit board area. This board is used with 2.4 GHz dual-mode Wi-Fi and Bluetooth chips by TSMC 40nm low power technology, power and RF properties best, which is safe, reliable, and scalable to a variety of applications.
After you setup your ESP8266 module as described here you can go on and write Arduino code that talks to the ESP8266 or even flash new firmware directly on the device. Someone has put together a firmware which allows you to send lua code to the module and run it through the serial console. This is a nice way to get started with programming the module directly instead of using an Arduino intermediary. This post describes how you can flash a new firmware on the module.

Getting the wiring right

Make sure you already have the wires setup as described in the previous post. Now the module needs to be put in a ready-to-flash-firmware state. 
  1. Add a wire between GPIO0 pin and the Ground pin (GND)
  2. Now reset the module be quickly connecting the RST pin to the GND pin (in my case the blue LED flashes quickly)

Getting the flash tool ready

In order to write new firmware to the module you’ll need to use a tool, the serial console isn’t helpful in this case.
  1. Download the esptool.py from here
  2. Make it executable and run it with ./esptool.py –help. On my Mac OS X machine I got an error, that the serial library is nowhere to be found. Because of this I had to
    1. brew install python
    2. pip install pyserial
      
    3. make sure that you will use the python installed by brew
  3. Download the lua firmware from here (the nodemcu_512k.bin file)
  4. Find out the port your FTDI controller or your Seeeduino is connected to. In my case I used the Arduino IDE to find the port and make sure no console is currently connected to the Arduino
  5. Replace tty.usbserial-A901LKQM with your actual com-port
    esptool.py --port /dev/tty.usbserial-A901LKQM write_flash 0x000000 nodemcu_512k.bin
  6. Remove the connection between GPIO0 and GND
  7. Reset the module again by connecting RST quickly to GND

Running Lua examples on the module

  1. Open a serial console and connect it with your Arduino or FTDI controller. I opened the console in the Arduino IDE and set the baud rate to 9600
  2. Run enter this Lua code into the console (you may have to enter it line by line):
    print(wifi.sta.getip())
    --0.0.0.0
    wifi.setmode(wifi.STATION)
    wifi.sta.config("SSID","password")
    print(wifi.sta.getip())
    --192.168.18.110
    
  3. Run more examples from here

Update 2015-01-04

I had some problems with the stability of the ESP8266 chip. It would reboot randomly and quite soon I suspected the power supply. After I switched from the Seeeduino 3.3V power to this power supply, those problems went away:

Links


Advertisement:

Posted by squix78

Leave a Reply