WiFi ESP8266
Last updated
Last updated
This module uses ESP8266EX's official model ESP-WROOM-02D, 4MB QSPI Flash. The module is certified by 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 as the development environment.
URL:http://arduino.esp8266.com/stable/package_esp8266com_index.json. Paste it into the URL of the additional development board in the Arduino preferences.
Then open the "Board Manager" and enter ESP8266 or 8266 to search for the board support package:
Download the package ESP8266 by ESP8266 Community.
After the board support package downloaded, we select ESP8266 Board (current version: 2.74) -> 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 use 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 downloader, and download the Blink example.
Compared with the Arduino UNO, the compilation time is slightly longer, after Linking, the download progress will be displayed as a percentage:
The "Blink sketch" uses 257KB of flash and 26.8KB of the SRAM.
Project URL:https://github.com/PetoiCamp/OpenCat/tree/main/ModuleTests/ESP8266WiFiController
There're 3 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 downloader to the WiFi module, we strongly recommend run it with your USB downloader so you can get the serial output in the Arduino serial monitor.
Open your smartphone WiFi scanner and find an access point named "Bittle-AP" that is not encrypted. 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 all nearby WiFi SSIDs and display them. After you click on your own WiFi SSID and enter the password, Bittle will connect to this network first.
Bittle will print out the IP address assigned by DHCP through the serial port after connecting to the WiFi successfully. You can also configure a fixed IP address in Arduino.
Enter the IP address of the WiFi module, now you can 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 while we need to change the network environment.
We use the WiFi manager library to configure the WiFi information through web.
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 serial port of the WiFi module 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:
After parsing the "name" parameter, we send the actionpage again.
We bond the handler method with the corresponding URLs.
Compared to the ATMega328P on the NyBoard, there’re more hardware and software resources on the ESP8266, 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.