WiFi and the Raspberry Pi

Arduino IDE Firmware Comments

I'll admit it. The Arduino IDE is my favorite way to program the ESP8266 at this time. It's a familiar environment, and it works. Additionally, the ESP8266 is behaving very well in this environment. I have more than five ESP8266 units running in LightSwarm, all compiled under the ESP8266 Arduino IDE and libraries.

However, you should remember one important thing about using the Arduino IDE and libraries for this chip. The Arduino has traditionally been single-threaded [14], and the ESP8266 by it's very nature must be multithreaded to receive and transmit on the WiFi while doing something else. To make all this work reliably, you need to insert delay(0) statements in various places in your code, especially in computationally expensive pieces. A delay(0) statement gives the ESP8266 a chance to do some of its background processing and keeps the data flowing.

I checked whether I could set this up to work under PlatformIO [15], and I was very pleased to see support already. PlatformIO is a cross-platform code builder, and the missing library manager for a number of different IDE systems (Arduino, Eclipse, etc.). I use it on SunRover [16] because I want to program the Arduino in the box from the Raspberry Pi without having to put up a whole graphical display. This allows me to program both computers remotely, which is an important feature.

Once I installed PlatformIO, I could use the command line only. In case you don't know how to use the command line on the Raspberry Pi, an upcoming SwitchDoc Labs column will take you through all the basics. Be prepared to become a wizard with your new knowledge after reading that column!

Reading Web Data on the Raspberry Pi

Given the success of the NodeMCU and Arduino IDE on the ESP8266 device, I'm going to use the Arduino IDE to build a small web server that I will attach to the Arduino Power Management System in the solar-powered SunRover robot. Then, I can issue commands to boot up the Raspberry Pi 2 or execute special commands even if the Raspberry Pi 2 is not currently running.

To save power, I intend to keep the ESP8266 either powered down or in deep sleep mode most of the time. At this point, I intend to bring it up five minutes before the hour to five minutes after the hour, which means I can reboot the Arduino, Raspberry Pi, or the motor controller all from the Arduino.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content