ESP8266

From Medien Wiki
Revision as of 23:06, 10 May 2016 by Mschied (talk | contribs)

Testing and using a ESP8266 board

Electronic Setup

http://www.uni-weimar.de/medien/wiki/images/Esp-201-cheatsheet.svg

Supply the board with 3.3V on VCC, best run it with a voltage source or regulator that can at least deliver 300mA (many arduino boards have 3.3V regulators on board, but they deliver less than 300mA). Initial testes just with a ftdi usb to serial converters show unstable wifi connections, sometimes even board startup is impossible (the esp8266 board draws too much current).

Testing the Board with AT Commands

full reference of all AT commands: http://bbs.espressif.com/download/file.php?id=256

first steps:

AT+RST - resets the board:
ATE1 (verbose)
ATE0 (non verbose)

pre-setup to either join a network (station mode) or create a new network acces point (AP)

AT+CWMODE=1 station mode (join an existing wifi network)
AT+CWMODE=2 access point mode (create a new wifi network)
AT+CWMODE=3 access point mode + station mode (create a wifi and join an other one at the same time)

select a network around you and join it:

AT+CWLAP list available networks around you that you could join.
AT+CWJAP="SSID","Your Password" (join a network with the ssid (visible name) and your wifi password)

or if you don't want to join an existing network, create your own:

AT+CWSAP_DEF="GoAway!!!","myAss!!!",1,0 (creates a wifi with the name GoAway!!! and an optional password: myAss!!! on channel 1. 
0 means "no encryption", so the password that was set before as myAss!!!" is not used here. (instead 0 setting to 3 uses wpa2_psk, so the password would be used) 
AT+CWDHCP_DEF=1 (turn on DHCP, so others can automatically get an IP address when they connect to your wifi)

either as a station or an AP create a simple server others can connect to:

AT+CIPMUX=1 (1: server accepts multiple connection, 0: single connections only)
AT+CIPSERVER=1,80 (1: create 0:destroy server, 80: listening on port 80)

now you can try to connect to your server, eg with your browser (not a good idea, but still interesting...) we need the ip address for that.

find the ip of your esp8266 board:

AT+CIFSR (wait until you get the below output)
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"1a:fe:34:d2:47:65"
+CIFSR:STAIP,"0.0.0.0"
+CIFSR:STAMAC,"18:fe:34:d2:47:65"

The first line shows the IP address of your board. you can now enter it in a browser: http://192.168.4.1:80 other convenient tests: in the shell: telnet, netcat in puredata: netsend

using the esp8266 with software serial

Arduino Pro Mini and ESP-8266.png

to be tried: https://github.com/itead/ITEADLIB_Arduino_WeeESP8266

simple sketch to test the software serial and the esp connected to it, based on softwareSerialExample.ino

AT+UART=9600,8,1,0,0

Sets the ESP8266 to 9600 baud, 8 databits, 1 stop bit no parity bit and no flow control.

/*
 * The circuit:
 * RX is digital pin 10 (connect to TX of the ESP8266)
 * TX is digital pin 11 (connect to RX of the ESP8266)
 *
 * This example code is in the public domain.
 */

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("AT+RST");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}


Use as a standalone Microcontroller Board

Enter Flash mode (to upload new firmware):

and try to upload the example patch below:

/* ESP8266 as an Arduino
 *  Wiring: 
 *  GPIO15 (IO15) to GND
 *  CHIP Enable to VCC (on some modules: CH_PD)
 *  GPIO0 (IO0) to GND
*/



void setup() {

  Serial.begin(115200);

}

void loop() {

  delay(1000);
  Serial.println("I'm there!!!!!");

}


Reverting Firmware to AT Firmware

get the latest Firmware on the espressif bbs home page: http://bbs.espressif.com/viewtopic.php?f=46&t=2054 (this was last checked 2016-05-10)

either use the flash download tool from the above linked page or for example the very useful esptool: https://github.com/themadinventor/esptool