Skip to content

Latest commit

 

History

History
103 lines (91 loc) · 4 KB

README.md

File metadata and controls

103 lines (91 loc) · 4 KB

MicroPython Raspberry Pi Pico WiFi Driver

  • This project was forked and modified from: https://github.com/kfricke/micropython-esp8266uart
  • This driver for MicroPython intends to be useable on any MicroPython platform which implements a serial UART interface.
  • I tested this on Raspberry Pi Pico, together with an ESP-01 module (with AT command UART interface).
  • Since Pi-Pico has no radio built-in, it is good to get a cheap WiFi module like ESP-01 for it.
+-------------------+                +-------------------+
|                   |                |                   |
|   Raspberry Pi    |                |      ESP-01       |
|      Pico         |                |                   |
|                   |                |                   |
|               IO4 +----------------> RXD               |
|                   |                |                   |
|               IO5 <----------------+ TXD               |
|                   |                |                   |
|               GND +----------------+ GND               |
|                   |                |                   |
|                   |                |                   |
|      HOST         |                |    WIFI MODULE    |
|                   |                |                   |
|   (MicroPython)   |                |   (AT Firmware)   |
|                   |                |                   |
+-------------------+                +-------------------+

Usage

  • Upload these script files onto your Pico board, using Thonny or mpfs, etc.:

    • esp_at_uart.py
    • uart_timeout_any.py
    • test.py
  • On the repl shell, run with:

import test

Note

  • So far there is no "timeout" for uart's read/readline, thus we have to use "uart_timeout_any" as a temporally hotfix. See: https://github.com/raspberrypi/micropython/blob/pico/ports/rp2/machine_uart.c

  • It seems the Pi Pico is quite slow in processing incoming UART bytes, and we are unable to set the RX buffer at this moment. So we lost some bytes while receiving bulk message from ESP-01, a quick fix here is to set the ESP-01 to use 9600bps instead. You may connect the ESP-01 to your PC's console and use AT+UART_DEF=9600,8,1,0,0 to setup it first (default to 115200bps).

Example Output

>>> import test
UART(1, baudrate=9600, bits=8, parity=None, stop=1, tx=4, rx=5)
Testing Generic Methods
=======================
AT startup...
Success!
Another AT startup...
Success!
Version...
       1 - TX: b'AT+GMR\r\n'
      29 - RX: b'AT+GMR\r\n'
      83 - RX: b'AT version:2.1.0.0(883f7f2 - Jul 24 2020 11:50:07)\r\n'
     117 - RX: b'SDK version:v4.0.1-193-ge7ac221\r\n'
     163 - RX: b'compile time(0ad6331):Jul 28 2020 02:47:21\r\n'
     193 - RX: b'Bin version:2.1.0(WROOM-32)\r\n'
     198 - RX: b'\r\n'
     202 - RX: b'OK\r\n'
     205 - 'OK' received!
Success!

Testing WIFI Methods
====================
Testing get_mode/set_mode of value 'STATION'(1)...
Success!
Connecting WLAN...
Success!
Checking if connected WLAN SYNCSIGN_2.4G
Success!
Disconnecting from WLAN...
Success!
Checking if not connected WLAN...
Success!
Setting Station mode...
Success!
Scanning for WLANs...
[{'mac': b'"********"', 'rssi': -52, 'encryption_protocol': 3, 'ssid': b'"SYNCSIGN_2.4G"', 'channel': 6}, {'mac': b'"********"', 'rssi': -53, 'encryption_protocol': 3, 'ssid': b'"******"', 'channel': 6}, {'mac': b'"********"', 'rssi': -67, 'encryption_protocol': 4, 'ssid': b'"******"', 'channel': 11}]
Setting AP + Station mode...
Success!
Reading access point configuration
{'max_conn': 4, 'ssid_hidden': 0, 'ssid': b'"ESP_8283B1"', 'channel': 1, 'password': b'""', 'encryption_protocol': 0}
Listing all stations connected to the module in access point mode...
[]
Read DHCP client and server settings:
{'softAP': False, 'station': False}
Checking DHCP client and server settings...
    Enable Station DHCP...
    Enable SoftAP DHCP...
Setting autoconnect to access point in station mode...
Reading the station IP...
b'+CIPSTA:ip:"0.0.0.0"'
Reading the access point IP...
b'+CIPAP:ip:"192.168.4.1"'
>>>