esp8266 IoT SDK 0.9.5 release, my notes

A new version of the SDK was released today. A few additional APIs have been introduced, but it appears that no existing functions have been changed/removed. I was able to replace the 0.9.3 SDK with this and compile my codebase successfully. I’ll update here after I’ve tried flashing a device. (UPDATE: I tested the ADC code from yesterday with the new SDK and it worked well)

There are a few interesting additions, there appears to be a new API called smartconfig, it looks like this allows the device to be configured from a smartphone. The protocols used are called AirKiss and ESP-TOUCH. I had a quick look through the library symbols, there wasn’t anything new that jumped out at me.

UPDATE: I’ve left what’s written below for reference, but the esp-open-sdk is a better solution, you can see my notes of that here.

As part of the process of installing the new version of the SDK, I’ve been tidying up my toolchain a bit. A complete tarball of my setup is here. This is the Linux setup. To download an install it you should be able to do the following:

sudo su
cd /opt
wget http://41j.com/blog/wp-content/uploads/2015/01/Espressif.0.9.5.tar.gz
tar xvzf Espressif.0.9.5.tar.gz
ln -s Espressif ./Espressif.0.9.5
cd Espressif
#install the Xtensa compiler
git clone -b lx106 git://github.com/jcmvbkbc/crosstool-NG.git 
cd crosstool-NG
./bootstrap && ./configure --prefix=`pwd` && make && make install
./ct-ng xtensa-lx106-elf
./ct-ng build
PATH=$PWD/builds/xtensa-lx106-elf/bin:$PATH

However I’ve not yet tried the above, if you are interesting in giving it ago please let me know. But these notes are currently for my reference. Once the SDK is installed, I used the following Makefile for building my projects Makefile. Here’s an example project I’ve been working on which uses this Makefile: bGeigieNano_ESP8266.tar

This is a continuation of my notes on the esp8266 microcontroller, you can find a complete list of my esp8266 posts here

Olimex esp8266 PCB Schematics/Layout

Olimex have made their esp8266 layout available here. It’s under a pretty permissive CC license (allowing commercial use with attribution). I’m interested in using this as a basis for my own designs. However Olumex use Eagle, and I’ve mostly using Kicad lately. This page contains image dumps of the schematic and layout for my reference in case I decide to use them as a basis for a Kicad design, I also generated the gerbers and attached them below.

Plug: I have a bunch of esp8266 related boards in my shop.

olimex_esp8266

olimex_front

olimex_back

Gerbers using eagle (untested): espg.tar

The original Eagle file (also available on the Olimex site):
MOD-WIFI-ESP8266_eagle_sources

esp8266 analogue input

esp1_analogue

The esp8266 contains a 10bit ADC. There are apparently various issues, including instability when transmitting over Wifi, and the lack of a voltage reference. However it is usable. The analogue input is labeled “tout” on the pinout below:

esp8266_pinout

Unfortunately this isn’t broken out on the cheapest esp8266 boards (the esp1) but it’s possible to get access to it with some wirewrap wire and careful soldering (see image above).

The ADC input can then be read using some relatively simple C code as shown below. This code was adapted from an old version of the SDK (it doesn’t seem to be present in the current version).

I’ve also attached a complete working example that uses the function below: adc_test.tar

uint16 ICACHE_FLASH_ATTR adc_read(void) {
  uint8 i;
  uint16 sar_dout, tout, sardata[8];

  rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);

  // disable interrupts?
  SET_PERI_REG_MASK(0x60000D5C, 0x200000);
  while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0
  sar_dout = 0;
  CLEAR_PERI_REG_MASK(0x60000D50, 0x02); //force_en=0
  SET_PERI_REG_MASK(0x60000D50, 0x02); //force_en=1

  os_delay_us(2);
  while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0
  read_sar_dout(sardata);

  // Could this be averaging 8 readings? If anyone has any info please comment.
  for (i = 0; i < 8; i++) {
    sar_dout += sardata[i];
  }
  tout = (sar_dout + 8) >> 4; //tout is 10 bits fraction

  // I assume this code re-enables interrupts
  rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);
  while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0
  CLEAR_PERI_REG_MASK(0x60000D5C, 0x200000);
  SET_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1
  CLEAR_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1
  return tout; //tout is 10 bits fraction
}

UPDATE: There’s also a system_adc_read function in the library symbols, I’ve not used it but it could be worth looking at.

This is a continuation of my notes on the esp8266 microcontroller, you can find a complete list of my esp8266 posts here

esp8266 notes summary

I’ve written a bunch of posts on the esp8266. This post is intended to summarize them, and I’ll update it as I add new content. All the code examples are designed for use with the open SDK available here.

SDK Investigations

Installing the SDK and basic examples
Notes on the 0.9.5 SDK, and rough installation notes
Looking at library symbols
How the SDK runloop works
Missing sscanf

Hardware

Module types available
Initial notes on programming/using the esp1

Wifi and TCP/IP

Access point mode
Wifi connection issues
Listen for incoming TCP/IP connections

Interfacing

UART (RS232) usage
GPIO Input
Analgoue Input

Internal peripherals

Internal flash storage
Sleep modes

My board designs

XBee carrier board
Programmer interface
Watch design
Olimex Design (not mine)