ESP8266
1. What is ESP8266?
ESP8266 is an electronic component that enables the Arduino board to communicate with the Internet at low cost.
2. Wiring ESP8266 to Arduino.
The pinout of the ESP8266 is as follows.
You can connect the ESP8266 to Arduino as follows.
ESP8266_TX <-> ARDUINO_D3
ESP8266_RX <-> ARDUINO_D4
3. Configure ESP8266.
Settings are required to use the ESP8266.
ESP8266 can be set using AT command. (See detail)
First of all, you need to create and upload an Arduino sketch that allows you to set the AT command on the ESP8266.
ARDUINO SKETCH FOR ESP8266 AT COMMAND
#include <SoftwareSerial.h>
#define ESP8266_TX 3
#define ESP8266_RX 4
#define ESP8266_BAUD 9600
SoftwareSerial esp8266(ESP8266_TX, ESP8266_RX); // SoftwareSerial(RX, TX)
void setup()
{
Serial.begin(ESP8266_BAUD);
esp8266.begin(ESP8266_BAUD);
}
void loop()
{
while(Serial.available() > 0)
esp8266.write(Serial.read());
while(esp8266.available() > 0)
Serial.write(esp8266.read());
}
After uploading the above Sketch, you can use the Arduino serial monitor to forward the AT command to the ESP8266.
Verify connection with Arduino
If you type 'AT' and you will see 'OK'.
Set mode
If you want to connect only through other AP, then you type 'AT+CWMODE=1'.
(It is called station mode)
If you want to connect directly, then you type 'AT+CWMODE=2'.
(It is called AP mode)
If you want to use both method, then you type 'AT+CWMODE=3'.
Join to other AP
If you have set station mode, then you need to join ESP8266 to available other AP.
You must first know the SSID and Password of the AP you want to join.
If you know it, you type 'AT+CWJAP="SSID","Password"'.
(ex, AT+CWJAP="MySSID","MyPassword")
If it is succeed, you can see 'OK'.
Settings for AP
If you have set AP mode, then you need to set for operating as AP.
Four informations are required for AP operation.
(1) SSID name
(2) Password
(3) Channel ID (You can choose 1~13)
(4) Access method (Normally use WPA2_PSK)
If you have decided above, then you type 'AT+CWSAP="SSID","Password",5,3'.
4. Test TCP connection.
If you have completed all the settings, you should test whether the TCP connection is good.
You need required tool for testing TCP connections, the most commonly used program is Putty.
You can download Putty at the following link. (Download Putty)
IP address of ESP8266
If you type 'AT+CIFSR', then you can know IP address of ESP8266.
Start TCP Server
To test TCP connections, the ESP8266 must function as a TCP Server.
First, you need to set up multiple connections, you type 'AT+CIPMUX=1'.
A port number is required to be a TCP server.
If you type 'AT+CIPSERVER=1, port number', then TCP server is started.
(ex, AT+CIPSERVER=1,5000)
Run Putty
Raw type allows Putty to make TCP connections to ESP8266.
Send message from Putty to Arduino
Putty If you enter keyboard on the screen, you can check the message on the Aduno serial monitor.
Send message from Arduino to Putty
To send a message from Arduino, first you type 'AT+CIPSEND=0,4'.
0 means connection id and 4 means length of message.
You can type the actual message after it.
The message entered on the Arduino serial monitor can be seen on the Putty screen.
5. Make wired diagram in ARDUnity.
In ARDUnity, you can use CommWiFi to connect Block as follows.
ArdunityApp and CommWiFi can be configured as follows.
Stream Class chooses SoftwareSerial because of above circuit.
(Baudrate: 9600, RX Pin: 3, TX Pin: 4)
Select Filter Stream as ESP8266.
The TCP port of the filter stream and the TCP port of CommWiFi must be the same.
You can see this as an example of ARDUnity Deluxe.
(Assets/ARDUnity/Examples/ConnectionUI/WiFiConnection(ESP8266))
6. Test Unity connection
If you play Unity and run 'connect' of ArdunityApp, you will see that it is communicating with the ESP8266.