WiFi module ESP8266
Last updated
Last updated
This module uses the ESP8266EX's official model ESP-WROOM-02D, which has 4MB of QSPI Flash. It is certified by the FCC in the United States, CE-RED in Europe, TELEC in Japan, and KC in South Korea.
The module is fully opened. You can program it separately. This is not a simple, transparent transmission module.
The module includes an automatic download circuit and a communication module. The automatic download circuit refers to the official recommendation to use 2 S8050 transistors to receive the RTS and DTR signals from the CH340C downloader and trigger the download sequence.
Connect to the NyBoard:
Update sketches through USB downloader:
We use the Arduino IDE as the development environment.
You must download and install Arduino IDE first.
URL:http://arduino.esp8266.com/stable/package_esp8266com_index.json. Paste it into the Additional Boards Manager URLs in the Arduino IDE preferences.
Then open the Board Manager and input ESP8266 or 8266 to search for the board support package:
Download the latest version of ESP8266 from ESP8266 Community.
After downloading the board support package, we select Board -> ESP8266 -> Generic ESP8266 Module.
Then we set the parameters:
Parameters
Settings
Builtin Led
2
Upload Speed
921600(Auto-negotiation during downloading, 115200 is too slow)
CPU Frequency
160MHz
Flash Size
4MB
Reset Method
DTR reset
lwIP variant
V2 Lower memory
Erase Flash
Only sketch
After configuration, we used the Arduino classic "Blink" program to test the ESP8266 development board.
Open the Blink project, configure the development board, plug the module into the communication module debugging interface of the USB uploader (USB Adapter), and upload the Blink sketch.
Compared with the Arduino UNO, the compilation time is slightly longer. After Linking, the uploading progress will be displayed as follows:
Project URL:https://github.com/PetoiCamp/OpenCat/tree/main/ModuleTests/ESP8266WiFiController
There are three files in the project:
ESP8266WiFiController.ino: Arduino sketch with server core code.
mainpage.h: welcome page (HTML) in a char array.
actionpage.h: action controller page (HTML) in a char array.
Please put them in the folder named "ESP8266WiFiController", then open the ino file and download it to the ESP8266 WiFi module.
After the sketch is uploaded to the WiFi module, we strongly recommend running it with your USB uploader (USB Adapter) so you can get the serial output in the serial monitor of Arduino IDE.
Open the serial monitor in Arduino IDE as follows. Then, unplug and re-plug the WiFi module into the USB uploader.
Open your smartphone's WiFi scanner and find an unencrypted access point named "Bittle-AP." Connect it.
If your smartphone automatically optimizes your network connection, it will cut the connection of "Bittle-AP" because there is no Internet connection. Your smartphone may connect to the WiFi with an Internet connection or even use your cellular data.
Your smartphone may auto-jump to the "WiFiManager" page when connecting to "Bittle-AP."
If not, please open your browser and enter 192.168.4.1 to enter the WiFi connection configuration page manually.
On the WiFiManager page, Bittle's wireless module will automatically search for and display all nearby WiFi SSIDs. After you click on your WiFi SSID and enter the password, Bittle will connect to this network first.
After successfully connecting to the WiFi, Bittle will print out the IP address assigned by DHCP through the serial port on the serial monitor.
Enter the WiFi module's IP address in the web browser, and you can now control the Bittle through WiFi!
The sample code is a simple web server example, including 2 HTML pages. The two pages are stored in two header files in the form of string constants. The advantage is to avoid calling the client. print function constantly.
Before we start our web server, we should configure the WiFi to connect to your local area network(LAN). We used to enter the WiFi SSID and password in the program, but it is very inconvenient when we need to change the network environment.
We use the WiFi manager library to configure the WiFi information online.
Create a new web server and configure port 80 (commonly used HTTP server port)
The HTTP response function is to handle the incoming HTTP requests.
The handleMainPage and handleActionPage response 200 (OK) and corresponding web HTML code for your web browser (client).
The HandleAction function is slightly different. This is an HTTP request processing function with parameter passing. When the parameter is "gyro," the WiFi module's serial port sends out the command ("g", switch IMU) so that our Bittle will execute the command.
So, how is this "gyro" parameter generated and passed? Because we sent such an HTTP request with a value to the server:
The server parses the action parameter by the function and resolves that the name is "gyro".
We can directly enter this URL in the browser and execute it with the keyboard. The more common method is to add a link to the "Walk" button on the ActionPage web page. When the gyro button is pressed, the above URL will be sent to the host.
The complete walk button configuration is as follows:
We will send the action page again after parsing the "name" parameter.
We bond the handler method with the corresponding URLs.
Compared to the ATMega328P on the NyBoard, the ESP8266 has more hardware and software resources so that you can do more experiments with it.
Connect your Bittle to IoT platforms with HTTP restful APIs.
MQTT and node-red.
OTA with WiFi.
Make ESP8266 a strong co-processor for NyBoard for motion data fusion.