athens iot meetup #3 - introduction to esp8266 (pavlos isaris)

1

Upload: athens-iot-meetup

Post on 13-Apr-2017

241 views

Category:

Devices & Hardware


1 download

TRANSCRIPT

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.

Features● Very low cost ( 3-5$ )

● Pre-programmed with an AT command set firmware

● Growing community

● Enough on-board processing power to deal with sensors

through GPIO

● Operating at 3.3V

● Can draw up to 170 mA of current

● Not 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 ESP8266

There are plenty of tutorials about how to update the firmware

version

After 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 sent

In 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 ESP8266

Serial.begin(57600); while(!Serial); // UART serial debug

wifi.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.)