Friday 20 March 2015

Interfacing the ESP8266 WIFI module to an Arduino



The current ESP8266 library project is called 'WeeESP8266'.

The WeeESP8266 Arduino API documentation is located here and the library files can be downloaded here from Github.

The  ESP8266 interface uses standard 'AT' (attention) commands. It uses the same type of commands that were used in MODEMs . . . . remember them? Below is a list of the standard commands but be aware that this may change with time.


AT COMMANDS
NOTE: There are must be no any spaces between the " and IP address or port

CommandsDescriptionTypeSet/ExecuteInquirytestParametersExamples
AT+RSTrestart the modulebasic----
AT+CWMODEwifi modewifiAT+CWMODE=<mode>AT+CWMODE?AT+CWMODE=?1= Sta, 2= AP, 3=both
AT+CWJAPjoin the APwifiAT+ CWJAP =<ssid>,< pwd >AT+ CWJAP?-ssid = ssid, pwd = wifi password
AT+CWLAPlist the APwifiAT+CWLAP
AT+CWQAPquit the APwifiAT+CWQAP-AT+CWQAP=?
AT+ CWSAPset the parameters of APwifiAT+ CWSAP= <ssid>,<pwd>,<chl>, <ecn>AT+ CWSAP?ssid, pwd, chl = channel, ecn = encryptionConnect to your router: :AT+CWJAP="YOURSSID","helloworld"; and check if connected: AT+CWJAP?
AT+ CIPSTATUSget the connection statusTCP/IPAT+ CIPSTATUS
AT+CIPSTARTset up TCP or UDP connectionTCP/IP1)single connection (+CIPMUX=0) AT+CIPSTART= <type>,<addr>,<port>; 2) multiple connection (+CIPMUX=1) AT+CIPSTART= <id><type>,<addr>, <port>-AT+CIPSTART=?id = 0-4, type = TCP/UDP, addr = IP address, port= portConnect to another TCP server, set multiple connection first: AT+CIPMUX=1; connect: AT+CIPSTART=4,"TCP","X1.X2.X3.X4",9999
AT+CIPSENDsend dataTCP/IP1)single connection(+CIPMUX=0) AT+CIPSEND=<length>; 2) multiple connection (+CIPMUX=1) AT+CIPSEND= <id>,<length>AT+CIPSEND=?send data: AT+CIPSEND=4,15 and then enter the data
AT+CIPCLOSEclose TCP or UDP connectionTCP/IPAT+CIPCLOSE=<id> or AT+CIPCLOSEAT+CIPCLOSE=?
AT+CIFSRGet IP addressTCP/IPAT+CIFSRAT+ CIFSR=?
AT+ CIPMUXset mutiple connectionTCP/IPAT+ CIPMUX=<mode>AT+ CIPMUX?0 for single connection 1 for mutiple connection
AT+ CIPSERVERset as serverTCP/IPAT+ CIPSERVER= <mode>[,<port> ]mode 0 to close server mode, mode 1 to open; port = portturn on as a TCP server: AT+CIPSERVER=1,8888, check the self server IP address: AT+CIFSR=?
+IPDreceived data






WeeESP8266 API
bool    kick (void) : Verify ESP8266 whether live or not.

bool    restart (void) : Restart ESP8266 by "AT+RST".

String  getVersion (void) : Get the version of AT Command Set.

bool    setOprToStation (void) : Set operation mode to staion.

bool    setOprToSoftAP (void) : Set operation mode to softap.

bool    setOprToStationSoftAP (void) : Set operation mode to station + softap.

String  getAPList (void) : Search available AP list and return it.

bool    joinAP (String ssid, String pwd) : Join in AP. 

bool    leaveAP (void) : Leave AP joined before. 

bool    setSoftAPParam (String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4) : Set SoftAP parameters. 

String  getJoinedDeviceIP (void) : Get the IP list of devices connected to SoftAP. 

String  getIPStatus (void) : Get the current status of connection(UDP and TCP). 

String  getLocalIP (void) : Get the IP address of ESP8266. 

bool    enableMUX (void) : Enable IP MUX(multiple connection mode). 

bool    disableMUX (void) : Disable IP MUX(single connection mode). 

bool    createTCP (String addr, uint32_t port) : Create TCP connection in single mode. 

bool    releaseTCP (void) : Release TCP connection in single mode. 

bool    registerUDP (String addr, uint32_t port) : Register UDP port number in single mode. 

