standard Arduino workshop 2014-2015
ESP8266+Arduino
Tom Tobbackwww.cassiopeia.hk2015
ESP8266+Arduino workshop 2015
Materials
ESP8266+Arduino workshop 2015
Arduino and wifiOfficial Arduino wifi shieldEUR 69 + VAT
Sparkfun CC3000 shieldUSD 40
Adafruit CC3000 moduleUSD 35
ESP8266+Arduino workshop 2015
ESP8266 wifi module
small
powerfull
cheap
=> IoT
ESP8266+Arduino workshop 2015
Todays setup
ESP8266+Arduino workshop 2015
ESP8266 wifi module
dont need microcontroller2 GPIO pins availableon ESP-01
more on ESP-12
ESP8266+Arduino workshop 2015
ESP8266 wifi moduledirect programming over USB/UARTwithout using Arduino board as micro-controller
1. esptool.py
2. NodeMCU - Lua
3. Arduino IDE!
https://github.com/esp8266/Arduino
ESP8266+Arduino workshop 2015
Todays setup
ESP8266+Arduino workshop 2015
Downloadshttp://www.dimsumlabs.com/
click on ESP8266 event
DHT library zipped zip file with:
esp8266-thingspeak-dht11-testesp8266-thingspeak-dht11-v3esp8266-dht11-webserverWiFiWebServer-dht11-led
ESP8266+Arduino workshop 2015
ESP8266 pinout
Vcc = 3V3 GNDUTXD = serial TXURXD = serial RXRST = reset
CH_PD = pull up 4.6kOhmGPIO0 = input/outputGPIO2 = input/output
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
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. blinkConnect ESP moduleOpen IDE Serial MonitorBaud rate = 9600Setting = Both NL & CR
ESP8266+Arduino workshop 2015
ESP8266 testAT commands of standard firmware
AT+RST resetAT+GMR check firmware version
AT+CWMODE=3 set mode to AP+STAAT+CWLAP list wifi networksAT+CWJAP=ssid,password connect to your wifiAT+CIOBAUD? check baud rateAT+CIOBAUD=9600 set new baud rate
https://nurdspace.nl/ESP8266
ESP8266+Arduino workshop 2015
ESP8266 and software serialArduino board has 1 hardware Serial on pin0 and pin1but this is also used for uploading and for Serial MonitorSome 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
ESP8266+Arduino workshop 2015
ESP8266 and software serialBetter solution:use updated firmware to allow 9600 baudthen can use software Serial for ESP8266and hardware Serial for uploading/monitor as always
new modules come set with default 9600 baudno update of firmware necessary
software serial on e.g. pin10 and pin11standard Arduino library
ESP8266+Arduino workshop 2015
ESP8266 setupESP8266 can act as:
WEB SERVERserve web pages over existing wifi network
ACCESS POINTcreate its own wifi network + web server
WEB CLIENTcommunicate with web servers (e.g. thingspeak.com)over existing wifi network
ESP8266+Arduino workshop 2015
ESP8266 web serverAT+RST resetAT+CWMODE=1 configure as nodeAT+CWLAP list access pointsAT+CWJAP=ssid,pwd connect to your wifiAT+CIFSR show ip addressAT+CIPMUX=1 allow multiple connectsAT+CIPSERVER=1,80 start server on port 80
go to browser and type IP addresscheck reply in serial monitor
ESP8266+Arduino workshop 2015
ESP8266 web servergo to browser and type IP addresscheck reply in serial monitor
+IPD, 0 [means connection id = 0]
AT+CIPSEND=0,12hello world [enter]AT+CIPCLOSE=0
see browser
ESP8266+Arduino workshop 2015
ESP8266 access pointAT+RST resetAT+CWMODE=2 configure as access pointAT+CWSAP? get your AP detailsAT+CWSAP=ssid,pwd,1,3
define your wifi APchange to unique ssid
connect to the AP with your phoneAT+CIFSR show ip addressAT+CIPMUX=1 allow multiple connectsAT+CIPSERVER=1,80 start server on port 80go to browser and type IP addresscheck reply in serial monitor
ESP8266+Arduino workshop 2015
ESP8266 web clientAT+RST resetAT+CWMODE=1 configure as nodeAT+CWJAP=ssid,pwd connect to your wifiAT+CIPSTART=TCP,184.106.153.149,80
connect to TCP socket
AT+CIPSEND= 4wait for >GET [enter]check reply
ESP8266+Arduino workshop 2015
ESP8266 web clientARDUINO SKETCH send commands over software serial
espSerial.println("AT+RST");
construct String to send commandsAT+CIPSTART=TCP,184.106.153.149,80String cmd; cmd = "AT+CIPSTART=\"TCP\",\"";cmd += THINGSPEAK_IP;cmd += "\",80";espSerial.println(cmd);
ESP8266+Arduino workshop 2015
ESP8266 web clientARDUINO SKETCH
construct HTTP request to be sentString cmd;cmd = "GET /update?key=xxxxxxxxxxxxxxxxxx&field1=";cmd += temp;cmd += "\r\n";send the length of the commandespSerial.print("AT+CIPSEND=");espSerial.println(cmd.length());
wait for > with espSerial.find(">")espSerial.println(cmd);decode the reply with espSerial.find("SEND OK")
ESP8266+Arduino workshop 2015
thingspeak.comcreate an account on thingspeak.comcreate a channelmake publicenter description
field 1: temperaturefield 2: humidity
saveget API Write Key
test in browser http://api.thingspeak.com/update?key=APIKEY&field1=23.66
ESP8266+Arduino workshop 2015
CONNECTIONS: 5V GND SIGNAL with pull-up resistor
ARDUINO LIBRARYhttps://github.com/adafruit/DHT-sensor-library
ARDUINO SKETCH#include DHT dht(3, DHT11);pinMode(3, INPUT); // DHT11dht.begin();float h = dht.readHumidity();float t = dht.readTemperature();
DHT11 setup
ESP8266+Arduino workshop 2015
ESP8266-thingspeak-dht11-test sketch
22.00degC 59.00% reset ESP8266..#T%Ca l!chKFgP |c[Vendor:www.ai-thinker.com Version:0.9.2.4]readyAT+CWMODE=1no changeAT+CWJAP="tobback","xxxx"OKAT+CIPMUX=0OKAT+CIPSTART="TCP","184.106.153.149",80OK [or Error]LinkedAT+CIPSEND=60> GET /update?key=RD9SEODFNKIBZ11M&field1=22.00&field2=59.00wrong syntaxERRORSEND OK+IPD,4:2107OK
ESP8266+Arduino workshop 2015
ESP8266-thingspeak-dht11-v3 sketch
check espSerial feedback to know if commands are workingsend status over Serial for debugging
DHT11 sensor sending data to THINGSPEAK.COM by ESP8266sample 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 wificannot connect to wificonnected to wifi..>send thingspeak.com OK.. receive OK!22.00degC 58.00% reset ESP8266..module ready..cannot connect to wificonnected to wifi..>send thingspeak.com OK.. receive OK!
ESP8266+Arduino workshop 2015
ESP8266-twitter-dht11-v3 sketch
twitter via thingspeak.com: tweet from your Arduino
in Thingspeak:add app ThingTweetlink to twitter account
in sketch:GET /apps/thingtweet/1/statuses/update/api_key=KEY&status=;
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)
ESP8266+Arduino workshop 2015
ESP8266 with Arduino IDE
Hardware connections:pull GPIO0 to GND (programming mode)connect URXD to TXconnect URXD to RXpower off/on
in IDE:set Tools / Programmer / esptoolset Tools / Board / generic ESP8266set Tools / Port / xxx/usb0
upload BLINK with pin = 0 = GPIO0release GPIO0 from GNDconnect GPIO0 to LED
ESP8266+Arduino workshop 2015
ESP8266 with Arduino IDE
use high level libraries:
#include ...WiFiServer server(80);WiFi.begin(ssid, password);WiFiClient client = server.available();...String req = client.readStringUntil('\r');...client.print(s);
standard Arduino workshop 2014-2015
Thank you
www.cassiopeia.hk
Happy tinkering!
Top Related