March 31, 2015

ESP8266 Resources


Here is my current list of links for the ESP8266 and Arduino.



Wiring

I have collected some wiring schemes of increasing complexity in this post.
However I have developed my own wiring scheme and described it in this Instructable. I think is easier for many people to start with a solid and tested scheme.

Libraries

  • WiFiEsp : This is my own library. It is designed to be very similar to standard Arduino Ethernet and WiFi shield libraries. The idea is to be able to reuse existing sketches and projects with this cheap ESP module. You can find more information on this post.
  • ITEADLIB_Arduino_WeeESP8266 : Seems to be the most stable and reliable ESP library at the moment (Apr 2015).
  • arduino-ESP8266 : Seems a good library
  • ThaiEasyElec (TEE_ESP) : Works only with SoftwareSerial, low level functions, poor documentation, no website or GIT repository.
  • ESP8266 EasyIoT
  • Adafruit: Seems a good library, debugging functions, missing high level functions.
  • espduino : Wifi library (Chip ESP8266 Wifi soc) for Arduino using SLIP protocol (custom firmware) via serial port. Release 0.1 was based on AT commands.
  • ESP8266 : Another library. Nothing special. 
  • ESP8266_client :  A lightweight library for client connections. Nothing special.
  • ESP8266_Simple :  Well documented, works only with SoftwareSerial, few functions.

Reference documentation


Flashing the firmware

I have developed my own procedure using Arduino board for flashing the ESP.


Other resources


  • Espressif forum:
  • ESP8266 forum : This is a community forum centered around the ESP8266. Everything is here, but probably best to read this stuff after going through a complete design example.
  • Electrodragon wiki : Wiki page with multiple sets of information and links for using the ESP8266.
  • Espressif is the manufacturer of the ESP8266. Their site is pretty much a bunch of marketing hoo-hah and you'll have to "contact" them for more information. Not too useful.
  • http://blog.electrodragon.com/esp8266-gpio-test-edited-firmware/ : A demo of turning the LEDs on the ESP8266 board on/off over the Wifi link.
  • http://scargill.wordpress.com : Peter Scargill has been pretty thorough in documenting his experiences in getting the ESP8266 up and running and delving into some of the capabilities of the chip.


March 28, 2015

Debugging ESP8266 commands with Arduino Uno

I have recently received an ESP8266 that is a tiny and cheap WiFi module that can be controlled through serial interface commands. I have read several blogs and forums to understand how to make it work. I finally found my own approach of testing this little toy.

ESP8266 pins are described in this diagram.
These are few important things I have discovered:
  1. Power - The ESP8266 needs 3.3V power. The ESP can draw up to 250mA while the Arduino Uno 3.3 output pin can provide only 50mA. In serious project you need a good 3.3V power source but for playing and debugging the Arduino Uno 3.3V output pin can be enough.
  2. CH_PD pin - The CH_PD pin needs to be held high so connect it to VCC also.
  3. TX/RX -In theory you TX and RX pins accept 3.3V so you need level shifters to adapt Arduino's 5V signals. However, I found out that it just works without level shifters.
  4. Debugging - To debug the ESP's commands you need 2 serial ports. One (the default one) is used by the Arduino Serial Monitor so it can be used to debug. The ESP will be attached to the second serial port but unfortunately the Arduino Uno has just one serial port. Some approaches require additional hardware or an Arduino Mega but I have found that the Software Serial library allows to emulate a serial port so I will use this simpler approach.

Wiring



NOTE: This is not a perfect wiring scheme because it doesn't use level shifters. Use at your own risk!

Connections are:
  • Arduino 3.3v power > breadboard red power rail
  • Arduino GND > breadboard black ground rail
  • ESP8266 GND > ground rail
  • ESP8266 VCC > power rail
  • ESP8266 CH_PD > power rail
  • ESP8266 TXD > Arduino Digital Pin #6 (RX pin using software serial)
  • ESP8266 RXD > Arduino Digital Pin #7 (TX pin using software serial)