bool    unregisterUDP (void) : Unregister UDP port number in single mode. 

bool    createTCP (uint8_t mux_id, String addr, uint32_t port) : Create TCP connection in multiple mode. 

bool    releaseTCP (uint8_t mux_id) : Release TCP connection in multiple mode. 

bool    registerUDP (uint8_t mux_id, String addr, uint32_t port) : Register UDP port number in multiple mode. 

bool    unregisterUDP (uint8_t mux_id) : Unregister UDP port number in multiple mode. 

bool    setTCPServerTimeout (uint32_t timeout=180) : Set the timeout of TCP Server. 

bool    startServer (uint32_t port=333) : Start Server(Only in multiple mode).

bool    stopServer (void) : Stop Server(Only in multiple mode).

bool    startTCPServer (uint32_t port=333) : Start TCP Server(Only in multiple mode). 

bool    stopTCPServer (void) : Stop TCP Server(Only in multiple mode). 

bool    send (const uint8_t *buffer, uint32_t len) : Send data based on TCP or UDP builded already in single mode. 

bool    send (uint8_t mux_id, const uint8_t *buffer, uint32_t len) : Send data based on one of TCP or UDP builded already in multiple mode. 

uint32_t    recv (uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from TCP or UDP builded already in single mode. 

uint32_t    recv (uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from one of TCP or UDP builded already in multiple mode. 

uint32_t    recv (uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from all of TCP or UDP builded already in multiple mode. 



Wiring connections to Arduino


MEGA

Serial 1 can be used. Create an object (named wifi) of class ESP8266 in your code like this:

#include "ESP8266.h" ESP8266 wifi(Serial1);

The connection should be like these:

ESP8266_TX  ->  RX1(D19) 

ESP8266_RX  ->  TX1(D18) 

ESP8266_CH_PD  ->  3.3V 

ESP8266_VCC  ->  3.3V 

ESP8266_GND  ->  GND




UNO

Software Serial can be used. Create an object (named wifi) of class ESP8266 in your code like this:

#include "ESP8266.h" 
#include <SoftwareSerial.h> 

SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */ 
ESP8266 wifi(mySerial);

The connection should be like these:

ESP8266_TX  ->  RX(D3)
 
ESP8266_RX  ->  TX(D2)
 
ESP8266_CH_PD  ->  3.3V
 
ESP8266_VCC  ->  3.3V
 
ESP8266_GND  ->  GND












Tuesday 17 March 2015

IoT - Using the ESP8266 WIFI module to make a Web Enabled LED



ESP8266 Module


Info & Guides

NurdSpace complete guide

Electrodragon

LUA Programming Language

http://www.esp8266.com/


Software

CoolTerm - Free Serial Terminal Emulator

nodemcu Firmware & Programmer - LUA Firmware

LuaLoader - Great MultiFunctional software (run the file as Administrator if you do not see your comm port)

ESPlorer - IDE for ESP8266 developers






Pin-Outs

ESP8266




CH340 Programmer





Quick Guide

  1. Wire up 8266 as per schematic above.
  2. Confirm communications are working to the 8266 with Coolterm.
  3. Set the 8266 into 'Flash update' mode by setting GPI00 to GND.
  4. Reset the power to the device.
  5. Download Flasher & firmware found here and flash the firmware to the ESP8266.
  6. Confirm comms again with Coolterm noting the change in firmware.
  7. Set the 8266 into 'Flash update' mode by setting GPI00 to GND.
  8. Reset the power to the device.
  9. Download nodemcu found here and flash the ESP8266 with 'ESP8266Flasher' using the default binary (nodemcu_latest.bin: 0x00000).
  10. Confirm comms again with Coolterm. a status line similar to
  11. 'NodeMCU 0.9.5 build 20150311 powered by Lua 5.1.4' will indicate LUA firmware is now installed.
  12. Download LuaLoader from here and set it to your correct Com Port. If LuaLoader does not see your Com Port set it to run as 'Administrator' in the file compatibility settings.
  13. You can now use LuaLoader to load programs onto the ESP8266 like the one below . . .



Webserver with web enabled LED



lua code


wifi.setmode(wifi.STATION);
wifi.sta.config({ssid="YOURROUTERNAME",pwd="YOURROUTERPASSWORD"});
gpio.mode(4, gpio.OUTPUT)
srv=net.createServer(net.TCP) 
srv:listen(80,function(conn) 
    conn:on("receive", function(client,request)
        local buf = "";
        local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
        if(method == nil)then 
            _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); 
        end
        local _GET = {}
        if (vars ~= nil)then 
            for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do 
                _GET[k] = v 
            end 
        end
        buf = buf.."<h1><b> Arduino Virgins - IoT LED</b></h1><form src=\"/\">Turn GPIO2 <select name=\"pin\" onchange=\"form.submit()\">";
        local _on,_off = "",""
        if(_GET.pin == "ON")then
              _on = " selected=true";
              gpio.write(4, gpio.HIGH);
        elseif(_GET.pin == "OFF")then
              _off = " selected=\"true\"";
              gpio.write(4, gpio.LOW);
        end
        buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>";
        client:send(buf);
        client:close();
        collectgarbage();
    end)

end)





Notes


  • Replace YOUROUTERNAME with the name of your own router and YOUROUTERPASSWORD with your routers password.
  • Upload this code using LuaLoader by copying it to your clipboard and using the 'Paste Text' button in LuaLoader to upload it to the ESP8266.
  • Connect an LED negative to a 220Ohm resistor, and the other end of the resistor to GND. Then connect the positive end of the LED to the GPIO2 pin on the ESP8266. . . . schematic to follow.
  • Use the 'Get IP' button in LuaLoader to get the IP address of the ESP8266(if you do not see a response of 'nil'you probably have the wrong routername and password setup in the above step).
  • Put the first address in your web browser. Its normally something like 192.168.0.20


You should see the following web page






ESP8266 PROJECT NOTES


  • My ESP8266-01 Module was set to 9600 baud by default.
  • After flashing it with ver  0.92 baud rate was 115200bps.
  • It CAN NOT be powered by the CH340 programmer. It has to have its own supply of 3.3v @ 20-250mA.



A high percentage of the project information was taken from Julian Ilets Videos shown below.


Part 1 of 4

Part 2 of 4

Part 3 of 4

Part 4 of 4

This may also be useful. More information from Great Scott











Tuesday 3 March 2015

Conversions & Translations



Arduino Terms
Alternative Names For The Same Pin

SDA = MOSI = SDI

SCL = SCLK = SCK = CLK = CLOCK

CS = SS = CE

RST = RESET

RS = D/C = A0

MISO = SD0








Sunday 1 March 2015

Thursday 26 February 2015

TFT Displays



Using the 1.44" 128x128 TFT Display as a basic text screen
Both the Black & Red PCB versions of these screen use the ILI9163 controller chip.
!!! Note: Each version has its own unique driver.

1.44" 128x128 TFT Display (Black PCB version) sold by Electrasheep

Libraries Required
Drivers & Sketch code (both Black & Red PCBs) - Electrasheep forum

MultiFont Graphics Driver & Great Usage ReadMe - Electrasheep forum


Guides
MultiFont Adafruit Graphics Library Read Me - Direct Download

Adafruit Graphics Library Guide - Original GFX library guide

Adafruit GFX Overview & detailed usage - by Adafruit

Dot Factory Font Creation Software - (See the MultiFont Guide above)



1.44 TFT Basic - Just a place holder atm. Will be updated soon







Arduino Libraries & Demo Code



Useful Libraries & Demo Code

Arduino Tutorial Reference Search Tool - by Visual Micro

HCSR04 Ultrasonic Project - Wiring Guide on Indistructables

HCSR04 Ultrasionic Demo - Code on Indistructables



Playing sounds on a Speaker or Piezo Sounder

Playing Tones - Code & Wiring

Pitch Follower Project - Code & Wiring

Playing a Melody - Code & Wiring







User Manuals for Arduino

Nano     








Interesting Projects



Keysweeper Pulls wireless keyboards keystrokes out of the air !

Thats nearly enough to make me go back to wired!

Internet LED Julian Ilets easy to follow project

Arduino Powered Night Light - Basic little project

Arduino-TVout - Composite video to use TV as Arduino Display !!!

Adruino Doorbell with recordable Wave file - by David Watt

8x8 LED Array driven by 74HC595 Shift registers - Arduino Hacks

RF Links Tutorial - Cheap and Easy Wireless Arduino!







Arduino Communities



On Google +

Arduino Tutorials

Arduino

Arduino basics






Wednesday 25 February 2015

Starting to Program the Arduino



Arduino Programming

Foundation in Arduino (by Arduino)

Language Reference (by Arduino)

Sketch Program examples (by Arduino)

Hacking guide - expanding on the basics (by Arduino)

Official Links (by Arduino)

Arduino Programming Notebook (v1.1) - Brian w. Evans



C & C++ General Programming Resources

Understanding Opperators (by Guy Lecky-Thompson)

Understanding Opperators (by exforsys)

Understanding Opperators (by Cplusplus)






Pin-outs & How to's - Common Components, Devices & Shields



Standard Displays

7 Segments display (Diagram from Pighixxx)

Hitachi 44780 Type LCD Displays (Pins Explained)

Hitachi 44780 Type LCD Displays (Wired in Parallel Pighixxx)

Hitachi 44780 Type LCD Displays (Wired in series using I2C)

Arduino LCD Key Pad Shield (by DFRobot)


LCD / TFT Displays

Watch this space! Have reams of stuff im working on . . .



LEDs

LED's (Great guide by Adafruit)

1088BS Green 8x8 LED Array - Data Sheet

MAXIM 7219 & 7221 LED Drivers - Arduino Playground



Laser
KY-008 Laser sensor module (TkkrLab)



Wireless

Nrf24L01 Wireless 2.4GHz Module (Great Tutorial)

Nrf24L01 Video Tutorial Project (by Jillian Ilett)

Nrf2401 Arduino Library (by maniacbug on GitHub)

Nrf2401 Arduino Library - Fixes the powerdown bug (by G Copeland)

UNBRICK Nfr24L01 - Video

ESP8266 EPS03 & Adapter boards









Clocks

DS1307 RTC Real Time Clock (by Henning Karlsen)










DS1302 RTC Real Time Clock (by Henning Karlsen)








KeyPad

Standard Keypad (by Henning Karlsen)


Relays

1 to 8 Relays (by Henning Karlsen)


SPI

Using free flash memory on some TFT displays (by Henning Karlsen)


SD Cards

SD Cards - over SPI (by Henning Karlsen)




Power

TP4056 - 5v Lithium Battery Charging Board (by Candle Power)




Programmers

CH340 USB to TTL Serial Converter - Windows & Linux Drivers

CH340 USB to TTL Serial Converter - Guide by ChilliTronix




Temperature

Melexis MLX90614 Non-Contact Temperature Sensor - Adafruit

LM34 LM35 Analogue Temperature Sensor - Adafruit








DS18B20 & DS18S20







DS18B20 Maxim Datasheet

DS18S20 Maxim Datasheet

DS18B20 Dallas/Maxim Digital Temp Sensor - Hobby Electronics

PJRC OneWire Libraries

DS18B20 Arduino Temperature Control Libraries - by Miles Burton

1 Wire Protocol Library in Depth - Arduino Playground




Humidity

DHT11






DHT11 Sensors - Arduino Playground (Great amount of quality info)







LDR - Light Dependant Resistor

Seeing The Light with an LDR



Switches

De-bouncing Switches so they don't trigger multiple times




Infrared

IR Communication - Great guide from Sparkfun

Phototransistor Fundamentals - Fairchild





page regularly updated . . . . . .













Pin-outs - Connecting and Wiring Arduinos



Connection 'Pin-Outs' for Arduino


Arduino UNO









Arduino Mega














Arduino Leonardo







Arduino Nano






Arduino Micro









Arduino Yun













From www.robgray.com





Arduino Due








Various Arduino pin-outs on a single page (by Henning Karlson)


Beginners Guide to Installing 3rd party / User Libraries



Non Interference


When starting out it is easy to get overwhelmed with 'problems'. To help things go smoothly I start with a clean system so initially to make sure that there is no interference between libraries remove all existing libraries from the user library area. This is normally found in a subdirectory called 'libraries' below the user sketch folder. In my case this is

C:\Users\Paul\Google Drive\Development\Arduino\libraries

Delete all the files in this directory.



Obviously this will remove any 3rd party libraries already installed but I have found it a valuable step to make sure a new library works correctly.

NOTE: This step is not compulsory and can be missed out if 100% confident or not a complete Virgin!


Installing User Libraries In the Arduino IDE

To install new libraries in Adruino IDE go to

Sketch|Import Library|Add Library

then navigate to the library to be installed. If it is a ZIP it will be decompressed and installed to the user library area mentioned above namely inside


C:\Users\Paul\Google Drive\Development\Arduino\libraries