Configuring the Raspberry Pi as an ESP8266 Development Environment

The Raspberry Pi is an advantageous platform for developing ESP8266 software, as it can power the ESP with its 3.3V pins, communicate directly with the ESP via its serial GPIO pins, and natively runs the Xtensa cross-compiler on its Linux-based Raspbian OS. We first began using it out of convenience, as it was the only thing that we had on-hand that could power and communicate with the ESP-12. However, we have found that we really like the workflow of coding, compiling and directly pushing firmware onto the ESP.

The first step to developing on a Raspberry Pi is to enable the Pi to communicate with the ESP8266 via its two serial pins. GPIO 14 and 15 are the Pi’s serial port, 14 being transmit and 15 being receive. A fresh installation of Raspbian needs a tiny bit of tweaking to use the port, however. The Wheezy-based version of Raspbian sends boot information to the serial port during the Pi’s startup, and this functionality must be disabled. To do so, open “cmdline.txt” in /boot using superuser privileges (ie “sudo nano /boot/cmdline.txt” in the terminal) and remove this segment:

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

Raspbian’s default configuration automatically provides a serial login service using getty over the serial port, which must be disabled in both Wheezy and Jessie. To disable this, use the command “sudo raspi-config” in the terminal. It will open a configuration program.

advanced

Select “Advanced” (option 9 on the main menu) and then “Serial” (option 8 on the Advanced menu). It will ask if the Raspberry Pi should provide serial login, to which you should select “no.”

raspi-config-2

raspi-config-3

You may need to use the “expand filesystem” option while you are in raspi-config (option 1 on the main menu). A freshly-written Raspbian SD card installation is likely not taking full advantage of the space provided to it, making it difficult to install new packages. If you have space issues in this tutorial, run this option before buying a new SD card!

The main menu of raspi-config

Select “Finish” on the main menu and allow the Pi to reboot.

Now you’ll need software to test the serial connection with. Open a terminal and install minicom (“sudo apt-get install minicom”). Connect the transmit pin of your ESP to the Pi’s receive pin and vice versa. Now, in the terminal, open a serial terminal:

minicom -D /dev/ttyAMA0

You should be able to send and receive communications with the ESP8266.

The next portion of the getting started guide covers the toolchain.

It is a good idea to start with updated repositories and upgrading the currently installed software:

sudo apt-get update
sudo apt-get upgrade

Once the update is finished, reboot the Pi. When the system is back on, open a terminal and install the required dependencies for the toolchain:

sudo apt-get install make autoconf automake libtool gcc g++ gperf flex bison texinfo gawk ncurses-dev libexpat-dev python python-serial sed git unzip bash libtool-bin

We are now ready to install the toolchain. You can put install this anywhere, but a good place for it would be the /opt directory:

cd /opt
sudo git clone –recursive https://github.com/pfalcon/esp-open-sdk.git
sudo chmod 777 -R esp-open-sdk
sudo chown -R YourRPiUsername esp-open-sdk/
cd esp-open-sdk
make

This will take approximately forever. Once it finishes, the final piece of the puzzle is adding the compiler to your path variable. We’ll put it at the very end of your ~/.profile:

PATH=”/opt/esp-open-sdk/xtensa-lx106-elf/bin:$PATH”

Placing the Xtensa Tools in the PATH Variable

Reboot the Pi and open a terminal. Check to make sure the PATH variable contains the xtensa toolchain by using the following command:

$PATH

The path to the compiler should be listed in the output of the PATH variable. You can now compile ESP8266 firmware and flash it to the device. You can test this by pulling the OpenMYR code and using the makefile while your ESP is connected to the serial and booted into write mode:

git clone https://github.com/OpenMYR/IoT_Motors.git
cd IoT_Motors
make flash-stepper

Finally, unless you’re all about terminal-based editors, you will want a text editor that is condusive for programming. The Pi’s built-in GUI text editors aren’t that useful, but we found that SciTE was perfect for our needs. It feels a lot like Notepad++ and made coding on the Pi a lot saner. It can be installed with a simple apt-get command:

sudo apt-get install scite

This entry was posted in ESP8266, Raspberry Pi, Raspbian, Reference and tagged , , , , . Bookmark the permalink.

2 Responses to Configuring the Raspberry Pi as an ESP8266 Development Environment

Leave a Reply to Brandon Brown Cancel reply

Your email address will not be published. Required fields are marked *