Esp8266 - Intro for dummies

Post on 08-Jan-2017

727 views 6 download

Transcript of Esp8266 - Intro for dummies

ESP8266“Designed for the needs of an increasingly connected

world”

Pavlos Isaris

IntroductionThe ESP8266 WiFi Module is a self contained SOC (system on a chip) with integrated TCP/IP protocol stack that can give any microcontroller access to a WiFi network.

FeaturesVery low cost ( 3-5$ )Pre-programmed with an AT command set firmwareGrowing communityEnough on-board processing power to deal with

sensors through GPIOOperating at 3.3VCan draw up to 170 mA of currentNot breadboard-friendly :-(

Βreadboard friendly version (ESP-12)

Why do we need a Voltage regulator?The ESP8266 may require more than the 35mA supplied by the Arduino 3.3V pin

Baud rate problemThe ESP-8266 comes in various firmware versions, varying also in the operating baud rate (older operate at 115200 bauds).My ESP8266 operates in 115200 bauds/second. This means that we can only use hardware serial to communicate with it (Arduino Software serial pins handle only 9600 bauds/second)In such occasion, it is possible to use an Arduino MEGA (4x Hardware serial couple-pins)

Alternative - Update firmware versionYou can also use an FTDI adapter (like the FT232rl) or FTDI cable, to communicate via USB with ESP8266There are plenty of tutorials about how to update the firmware versionAfter you have updated the firmware version you can change the baud rate

Multiple variations

Module GPIO Notes

ESP-01 GPIO0/2/16 Most common module.

ESP-02 GPIO0/2/15

ESP-03 GPIO0/2/12/13/14/15/16 Most popular in esp8266.com poll

ESP-04 GPIO0/2/12/13/14/15/16

ESP-05 None

ESP-06 GPIO0/2/12/13/14/15/16

ESP-07 GPIO0/2/4/5/12/13/14/15/16

ESP-08 GPIO0/2/12/13/14/15/16

ESP-09 GPIO0/2/12/13/14/15 1MB Flash memory

ESP-10 None

ESP-11 GPIO0/1

ESP-12 ADC + GPIO0/2/4/5/12/13/14/15/16

Recently adopted by many due to many GPIOs

Using Arduino IDE Serial Monitor#include <SoftwareSerial.h>SoftwareSerial ESPserial(2, 3); // RX | TX void setup() { Serial.begin(115200); // communication with the host computer ESPserial.begin(115200); Serial.println(""); Serial.println("Remember to to set Both NL & CR in the serial monitor."); Serial.println("Ready"); Serial.println(""); }

Using Arduino IDE Serial Monitorvoid loop() { // listen for communication from the ESP8266 and then write it to the serial monitor if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); } // listen for user input and send it to the ESP8266 if ( Serial.available()) { ESPserial.write( Serial.read() ); }}

Basic AT commands

Checking for available WiFi networks

Connect to Network

See details

Send a requestAllow multiple connections

Start connection

Specify bytes to be sentIn this case it is “GET / HTTP/1.0\r\n\r\n”

Get the response back

Acting as TCP Server

Acting as a Wifi Access point

ESP8266 core-library#include <Adafruit_ESP8266.h>

#include <SoftwareSerial.h>

#define ARD_RX_ESP_TX 2

#define ARD_TX_ESP_RX 3

#define ESP_RST 4

SoftwareSerial softser(ARD_RX_ESP_TX, ARD_TX_ESP_RX);

Adafruit_ESP8266 wifi(&softser, &Serial, ESP_RST);

#define ESP_SSID "SSIDNAME" // Your network name here

#define ESP_PASS "PASSWORD" // Your network password here

#define HOST "www.adafruit.com" // Host to contact

#define PAGE "/testwifi/index.html" // Web page to request

#define PORT 80 // 80 = HTTP default port

ESP8266 core-librarysoftser.begin(9600); // Soft serial connection to ESP8266Serial.begin(57600); while(!Serial); // UART serial debugwifi.connectToAP(F(ESP_SSID), F(ESP_PASS))

Serial.print(F("OK\nRequesting page..."));

if(wifi.requestURL(F(PAGE))) { Serial.println("OK\nSearching for string..."); if(wifi.find(F("working"), true)) { Serial.println(F("found!")); } else { Serial.println(F("not found.")); }} else { // URL request failed Serial.println(F("error")); }wifi.closeTCP();

Espert - Development board

http://www.espert.co/ (v2.0 To be released by April 2016.)