I don’t particularly like Lua, or the AT firmware from Espressif, so decided to look into native C code. As the “regular” SDK seems to be going more and more closed-source I decided to try the FreeRTOS-based SDK instead.
So I setup the ESP-01 on the breadboard as shown. I’ve used a little adaptor to space out the pins – basically a 4×4 piece of stripboard with male headers (pins) on the outside pointing down and female headers on the inside pointing up to plug the ESP’s 8 pins into, with the traces cut down the middle – or joined using solder blobs if using perfboard.
Serial comms and flashing is via a USB UART (pinouts may differ) with TXD on the UART to URXD on the ESP, and RXD to UTXD in the same fashion. GND is joined to the GND (blue) rail on the breadboard.
CH_PD and VCC are connected to the VCC (red) rail from a 3.3v power supply, not the UART. RST is not connected. Pinout diagram.
Install dependencies, on Debian (and probably Ubuntu) this should do it:
sudo apt-get install git autoconf build-essential gperf bison flex \ texinfo libtool libncurses5-dev wget gawk libc6-dev-amd64 \ python-serial libexpat-dev unrar sed
Download the repositories (using my fork of the SDK for now, until they merge my PR):
git clone https://github.com/pfalcon/esp-open-sdk.git git clone https://github.com/sej7278/esp_iot_rtos_sdk.git git clone https://github.com/espressif/esp_iot_rtos_sdk_lib.git wget http://www.the-jedi.co.uk/downloads/arduino/user_main.c
Build the toolchain (N.B. this toolchain will work with the regular SDK too, so you can build nodemcu for example):
cd esp-open-sdk/ make
Merge the closed-source libs and my app with the SDK:
cd ../ cp esp_iot_rtos_sdk_lib/lib/* esp_iot_rtos_sdk/lib/ cp user_main.c esp_iot_rtos_sdk/app/user/ mkdir esp_iot_rtos_sdk/app/user/include cp esp_iot_rtos_sdk/examples/driver_lib/include/uart.h app/user/include/
At this point we need to add the toolchain to our $PATH, easiest way is to add this to the bottom of ~/.bashrc:
Next time you open a terminal (or source ~/.bashrc) the xtensa-lx106-elf-* binaries will be found, assuming you checked out the git repo’s to your $HOME directory, if not change the $PATH accordingly.
Make any changes you need to esp_iot_rtos_sdk/app/user/user_main.c – probably ssid, password, ip, gateway, netmask.
On the ESP-01 connect GPIO0 to GND and power it up.
Now we can compile and flash:
cd esp_iot_rtos_sdk/ make && make flash
After a few seconds, the compilation will be done and flashing will take a while longer. Once that’s done, power down the ESP-01 and return GPIO0 to the LED’s resistor. Run your serial console application e.g.
screen /dev/ttyUSB0 9600
Then power on the ESP-10. You should see some system stats and the wifi connection status like so:
System Info: Time=319701 RTC time=52079 Chip id=0x9a5640 Free heap size=45632 Mem info: data : 0x3ffe8000 ~ 0x3ffe87b0, len: 1968 rodata: 0x3ffe87b0 ~ 0x3ffea198, len: 6632 bss : 0x3ffea198 ~ 0x3fff1b80, len: 31208 heap : 0x3fff1b80 ~ 0x3fffc000, len: 42112 SDK version:0.0.5 mode : sta(18:fe:34:9c:75:64) add if0 b scandone add 0 aid 2 aid end cnt connected with MYSSID, channel 11 ip:192.168.1.2 mask:255.255.255.0 gw:192.168.1.1
You should also be able to ping the IP address and the two LED’s will flash.
So we have the toolchain setup and have made a basic user application within the SDK which controls wifi, serial and GPIO!
Next I need to think of a way to move the user apps outside of the SDK directory structure and do something more interesting like i2c or a web interface.