11. ESP8266+Arduino workshop 2015
ESP8266 test
Communicate with ESP8266 using Serial converter on our
Arduino board
● Vcc = 3V3
● GND
● URXD = serial RX = pin0
● UTXD = serial TX = pin1
note: pins seem 5V tolerant
12. ESP8266+Arduino workshop 2015
ESP8266 test
Communicate with ESP8266 using Serial converter on our
Arduino board (RX, TX)
Upload any sketch not using Serial e.g. blink
Connect ESP module
Open IDE Serial Monitor
Baud rate = 9600
Setting = “Both NL & CR”
13. ESP8266+Arduino workshop 2015
ESP8266 test
AT commands of standard firmware
AT+RST reset
AT+GMR check firmware version
AT+CWMODE=3 set mode to AP+STA
AT+CWLAP list wifi networks
AT+CWJAP=”ssid”,”password” connect to your wifi
AT+CIOBAUD? check baud rate
AT+CIOBAUD=9600 set new baud rate
https://nurdspace.nl/ESP8266
14. ESP8266+Arduino workshop 2015
ESP8266 and software serial
Arduino board has 1 hardware Serial on pin0 and pin1
but this is also used for uploading and for Serial Monitor
Some earlier modules had baud rate 115200 and their
firmware did not allow to change it. would only work with
hardware Serial, so Serial Monitor over software Serial +
USB converter
15. ESP8266+Arduino workshop 2015
ESP8266 and software serial
Better solution:
use updated firmware to allow 9600 baud
then can use software Serial for ESP8266
and hardware Serial for uploading/monitor as always
new modules come set with default 9600 baud
no update of firmware necessary
software serial on e.g. pin10 and pin11
standard Arduino library
16. ESP8266+Arduino workshop 2015
ESP8266 setup
ESP8266 can act as:
WEB SERVER
serve web pages over existing wifi network
ACCESS POINT
create its own wifi network + web server
WEB CLIENT
communicate with web servers (e.g. thingspeak.com)
over existing wifi network
17. ESP8266+Arduino workshop 2015
ESP8266 web server
AT+RST reset
AT+CWMODE=1 configure as node
AT+CWLAP list access points
AT+CWJAP=”ssid”,”pwd” connect to your wifi
AT+CIFSR show ip address
AT+CIPMUX=1 allow multiple connects
AT+CIPSERVER=1,80 start server on port 80
go to browser and type IP address
check reply in serial monitor
18. ESP8266+Arduino workshop 2015
ESP8266 web server
go to browser and type IP address
check reply in serial monitor
+IPD, 0 [means connection id = 0]
AT+CIPSEND=0,12
hello world [enter]
AT+CIPCLOSE=0
see browser
19. ESP8266+Arduino workshop 2015
ESP8266 access point
AT+RST reset
AT+CWMODE=2 configure as access point
AT+CWSAP? get your AP details
AT+CWSAP=”ssid”,”pwd”,1,3
define your wifi AP
change to unique ssid
connect to the AP with your phone
AT+CIFSR show ip address
AT+CIPMUX=1 allow multiple connects
AT+CIPSERVER=1,80 start server on port 80
go to browser and type IP address
check reply in serial monitor
20. ESP8266+Arduino workshop 2015
ESP8266 web client
AT+RST reset
AT+CWMODE=1 configure as node
AT+CWJAP=”ssid”,”pwd” connect to your wifi
AT+CIPSTART=”TCP”,”184.106.153.149”,80
connect to TCP socket
AT+CIPSEND= 4
wait for “>”
GET [enter]
check reply
21. ESP8266+Arduino workshop 2015
ESP8266 web client
ARDUINO SKETCH
send commands over software serial
espSerial.println("AT+RST");
construct String to send commands
AT+CIPSTART=”TCP”,”184.106.153.149”,80
String cmd;
cmd = "AT+CIPSTART="TCP","";
cmd += THINGSPEAK_IP;
cmd += "",80";
espSerial.println(cmd);
22. ESP8266+Arduino workshop 2015
ESP8266 web client
ARDUINO SKETCH
construct HTTP request to be sent
String cmd;
cmd = "GET /update?key=xxxxxxxxxxxxxxxxxx&field1=";
cmd += temp;
cmd += "rn";
send the length of the command
espSerial.print("AT+CIPSEND=");
espSerial.println(cmd.length());
wait for “>” with espSerial.find(">")
espSerial.println(cmd);
decode the reply with espSerial.find("SEND OK")
23. ESP8266+Arduino workshop 2015
thingspeak.com
create an account on thingspeak.com
create a channel
make public
enter description
field 1: temperature
field 2: humidity
save
get API Write Key
test in browser http://api.thingspeak.com/update?
key=APIKEY&field1=23.66
24. ESP8266+Arduino workshop 2015
CONNECTIONS:
● 5V
● GND
● SIGNAL with pull-up resistor
ARDUINO LIBRARY
https://github.com/adafruit/DHT-sensor-library
ARDUINO SKETCH
#include <DHT.h>
DHT dht(3, DHT11);
pinMode(3, INPUT); // DHT11
dht.begin();
float h = dht.readHumidity();
float t = dht.readTemperature();
DHT11 setup
25. ESP8266+Arduino workshop 2015
ESP8266-thingspeak-dht11-test sketch
22.00degC 59.00% reset ESP8266..
ó#âáT%ÐÇCÁaæ l!ÈÅèchKäFgÚ¡P¥øäæ |cø
[Vendor:www.ai-thinker.com Version:0.9.2.4]
ready
AT+CWMODE=1
no change
AT+CWJAP="tobback","xxxx"
OK
AT+CIPMUX=0
OK
AT+CIPSTART="TCP","184.106.153.149",80
OK [or Error]
Linked
AT+CIPSEND=60
> GET /update?key=RD9SEODFNKIBZ11M&field1=22.00&field2=59.00
wrong syntax
ERROR
SEND OK
+IPD,4:2107
OK
26. ESP8266+Arduino workshop 2015
ESP8266-thingspeak-dht11-v3 sketch
check espSerial feedback to know if commands are working
send status over Serial for debugging
DHT11 sensor sending data to THINGSPEAK.COM by ESP8266
sample interval (s): 5
22.00degC 57.00% reset ESP8266..module ready..connected to wifi..>send
thingspeak.com OK.. receive OK!
22.00degC 59.00% reset ESP8266..module ready..cannot connect to wifi
cannot connect to wifi
connected to wifi..>send thingspeak.com OK.. receive OK!
22.00degC 58.00% reset ESP8266..module ready..cannot connect to wifi
connected to wifi..>send thingspeak.com OK.. receive OK!
27. ESP8266+Arduino workshop 2015
ESP8266-twitter-dht11-v3 sketch
twitter via thingspeak.com: tweet from your Arduino
in Thingspeak:
add app ThingTweet
link to twitter account
in sketch:
“GET
/apps/thingtweet/1/statuses/update/api_key=KEY&status=”;
28. ESP8266+Arduino workshop 2015
ESP8266 with Arduino IDE
Customised IDE using esptool to upload/flash Arduino-style
sketches https://github.com/esp8266/Arduino
Needs Serial-USB converter (UART)
29. ESP8266+Arduino workshop 2015
ESP8266 with Arduino IDE
Hardware connections:
pull GPIO0 to GND (programming mode)
connect URXD to TX
connect URXD to RX
power off/on
in IDE:
set Tools / Programmer / esptool
set Tools / Board / generic ESP8266
set Tools / Port / xxx/usb0
upload BLINK with pin = 0 = GPIO0
release GPIO0 from GND
connect GPIO0 to LED
30. ESP8266+Arduino workshop 2015
ESP8266 with Arduino IDE
use high level libraries:
#include <ESP8266WiFi.h>
...
WiFiServer server(80);
WiFi.begin(ssid, password);
WiFiClient client = server.available();
...
String req = client.readStringUntil('r');
...
client.print(s);