Raspberry Pi Pico MicroPython exercise of using
uasyncio:
"""
MicroPython uasyncio exercise on RP2040
"""
from sys import implementation
from os import uname
import uasyncio as asyncio
from machine import Pin
import utime
led = Pin(25, Pin.OUT)
print(implementation.name)
print(uname()[3])
print(uname()[4])
print()
print(asyncio.__name__)
print(asyncio.__version__)
#Toggle onboard LED every 500ms
async def asyncTask1():
while True:
led.toggle()
await asyncio.sleep_ms(500)
#print time every 1 second
async def asyncTask2():
while True:
print(utime.time())
await asyncio.sleep_ms(1000)
loop = asyncio.get_event_loop()
loop.create_task(asyncTask1())
loop.create_task(asyncTask2())
loop.run_forever()
print("- bye -")
The BOOTSEL button on my Raspberry Pi Pico broken! Here is how to reset
Pico and enter BOOTLOADER mode using Python (MicroPython/CircuitPython) code;
such that no need touch BOOTSEL button and un-plug/re-plug USB.
In case the Raspberry Pi Pico is flashed MicroPython:
adafruit nina-fw
is a slight variant of the
Arduino WiFiNINA core. ESP32 with nina-fw flashed, can be used as WiFi/BLE Co-Processor. This post
show how to connected ESP32 to Raspberry Pi Pico, flash ESP32 firmware using
Pico, and test WiFi/BLE with Pico/CircuitPython; on Raspberry Pi.
The ESP32 used here is a ESP32-S breadout board, flash with current latest
version NINA_W102-1.7.3.bin.
import board
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
from adafruit_airlift.esp32 import ESP32
esp32 = ESP32(
reset=board.GP16,
gpio0=board.GP9,
busy=board.GP14,
chip_select=board.GP13,
tx=board.GP0, #connect to ESP32 RX
rx=board.GP1, #connect to ESP32 TX
)
adapter = esp32.start_bluetooth()
ble = BLERadio(adapter)
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)
while True:
ble.start_advertising(advertisement)
print("waiting to connect")
while not ble.connected:
pass
print("connected: trying to read input")
while ble.connected:
# Returns b'' if nothing was read.
one_byte = uart.read(1)
if one_byte:
print(one_byte)
uart.write(one_byte)
This post show how ESP32 flashed with adafruit nina-fw, act as WiFi
Co-Processor work with Raspberry Pi Pico with CircuitPython.
adafruit nina-fw
is a slight variant of the
Arduino WiFiNINA core. The ESP32 used here is a ESP32-S breadout board, flash with current latest
version NINA_W102-1.7.3.bin.
Raspberry Pi Pico is flashed CircuitPython 6.2.0, with adafruit_esp32spi and
adafruit_requests libraries installed.