How to use the ESP8266 to give your Arduino or Raspberry Pi boards wireless capabilities.
Many projects require some kind of communication between different devices and the goal of this article is to introduce you to the basics of connecting a microcontroller to the internet wirelessly by utilizing an ESP8266 breakout board.
HARDWARE 1 Arduino UNO 1 Raspberry Pi B+ 1 ESP8266
Longer code examples for this tutorial are available for download at the end of the article.
Testing the Wireless Adapter With Arduino
The bootloader of some Arduinos can be disabled by connecting the reset pin to ground. This will allow you to directly communicate with a device (like the ESP8266) that is connected to the board’s serial port:
Many different breakout boards are available so I can’t give you a general hookup guide for each one. Some require additional resistors and capacitors to work safely. Consult your board’s documentation for further information!
You can then start the Arduino IDE and open a new serial monitor. Set the baud rate to 115200 (some older adapters might use 9600) and the line ending to “Both NL & CR”. Then type “AT+GMR” in the input field and hit enter. The response should look like this:
Understanding AT Commands
These are used to connect the adapter to a network, send and receive data and disconnect the device. It only accepts a relatively small number of instructions but some devices, like cellular adapters, can interpret additional commands for making phone calls, etc.
Anyway, let’s start with establishing a Wi-Fi connection:
AT+CWJAP="SSID","password"
Replace SSID with your network’s name and type your password. You should receive an answer similar to mine:
AT+CWMODE?
AT+CWMODE=1
Setting it to mode one will make the adapter behave like a client device. Mode two is for servers and mode three is the dual mode.
Upon connecting, you can communicate with a server:
The first command:
AT+CIPSTART=”TCP”, “server”, port
AT+CIPSEND=number_of_bytes
This was a short summary of the most important commands. Refer to this page for a full list of supported instructions.
Using the ESP8266 With a Raspberry Pi.
sudo screen /dev/serial0 115200
Interfacing the Adapter from Arduino Code
Please insert the ESP8266-Arduino-test-program.txt here
Interfacing the Adapter With Linux and C
Please insert the ESP8266-test-program.txt here
The ESP8266 can easily be interfaced by any device that supports a serial connection.
However, the Arduino Software Serial library can be a bit slow, so you should try to directly connect the adapter to the Arduino’s serial interface in a finished project (and remove the serial debug output) to ensure proper readouts.
The Raspberry Pi doesn’t suffer from these issues because the hardware is accessed directly.
Thanks!!!
ReplyDeleteI visited your website is really nice👍🏻✌🏻