ESP8266 vs. Arduino

The inexpensive ESP8266 module looks promising for realizing own IoT projects.
However there are a couple of stumbling blocks to be found when trying to integrate this module. These are the ones I found when I tried to connect an Arduino Pro Mini (3,3 V) to the local WiFi network with this module.

Stumbling block #1

During development the ESP8266 module requires its own 3.3 V (!) power supply. The power consumption increases when a WiFi connection is established. Powering the ESP8266 module via FTDI/USB is not sufficient as soon as WiFi connections are planned.

 

ESP8266 on FTDI programmer

Stumbling block #2

To check whether the ESP8266 is flashed with firmware and understands AT commands first connect it directly to an FTDI programmer:

FTDI programmer
GND GND 3.3V power supply
VCC not connected
RX TX ESP8266
TX RX ESP8266
DTR  not connected
RST  not connected
ESP8266 module
GND GND 3.3V power supply
VCC VCC 3.3V power supply
RX TX FTDI
TX RX FTDI
CHPD VCC 3.3V power supply via 10k resistor
REST VCC 3.3V power supply via 10k resistor

esp8266onftdi_breadboard

With a terminal (e.g. from the Arduino IDE) it is now possible to send AT commands to the ESP8266. A comprehensive description of the AT command set for ESP8266 modules is found on  http://www.esp8266.com/wiki/doku.php?id=at_commands .

Stumbling block #3

New line and carriage return must be set in the terminal and the proper baud rate (115200) must be selected.

Basic AT commands

command expected result description
AT OK Test whether AT commands will work
AT+GMR e.g. AT version:0.60.0.0(Jan 29 2016 15:10:17)
SDK veróion:1.5.2(80914727)
compile time:Jan 29 2016 19:06:34
OK
Print version information
AT+RST OK Reset ESP8266 module
AT+RESTORE OK Configuration will be reset to factory defaults.
AT+CWLAP list of WIFI local networks Available WIFI access points will be displayed.
AT+CWJAP=“<SSID>“,“<WIFIpassword>“ WIFI CONNECTED
WIFI GOT IP
OK
Connects to the WIFI network with SSID + WIFIpassword
AT+CWDHCP_DEF=1,1 OK Enable DHCP, set ESP8266 as station
AT+PING=“<IPv4address>“ ping response Pings an IP address

Stumbling block #4

If the module appears to have no firmware it is necessary to flash the firmware.

ESP8266 on Arduino

An Arduino can be used to program the ESP8266. Assuming that this simple Arduino sketch was uploaded to the Arduino first:

#define SSID "<SSID>"
#define PASS "<WIFIpassword>"
#define IP "<IPv4adress>"

void setup() { 
  Serial.begin(115200);  // set baud rate
  
  Serial.println("AT");
  delay(5000);
  if( Serial.find("OK") ){
    connectToWiFi();
  }
}

void loop(){
  // generate some traffic
  ping();
  delay(10000);
}

void connectToWiFi(){
  // enable DHCP and set ESP8266 as station
  Serial.println("AT+CWDHCP_CUR=1,1");
  delay(2000);
  // connect to the WIFI network
  String cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  Serial.println(cmd);
}

void ping() {
    String cmd="AT+PING=\"";
    cmd += IP;
    cmd += "\"";
    Serial.println(cmd);
}

The program sets up a WiFi connection to the desired network and generates some network traffic using ping. The network traffic can be observed using tcpdump (Linux) for example.

Stumbling block #5/6

ESP8266 must be powered off and RX/TX lines must be connected to the Arduino everytime the sketch is uploaded. 😉

Stumbling block #7

Once the Arduino is generating the AT commands for the ESP8266 the setup has to be slightly changed:

Arduino Pro Mini, 3,3 V
GND in GND 5 V power supply
VCC in VCC 5 V power supply
RX TX ESP8266
TX RX ESP8266
DTR not connected
RST not connected
ESP8266 module
GND GND 3.3V power supply
VCC VCC 3.3V power supply
RX TX Arduino
TX RX Arduino
CHPD VCC 3.3V power supply via 10k resistor
REST VCC 3.3V power supply via 10k resistor

esp8266onarduino_breadboard

Now the Arduino should be able to connect to the local WiFi network and should ping the desired IP every couple of seconds.

Advertisements

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s