Code


#include "SoftwareSerial.h"

SoftwareSerial esp8266(6, 7); // RX, TX

void setup()
{
  Serial.begin(115200); // serial port used for debugging
  esp8266.begin(9600);  // your ESP's baud rate might be different
}
 
void loop()
{
  if(esp8266.available())  // check if the ESP is sending a message
  {
    while(esp8266.available())
    {
      char c = esp8266.read();  // read the next character.
      Serial.write(c);  // writes data to the serial monitor
    }
  }
 
  if(Serial.available())
  {
    delay(10);  // wait to let all the input command in the serial buffer

    // read the input command in a string
    String cmd = "";
    while(Serial.available())
    {
      cmd += (char)Serial.read();
    }

    // print the command and send it to the ESP
    Serial.println("---------------------");
    Serial.print(">> ");
    Serial.println(cmd);
    Serial.println("---------------------");
    esp8266.println(cmd); // send the read character to the esp8266
  }
}

Commands

Now that you have wired your ESP and uploaded the sketch to Arduino you can open the serial monitor and play with the 'AT' commands.
Remember to set the baud rate to 115200. Newer ESP modules also require to send NL & CR characters.



The main ESP8266 AT commands are listed here.
  • AT - Test
  • AT+RST - Reset
  • AT+CWLAP - List WiFi available networks
  • AT+CWJAP="SSID","PWD" - Connect to a network (change SSID and PWD to match your access point)
  • AT+CWJAP? - Check if connected successfully
For a full list of commands refer to this document.

March 5, 2015

Animation of five LEDs using Arduino PWM output pins

This example is part of the ALA (Arduino Light Animation) library and shows how to create animations using some LEDs and an Arduino board.
Checkout this small video to see how the animations look like.



Circuit

The circuit is really simple. Just five red LEDs connected to five analog output pins of the Arduino and five 220 Ohm resistors.



Code

You have to download and install the ALA library from here first.

#include <AlaLed.h>

AlaLed leds;
byte pins[] = { 5, 6, 9, 10, 11 };

AlaSeq seq[] =
{
  { ALA_FADEIN, 1000, 1000 },
  { ALA_ON, 1000, 1000 },
  { ALA_FADEOUT, 1000, 1000 },
  { ALA_BARSHIFTRIGHT, 1000, 1000 },
  { ALA_BARSHIFTLEFT, 1000, 1000 },
  { ALA_OFF, 1000, 1000 },
  { ALA_PIXELSHIFTRIGHT, 700, 1400 },
  { ALA_PIXELSHIFTLEFT, 700, 1400 },
  { ALA_BLINKALT, 500, 3000 },
  { ALA_PIXELSMOOTHSHIFTRIGHT, 1000, 4000 },
  { ALA_PIXELSMOOTHSHIFTLEFT, 1000, 4000 },
  { ALA_FADEINOUT, 1000, 4000 },
  { ALA_COMET, 1000, 4000 },
  { ALA_GLOW, 1000, 4000 },
  { ALA_STROBO, 200, 4000 },
  { ALA_ENDSEQ, 0, 0 }
};


void setup()
{
  leds.initPWM(3, pins);
  leds.setAnimation(seq);
}

void loop()
{
  leds.runAnimation();
}

I have designed the ALA library with simplicity in mind. You just need to initialize the AlaLed object in the setup function passing the number of LEDs you want to drive. Then you call the runAnimation method passing an array of triplets to describe the desired animation sequence. Finally you have to call the runAnimation method in the loop function to animate your LEDs.
The tricky part is the AlaSeq structure that is made by 3 fields:
  1. A numeric code identifying the desired animation. Valid codes are listed in the Ala.h header file.
  2. The animation loop duration in milliseconds.
  3. The animation total duration in milliseconds.
The last entry in the array must be ALA_ENDSEQ to close the animation sequence.