Difference between revisions of "Template:Pico ESP8266 Guide"
(17 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
==Quick start== | ==Quick start== | ||
=== '''Hardware connection''' === | === '''Hardware connection''' === | ||
− | #Press and hold the BOOTSEL button of Pico, the pico will be recognized as a movable disk, copy the dev_cdc_ports.uf2 file from demo codes to the Pico, the Pico will automatically restart and work as the USB to serial adapter. | + | #Press and hold the BOOTSEL button of Pico, the pico will be recognized as a movable disk, copy the dev_cdc_ports.uf2 file from demo codes to the Pico, the Pico will automatically restart and work as the USB to serial adapter. |
#Connect the Pico_EPS8266 board to Pico, then connect the Pico to PC by USB cable. | #Connect the Pico_EPS8266 board to Pico, then connect the Pico to PC by USB cable. | ||
#Open an SSCOM software, choose the correct COM port, and set the baud rate to 115200. | #Open an SSCOM software, choose the correct COM port, and set the baud rate to 115200. | ||
− | #Test the module by AT command<br /> | + | #Test the module by AT command.<br /> |
[[File:Pico-ESP8266-01.png|border|800px]] | [[File:Pico-ESP8266-01.png|border|800px]] | ||
=== '''AT commands''' === | === '''AT commands''' === | ||
− | *1. AT | + | *1. AT: |
AT | AT | ||
Response: | Response: | ||
Line 14: | Line 14: | ||
OK | OK | ||
− | *2. AT+RST Restart device | + | *2. AT+RST Restart device: |
AT+RST | AT+RST | ||
Response: | Response: | ||
Line 20: | Line 20: | ||
OK | OK | ||
− | *3. AT+GMR Check version | + | *3. AT+GMR Check version: |
AT+GMR | AT+GMR | ||
− | Response | + | Response: |
AT+GMR | AT+GMR | ||
AT version:1.2.0.0(Jul 1 2016 20:04:45) | AT version:1.2.0.0(Jul 1 2016 20:04:45) | ||
Line 31: | Line 31: | ||
=== '''TCP Client''' === | === '''TCP Client''' === | ||
− | *1. Configure WiFi mode | + | *1. Configure WiFi mode. |
AT+CWMODE=3 //softAP+station mode | AT+CWMODE=3 //softAP+station mode | ||
Response: : | Response: : | ||
OK | OK | ||
− | *2. Connect to router | + | *2. Connect to the router. |
− | AT+CWJAP="SSID","password" //SSID and password of router | + | AT+CWJAP="SSID","password" //SSID and password of the router |
Response: : | Response: : | ||
AT+CWJAP="SSID","password" | AT+CWJAP="SSID","password" | ||
OK | OK | ||
− | :If it | + | : If it succeeds in connecting the WIFI, it will respond and get an IP address. |
WIFI CONNECTED | WIFI CONNECTED | ||
WIFI GOT IP | WIFI GOT IP | ||
− | *3. Check the IP address of ESP8266 | + | *3. Check the IP address of ESP8266. |
AT+CIFSR | AT+CIFSR | ||
Response: : | Response: : | ||
Line 52: | Line 52: | ||
OK | OK | ||
− | *4. PC and ESP8266 are connected to the same router, use the network debugging tool | + | *4. PC and ESP8266 are connected to the same router, use the network debugging tool on the PC end, and establish a TCP server.<br \> |
− | :For example, build a server | + | : For example, build a server on a PC with IP address 192.168.3.116 and port 8080.<br \> |
− | *5. ESP8266 | + | *5. ESP8266 works as a TCP client and connects to the server. |
AT+CIPSTART="TCP","192.168.3.116",8080 //protocol, server IP and port | AT+CIPSTART="TCP","192.168.3.116",8080 //protocol, server IP and port | ||
Response : | Response : | ||
Line 60: | Line 60: | ||
OK | OK | ||
− | *6. ESP8266 device ends data of a specified length to the server | + | *6. ESP8266 device ends data of a specified length to the server. |
AT+CIPSEND=4 //set date length which will be sent, such as 4 bytes | AT+CIPSEND=4 //set date length which will be sent, such as 4 bytes | ||
>test //enter the data, no CR | >test //enter the data, no CR | ||
Line 66: | Line 66: | ||
Recv 4 bytes | Recv 4 bytes | ||
SEND OK | SEND OK | ||
− | *7. The data is printed if ESP8266 | + | *7. The data is printed if ESP8266 receives data from the server. |
+IPD,n:xxxxxxxxxx //received n bytes, data=xxxxxxxxxxx | +IPD,n:xxxxxxxxxx //received n bytes, data=xxxxxxxxxxx | ||
*8. Enable the transparent transmission mode, data can be directly transmitted | *8. Enable the transparent transmission mode, data can be directly transmitted | ||
Line 77: | Line 77: | ||
> //From now on, data received from UART will be transmitted to the server automatically. | > //From now on, data received from UART will be transmitted to the server automatically. | ||
− | *10. Exit sending | + | *10. Exit sending data: |
If +++ is detected in a single packet of data during transparent transmission, the system stops transparent transmission.<br \> | If +++ is detected in a single packet of data during transparent transmission, the system stops transparent transmission.<br \> | ||
− | :- If you use the keyboard to type +++, it may take too long and is not considered as three consecutive + s. You are advised to use a serial port tool to send +++ at a time and | + | :- If you use the keyboard to type +++, it may take too long and is not considered as three consecutive + s. You are advised to use a serial port tool to send +++ at a time and not carry invisible characters such as Spaces or newlines.<br \> |
:- Please send the next AT command AT least one second later<br \> | :- Please send the next AT command AT least one second later<br \> | ||
− | *11. Exit the transparent transmission mode | + | *11. Exit the transparent transmission mode. |
AT+CIPMODE=0 | AT+CIPMODE=0 | ||
Response : | Response : | ||
OK | OK | ||
− | *12.Disconnect TCP | + | *12. Disconnect TCP. |
AT+CIPCLOSE | AT+CIPCLOSE | ||
Response : | Response : | ||
Line 93: | Line 93: | ||
=== '''TCP Server''' === | === '''TCP Server''' === | ||
− | *1. Configure WiFi mode | + | *1. Configure WiFi mode: |
AT+CWMODE=3 //softAP+station mode | AT+CWMODE=3 //softAP+station mode | ||
Response : | Response : | ||
OK | OK | ||
− | *2. Connect to router | + | *2. Connect to router: |
− | AT+CWJAP="SSID","password" //SSID and password of router | + | AT+CWJAP="SSID","password" //SSID and password of the router |
Response : | Response : | ||
OK | OK | ||
− | *3. Check IP address of ESP8266 device | + | *3. Check the IP address of the ESP8266 device: |
AT+CIFSR | AT+CIFSR | ||
Response : | Response : | ||
Line 109: | Line 109: | ||
+CIFSR:STAMAC,"18:fe:34:a5:8d:c6" | +CIFSR:STAMAC,"18:fe:34:a5:8d:c6" | ||
OK | OK | ||
− | *4. Enable multiple connection | + | *4. Enable multiple connection: |
AT+CIPMUX=1 | AT+CIPMUX=1 | ||
Response : | Response : | ||
OK | OK | ||
− | <span style="color:red;">Note: If "IPMODE must be 0" appears, it is necessary to disconnect ESP8266 and then enter the command. If not, press the button or power off to restart the module and then operate again.</span><br \> | + | <span style="color:red;">Note: If "IPMODE must be 0" appears, it is necessary to disconnect ESP8266 and then enter the command. If not, press the button or power off to restart the module and then operate it again.</span><br \> |
*5. Build TCP server | *5. Build TCP server | ||
AT+CIPSERVER=1 // default port = 333 | AT+CIPSERVER=1 // default port = 333 | ||
Response : | Response : | ||
OK | OK | ||
− | *6. The PC and THE ESP8266 are connected to the same router. Use the network debugging tool on the PC to establish a TCP client and connect to the TCP server of the ESP8266 | + | *6. The PC and THE ESP8266 are connected to the same router. Use the network debugging tool on the PC to establish a TCP client and connect to the TCP server of the ESP8266. |
− | *7. Send data | + | *7. Send data: |
//ID number of connection is defaulted to be 0. | //ID number of connection is defaulted to be 0. | ||
AT+CIPSEND=0,4 //send 4 bytes to connection NO.0 | AT+CIPSEND=0,4 //send 4 bytes to connection NO.0 | ||
Line 128: | Line 128: | ||
SEND OK | SEND OK | ||
− | *8. When the ESP8266 device receives data from the server, the following message is | + | *8. When the ESP8266 device receives data from the server, the following message is displayed: |
+IPD,0,n:xxxxxxxxxx //received n bytes, data=xxxxxxxxxxx | +IPD,0,n:xxxxxxxxxx //received n bytes, data=xxxxxxxxxxx | ||
− | *9.Disconnect TCP | + | *9. Disconnect TCP: |
AT+CIPCLOSE | AT+CIPCLOSE | ||
Response : | Response : | ||
Line 139: | Line 139: | ||
=== '''UDP''' === | === '''UDP''' === | ||
UDP transmission does not distinguish between server and client and is established by the AT+CIPSTART command. | UDP transmission does not distinguish between server and client and is established by the AT+CIPSTART command. | ||
− | *1. Configure WiFi mode | + | *1. Configure WiFi mode. |
AT+CWMODE=3 //softAP+station mode | AT+CWMODE=3 //softAP+station mode | ||
Response : | Response : | ||
OK | OK | ||
− | *2. Connect to router | + | *2. Connect to the router. |
AT+CWJAP="SSID","password" //SSID and password of router | AT+CWJAP="SSID","password" //SSID and password of router | ||
Response : | Response : | ||
Line 151: | Line 151: | ||
WIFI CONNECTED | WIFI CONNECTED | ||
WIFI GOT IP | WIFI GOT IP | ||
− | *3. Example Query the IP address of the ESP8266 | + | *3. Example Query the IP address of the ESP8266. |
AT+CIFSR | AT+CIFSR | ||
Response : | Response : | ||
Line 161: | Line 161: | ||
OK | OK | ||
*4. The PC and the ESP8266 are connected to the same router. Use the network debugging tool on the PC to set up a TCP server.<br \> | *4. The PC and the ESP8266 are connected to the same router. Use the network debugging tool on the PC to set up a TCP server.<br \> | ||
− | :For example, build a server | + | : For example, build a server on a PC with IP 192.168.3.116, and the port is set as 8080.<br \> |
− | *5. Enable multiple | + | *5. Enable multiple connections. |
AT+CIPMUX=1 | AT+CIPMUX=1 | ||
Response : | Response : | ||
OK | OK | ||
− | <span style="color:red;">Note: If "IPMODE must be 0" appears, it is necessary to disconnect ESP8266 and then enter the command. If not, press the button or power off to restart the module and then operate again.</span><br \> | + | <span style="color:red;">Note: If "IPMODE must be 0" appears, it is necessary to disconnect ESP8266 and then enter the command. If not, press the button or power off to restart the module and then operate it again.</span><br \> |
*6. Create a UDP transport. For example, to assign a joined number of 4, the instruction is as follows: | *6. Create a UDP transport. For example, to assign a joined number of 4, the instruction is as follows: | ||
AT+CIPSTART=4,"UDP","192.168.101.110",8080,1112,0 | AT+CIPSTART=4,"UDP","192.168.101.110",8080,1112,0 | ||
Line 175: | Line 175: | ||
Note:<br \> | Note:<br \> | ||
About the command:<br \> | About the command:<br \> | ||
− | :*"192.168.101.110", 8080 is the remote IP and port transmitted, that is the UDP port | + | :*"192.168.101.110", 8080 is the remote IP and port transmitted, that is the UDP port built in step 4;<br \> |
:*1112 is the local UDP port of ESP8266, it is configurable, or a random port<br \> | :*1112 is the local UDP port of ESP8266, it is configurable, or a random port<br \> | ||
:*0 Indicates that after the current UDP transmission is established, the UDP remote device will not be changed by other devices. Even if other devices send data to ESP8266 UDP port 1112 through UDP protocol, the remote end of THE UDP transmission no. 4 of ESP8266 will not be replaced. If the command "AT+CIPSEND=4, X" is used to send data, the current PC will still receive the data.<br \> | :*0 Indicates that after the current UDP transmission is established, the UDP remote device will not be changed by other devices. Even if other devices send data to ESP8266 UDP port 1112 through UDP protocol, the remote end of THE UDP transmission no. 4 of ESP8266 will not be replaced. If the command "AT+CIPSEND=4, X" is used to send data, the current PC will still receive the data.<br \> | ||
Line 198: | Line 198: | ||
AT+CIPSEND | AT+CIPSEND | ||
− | > //From now on, data received from UART will be transmitted to server automatically. | + | > //From now on, data received from UART will be transmitted to the server automatically. |
− | *11. Exit sending | + | *11. Exit sending data: |
If +++ is detected in a single packet of data during transparent transmission, the system stops transparent transmission.<br \> | If +++ is detected in a single packet of data during transparent transmission, the system stops transparent transmission.<br \> | ||
− | :- If you use the keyboard to type +++, it may take too long and is not considered as three consecutive + s. You are advised to use a serial port tool to send +++ at a time and | + | :- If you use the keyboard to type +++, it may take too long and is not considered as three consecutive + s. You are advised to use a serial port tool to send +++ at a time and not carry invisible characters such as Spaces or newlines.<br \> |
:- After that, send the next AT command AT least one second later.<br \> | :- After that, send the next AT command AT least one second later.<br \> | ||
*12. Exit the transparent transmission mode | *12. Exit the transparent transmission mode | ||
Line 214: | Line 214: | ||
OK | OK | ||
− | |||
==MicroPython Example== | ==MicroPython Example== | ||
Before Pico can run MicroPython programs, you need to download the MicroPython firmware, install the Thonny IDE, and configure the motherboard environment with the Rasberry Pi option. | Before Pico can run MicroPython programs, you need to download the MicroPython firmware, install the Thonny IDE, and configure the motherboard environment with the Rasberry Pi option. | ||
==='''TCP Client'''=== | ==='''TCP Client'''=== | ||
− | * | + | *Open the TCP&UDP test tool, create the server, and start the server. |
− | [[File:Pico-ESP8266- | + | [[File:Pico-ESP8266-TCP-1.png|border|700px]] |
*Open tcp_client.py in Thonny IDE and change the SSID and password to the actual WiFi account and password. Change the values of ServerIP and Port in the program to the IP and Port of the actual TCP server. | *Open tcp_client.py in Thonny IDE and change the SSID and password to the actual WiFi account and password. Change the values of ServerIP and Port in the program to the IP and Port of the actual TCP server. | ||
[[File:Pico-ESP8266-02.png|border|700px]] | [[File:Pico-ESP8266-02.png|border|700px]] | ||
*Click run program. After running, the program will connect to WiFi and send data to the server. The information sent by the server is displayed in the shell. | *Click run program. After running, the program will connect to WiFi and send data to the server. The information sent by the server is displayed in the shell. | ||
+ | <!-- | ||
[[File:Pico-ESP8266-03.png|border|700px]] | [[File:Pico-ESP8266-03.png|border|700px]] | ||
+ | --> | ||
+ | |||
==='''TCP Server'''=== | ==='''TCP Server'''=== | ||
− | *Open tcp_server.py program in Thonny IDE and change SSID and password values to the actual WiFi account password. | + | *Open the tcp_server.py program in Thonny IDE and change SSID and password values to the actual WiFi account password. |
*Click to run the program. After the program runs, it will connect to WiFi and start the server. The SHELL displays the STAIP address of ESP8266. | *Click to run the program. After the program runs, it will connect to WiFi and start the server. The SHELL displays the STAIP address of ESP8266. | ||
[[File:Pico-ESP8266-05.png|border|700px]] | [[File:Pico-ESP8266-05.png|border|700px]] | ||
− | *Open the TCP&UDP test tool, create a connection, set the type to TCP, target IP to the STAIP address displayed in the shell, port 8080. | + | *Open the TCP&UDP test tool, create a connection, set the type to TCP, and target IP to the STAIP address displayed in the shell, port 8080. |
[[File:Pico-ESP8266-06.png|border|700px]] | [[File:Pico-ESP8266-06.png|border|700px]] | ||
− | *Click the "connect" button to connect to the server. After normal connection, the icon changes from blue dot to green triangle. | + | *Click the "connect" button to connect to the server. After a normal connection, the icon changes from a blue dot to a green triangle. |
+ | <!-- | ||
[[File:Pico-ESP8266-07.png|border|700px]] | [[File:Pico-ESP8266-07.png|border|700px]] | ||
+ | --> | ||
+ | |||
=== '''UDP''' === | === '''UDP''' === | ||
− | *Open the TCP&UDP test tool, create a connection, select UDP as the type, the destination IP address is the STAIP address displayed in the shell after running the program, the port is 1112, and the local port is 8087. Select Create and Connect. | + | *Open the TCP&UDP test tool, create a connection, and select UDP as the type, the destination IP address is the STAIP address displayed in the shell after running the program, the port is 1112, and the local port is 8087. Select Create and Connect. |
− | [[File:Pico-ESP8266- | + | [[File: Pico-ESP8266-04.png|border|700px]] |
− | *Open tcp_server.py program in Thonny IDE and change SSID and password to the actual WiFi account and password. Set remote_IP to the actual IP address of the computer | + | *Open the tcp_server.py program in Thonny IDE and change the SSID and password to the actual WiFi account and password. Set remote_IP to the actual IP address of the computer |
[[File:Pico-ESP8266-08.png|border|700px]] | [[File:Pico-ESP8266-08.png|border|700px]] | ||
*After the program runs, it will connect to WiFi and send data to UDP on the computer side. Enter a string in the send area and send it. ESP8266 receives the message and sends it back for display in the receiving area. The shell port will also display the received information. | *After the program runs, it will connect to WiFi and send data to UDP on the computer side. Enter a string in the send area and send it. ESP8266 receives the message and sends it back for display in the receiving area. The shell port will also display the received information. | ||
+ | <!-- | ||
[[File:Pico-ESP8266-10.png|border|700px]] | [[File:Pico-ESP8266-10.png|border|700px]] | ||
+ | --> | ||
==C/C++ codes== | ==C/C++ codes== | ||
Line 246: | Line 253: | ||
chmod +x pico_setup.sh | chmod +x pico_setup.sh | ||
./pico_setup.sh | ./pico_setup.sh | ||
− | *Download the demo codes | + | *Download the demo codes: |
cd ~ | cd ~ | ||
− | wget https:// | + | wget https://files.waveshare.com/upload/4/41/Pico-ESP8266.zip |
unzip Pico-ESP8266.zip | unzip Pico-ESP8266.zip | ||
cp -r Pico-ESP8266/c/pico-esp8266 pico | cp -r Pico-ESP8266/c/pico-esp8266 pico | ||
*Before compiling the program, you need to modify the program and change the values of SSID and password to the actual WiFi account password. Change the values of ServerIP and Port in the program to the IP and Port of the actual TCP server. | *Before compiling the program, you need to modify the program and change the values of SSID and password to the actual WiFi account password. Change the values of ServerIP and Port in the program to the IP and Port of the actual TCP server. | ||
− | * | + | *Compiler: |
cd pico/pico-esp8266/build | cd pico/pico-esp8266/build | ||
cmake .. | cmake .. | ||
Line 267: | Line 274: | ||
*Hold the IO0 button of the PICo-ESP8266 and then press the RESET button to enter download mode. Select the corresponding serial port and set the baud rate to 115200. Click START and wait for the download to complete. | *Hold the IO0 button of the PICo-ESP8266 and then press the RESET button to enter download mode. Select the corresponding serial port and set the baud rate to 115200. Click START and wait for the download to complete. | ||
*To set the AT firmware for nonOS_AT_BIN_V1.7.4, follow the following figure. | *To set the AT firmware for nonOS_AT_BIN_V1.7.4, follow the following figure. | ||
− | [[File:Pico-ESP8266-13.png|border|800px]] | + | <!--[[File:Pico-ESP8266-13.png|border|800px]] --> |
+ | [[File:Pico-ESP8266-013.png|border|800px]] |
Latest revision as of 03:28, 18 December 2023
Quick start
Hardware connection
- Press and hold the BOOTSEL button of Pico, the pico will be recognized as a movable disk, copy the dev_cdc_ports.uf2 file from demo codes to the Pico, the Pico will automatically restart and work as the USB to serial adapter.
- Connect the Pico_EPS8266 board to Pico, then connect the Pico to PC by USB cable.
- Open an SSCOM software, choose the correct COM port, and set the baud rate to 115200.
- Test the module by AT command.
AT commands
- 1. AT:
AT Response: AT OK
- 2. AT+RST Restart device:
AT+RST Response: AT+RST OK
- 3. AT+GMR Check version:
AT+GMR Response: AT+GMR AT version:1.2.0.0(Jul 1 2016 20:04:45) SDK version:1.5.4.1(39cb9a32) Ai-Thinker Technology Co. Ltd. v1.5.4.1-a Nov 30 2017 15:54:29 OK
TCP Client
- 1. Configure WiFi mode.
AT+CWMODE=3 //softAP+station mode Response: : OK
- 2. Connect to the router.
AT+CWJAP="SSID","password" //SSID and password of the router Response: : AT+CWJAP="SSID","password" OK
- If it succeeds in connecting the WIFI, it will respond and get an IP address.
WIFI CONNECTED WIFI GOT IP
- 3. Check the IP address of ESP8266.
AT+CIFSR Response: : +CIFSR:APIP,"192.168.4.1" +CIFSR:APMAC,"1a:fe:34:a5:8d:c6" +CIFSR:STAIP,"192.168.3.133" +CIFSR:STAMAC,"18:fe:34:a5:8d:c6" OK
- 4. PC and ESP8266 are connected to the same router, use the network debugging tool on the PC end, and establish a TCP server.
- For example, build a server on a PC with IP address 192.168.3.116 and port 8080.
- 5. ESP8266 works as a TCP client and connects to the server.
AT+CIPSTART="TCP","192.168.3.116",8080 //protocol, server IP and port Response : CONNECT OK
- 6. ESP8266 device ends data of a specified length to the server.
AT+CIPSEND=4 //set date length which will be sent, such as 4 bytes >test //enter the data, no CR Response : Recv 4 bytes SEND OK
- 7. The data is printed if ESP8266 receives data from the server.
+IPD,n:xxxxxxxxxx //received n bytes, data=xxxxxxxxxxx
- 8. Enable the transparent transmission mode, data can be directly transmitted
AT+CIPMODE=1 Response : OK
- 9. If the transparent transmission mode is enabled, data can be directly transmitted
AT+CIPSEND > //From now on, data received from UART will be transmitted to the server automatically.
- 10. Exit sending data:
If +++ is detected in a single packet of data during transparent transmission, the system stops transparent transmission.
- - If you use the keyboard to type +++, it may take too long and is not considered as three consecutive + s. You are advised to use a serial port tool to send +++ at a time and not carry invisible characters such as Spaces or newlines.
- - Please send the next AT command AT least one second later
- 11. Exit the transparent transmission mode.
AT+CIPMODE=0 Response : OK
- 12. Disconnect TCP.
AT+CIPCLOSE Response : CLOSED
OK
TCP Server
- 1. Configure WiFi mode:
AT+CWMODE=3 //softAP+station mode Response : OK
- 2. Connect to router:
AT+CWJAP="SSID","password" //SSID and password of the router Response : OK
- 3. Check the IP address of the ESP8266 device:
AT+CIFSR Response : +CIFSR:APIP,"192.168.4.1" +CIFSR:APMAC,"1a:fe:34:a5:8d:c6" +CIFSR:STAIP,"192.168.3.133" +CIFSR:STAMAC,"18:fe:34:a5:8d:c6" OK
- 4. Enable multiple connection:
AT+CIPMUX=1 Response : OK
Note: If "IPMODE must be 0" appears, it is necessary to disconnect ESP8266 and then enter the command. If not, press the button or power off to restart the module and then operate it again.
- 5. Build TCP server
AT+CIPSERVER=1 // default port = 333 Response : OK
- 6. The PC and THE ESP8266 are connected to the same router. Use the network debugging tool on the PC to establish a TCP client and connect to the TCP server of the ESP8266.
- 7. Send data:
//ID number of connection is defaulted to be 0. AT+CIPSEND=0,4 //send 4 bytes to connection NO.0 >test //enter the data, no CR Response : Recv 4 bytes SEND OK
- 8. When the ESP8266 device receives data from the server, the following message is displayed:
+IPD,0,n:xxxxxxxxxx //received n bytes, data=xxxxxxxxxxx
- 9. Disconnect TCP:
AT+CIPCLOSE Response : CLOSED OK
UDP
UDP transmission does not distinguish between server and client and is established by the AT+CIPSTART command.
- 1. Configure WiFi mode.
AT+CWMODE=3 //softAP+station mode Response : OK
- 2. Connect to the router.
AT+CWJAP="SSID","password" //SSID and password of router Response : AT+CWJAP="SSID","password" OK
- If the connection is normal, it may prompt you to connect to WIFI and obtain the IP address.
WIFI CONNECTED WIFI GOT IP
- 3. Example Query the IP address of the ESP8266.
AT+CIFSR Response : +CIFSR:APIP,"192.168.4.1" +CIFSR:APMAC,"1a:fe:34:a5:8d:c6" +CIFSR:STAIP,"192.168.3.133" +CIFSR:STAMAC,"18:fe:34:a5:8d:c6" OK
- 4. The PC and the ESP8266 are connected to the same router. Use the network debugging tool on the PC to set up a TCP server.
- For example, build a server on a PC with IP 192.168.3.116, and the port is set as 8080.
- 5. Enable multiple connections.
AT+CIPMUX=1 Response : OK
Note: If "IPMODE must be 0" appears, it is necessary to disconnect ESP8266 and then enter the command. If not, press the button or power off to restart the module and then operate it again.
- 6. Create a UDP transport. For example, to assign a joined number of 4, the instruction is as follows:
AT+CIPSTART=4,"UDP","192.168.101.110",8080,1112,0 Response : 4, CONNECT OK
Note:
About the command:
- "192.168.101.110", 8080 is the remote IP and port transmitted, that is the UDP port built in step 4;
- 1112 is the local UDP port of ESP8266, it is configurable, or a random port
- 0 Indicates that after the current UDP transmission is established, the UDP remote device will not be changed by other devices. Even if other devices send data to ESP8266 UDP port 1112 through UDP protocol, the remote end of THE UDP transmission no. 4 of ESP8266 will not be replaced. If the command "AT+CIPSEND=4, X" is used to send data, the current PC will still receive the data.
- "192.168.101.110", 8080 is the remote IP and port transmitted, that is the UDP port built in step 4;
- 7. Send data
AT+CIPSEND=4,7 //Send 7 bytes to transmission NO.4 >UDPtest // enter the data, no CR Response : Recv 7 bytes SEND OK
Note:
- • When sending data, if the number of bytes entered exceeds the set length(n):
- - The system prompts BUSY, sends the first N bytes of data, and responds SEND OK when the sending is complete.
- - The data that exceeds the length is considered invalid and is not accepted.
- - The system prompts BUSY, sends the first N bytes of data, and responds SEND OK when the sending is complete.
- 8. Receive data. When the ESP8266 device receives data from the server, the following information is displayed:
+IPD,4,n:xxxxxxxxxx //received n bytes, data=xxxxxxxxxxx
- 9. If the transparent transmission mode is enabled, data can be directly transmitted.
AT+CIPMODE=1 Response : OK
- 10. The ESP8266 device transmits data to the server through transmission
AT+CIPSEND > //From now on, data received from UART will be transmitted to the server automatically.
- 11. Exit sending data:
If +++ is detected in a single packet of data during transparent transmission, the system stops transparent transmission.
- - If you use the keyboard to type +++, it may take too long and is not considered as three consecutive + s. You are advised to use a serial port tool to send +++ at a time and not carry invisible characters such as Spaces or newlines.
- - After that, send the next AT command AT least one second later.
- 12. Exit the transparent transmission mode
AT+CIPMODE=0 Response : OK
- 13. Disconnect UDP transmission
AT+CIPCLOSE=4 Response : 4, CLOSED OK
MicroPython Example
Before Pico can run MicroPython programs, you need to download the MicroPython firmware, install the Thonny IDE, and configure the motherboard environment with the Rasberry Pi option.
TCP Client
- Open the TCP&UDP test tool, create the server, and start the server.
- Open tcp_client.py in Thonny IDE and change the SSID and password to the actual WiFi account and password. Change the values of ServerIP and Port in the program to the IP and Port of the actual TCP server.
- Click run program. After running, the program will connect to WiFi and send data to the server. The information sent by the server is displayed in the shell.
TCP Server
- Open the tcp_server.py program in Thonny IDE and change SSID and password values to the actual WiFi account password.
- Click to run the program. After the program runs, it will connect to WiFi and start the server. The SHELL displays the STAIP address of ESP8266.
- Open the TCP&UDP test tool, create a connection, set the type to TCP, and target IP to the STAIP address displayed in the shell, port 8080.
- Click the "connect" button to connect to the server. After a normal connection, the icon changes from a blue dot to a green triangle.
UDP
- Open the TCP&UDP test tool, create a connection, and select UDP as the type, the destination IP address is the STAIP address displayed in the shell after running the program, the port is 1112, and the local port is 8087. Select Create and Connect.
- Open the tcp_server.py program in Thonny IDE and change the SSID and password to the actual WiFi account and password. Set remote_IP to the actual IP address of the computer
- After the program runs, it will connect to WiFi and send data to UDP on the computer side. Enter a string in the send area and send it. ESP8266 receives the message and sends it back for display in the receiving area. The shell port will also display the received information.
C/C++ codes
- C/C++ is compiled in Raspberry PI. This step can be skipped if the Pico compilation environment has been configured for Raspberry PI. If the Pico compilation environment has not been configured, perform the following operations.
wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh chmod +x pico_setup.sh ./pico_setup.sh
- Download the demo codes:
cd ~ wget https://files.waveshare.com/upload/4/41/Pico-ESP8266.zip unzip Pico-ESP8266.zip cp -r Pico-ESP8266/c/pico-esp8266 pico
- Before compiling the program, you need to modify the program and change the values of SSID and password to the actual WiFi account password. Change the values of ServerIP and Port in the program to the IP and Port of the actual TCP server.
- Compiler:
cd pico/pico-esp8266/build cmake .. make
Download AT Firmware
- Hold the Pico's BOOTSEL button and power on. The computer will recognize a USB flash drive and copy the dev_CDC_ports.uf2 file from the sample program to the flash drive to download the program. The Pico will become a USB-to-serial device.
- Run the flash_download_tool software.
- The factory default of the module is C1.5.4.1 AT firmware 32Mbit version. Select ai-thinker_esp8266_dout_32mbit_V1.5.4.1 -a_20171130.bin and set the address to 0x0. Set SPI SPEED to 40MHz, SPI MODE to DOUT, and FLASH SIZE to 32Mb-C1.
- Hold the IO0 button of the PICo-ESP8266 and then press the RESET button to enter download mode. Select the corresponding serial port and set the baud rate to 115200. Click START and wait for the download to complete.
- To set the AT firmware for nonOS_AT_BIN_V1.7.4, follow the following figure.