In my last post I mentioned that there was an Arduino compatible core available for the ESP8266 - in this post I cover how to install this core as well as cores for other non-Arduino hardware.

A Brief History of Arduino

The Arduino system started in 2005 as a project platform for students and consists of a hardware platform (based on the Atmel ATmega chips) as well as a software library (based on Wiring).

Wiring was originally designed for use by artists and designers so the focus was on ease of use and good documentation - although it uses C++ as the implementation language many of the language features are hidden, not available or simply discouraged. The result is an API with a very shallow learning curve which is ideal for one off projects or prototypes.

The original Arduino hardware was based around the ATmega series of chips and was very easy to duplicate, resulting in a wide range of clones and homebrew versions all sharing a compatible form factor and API. This allows code to be easily shared and ported to different systems.

TODO: PIC Arduino

It wasn't long before boards were released that used very different hardware (such as PIC and ARM chips) but retained software compatibility through the Wiring API. Even the official boards started to include ARM based systems. These boards obviously required different toolchains and libraries and integrating them into the Arduino IDE was problematic, event for the official boards.

Arduino Board Manager

To solve the issue of supporting different cores and different compilers the Arduino IDE implemented the Board Manager - a tool that allows you to select, download and install support for other boards directly from the IDE. Although initially only official boards were supported version 1.6.4 added support for third party boards and cores.

To access the boards manager simply choose Tools|Board|Boards Manager... from the menu and you will be presented with a list of available boards you can install.

Board Manager

In a fresh install this list will only show boards hosted by the Arduino site, to add board packages that are hosted elsewhere you will need a URL for the board index. The Arduino site lists a number of third party URLs. Other Arduino compatible boards should provide you with a board support URL for their product.

To add these URLs simply select File|Preferences from the menu and click on Additional Boards Manager URLs. Enter the new board URL (one per line) and you are done.

Board Manager URLs

To actually install the board support library go back to the Board Manager and your new boards should now appear in the list. Adafruit have a good tutorial that covers the process.

The ESP8266 Core

The Arduino core for the ESP8266 implements the standard API with some minor differences in PROGMEM handling as documented here. The mapping of pin numbers to actual physical GPIOs is different but well documented - the image below shows how the pins are numbered on an ESP-12 module.

ESP8266 Pin Mapping

The core also provides ESP8266 specific implementations of the standard libaries such as SPI, EEPROM, Wire and SoftwareSerial. There is also an ESP library included that provides access to the ESP8266 chip ID, allows entering the various sleep modes of the processor and provides information about the external SPI flash chip.

One of the main reasons to use the ESP8266 is the integrated 802.11 b/g/n WiFi transceiver and this is well supported. As well as providing a WiFi library that is compatible with the one that supports the official Arduino WiFi shield. Extensions support operating as a access point as well as a client.

There are additional libraries provided to support service announcement (with DNS-SD and SSDP), and the ability to act as a DNS server - these features are important to allow automatic discovery of and connection to ESP8266 based sensors. Most other Arduino libraries should work with the core (as long as they don't use AVR specific features) - a list of verified libraries is provided.

Next Steps

With this core I can make use of the Arduino ecosystem and massive code base with ESP8266 based projects. Despite it's faults the Arduino enviroment is great for prototyping and having it available as a tool should speed things up considerably.

One of the things I am keen to work with is the ITEAD Sonoff module. This is essentially a 240AC relay with an integrated ESP8266 chip for wireless control. Although it come loaded with firmware and there is a phone application available for controlling it I would like to customise the firmware to integrate it with my own system.

ITEAD Sonoff Module

Thankfully the Sonoff exposes the GPIO pins of the ESP8266 to a 2.54mm pitch header (including the all important programming interface) so this shouldn't be that difficult to do. With the libraries included in the ESP8266 core setting up automatic discovery of the devices should not be too difficult to achieve either.

The wider availability of the Arduino API through custom cores is a valuable tool - if you are already working with the Arduino and looking for a wide range of hardware to use while making use of your existing skills this is probably the best path to take.