New kid in town : Pico W

On 30 june 2022 I got a mailing from RaspberryPI  store that the Raspberry PI foundation has released a new PI Pico which also includes a wireless module for Wifi and Bluetooth.

So I ordered 4 of them to get myself familiar with this new microcontroller and to do some experiments with it. And 1 day later postman dropped of a package. 

pico-012

More info can be found on these links : 

To sum it all up :

The Raspberry PI Pico W is a low-cost, high-performance microcontroller board with flexible digital interfaces. Key features like the PI Pico include:

  • RP2040 microcontroller chip designed by Raspberry Pi in the United Kingdom
  • Dual-core ARM Cortex M0+ processor, flexible clock running up to 133 MHz
  • 264kB of SRAM, and 2MB of on-board Flash memory
  • Castellated module allows soldering direct to carrier boards
  • USB 1.1 Host and Device support
  • Low-power sleep and dormant modes
  • Drag & drop programming using mass storage over USB
  • 26 multi-function GPIO pins
  • 2×SPI, 2×I2C, 2×UART, 3×12-bit ADC, 16×controllable PWM channels
  • Accurate clock and timer on-chip
  • Temperature sensor
  • Accelerated floating point libraries on-chip
  • 8×Programmable IO (PIO) state machines for custom peripheral support
  • CYW43439 wireless chip (supports IEEE 802.11 b/g/n wireless LAN, and Bluetooth 5.2; of these, only wireless LAN is supported at launch.)

 pico-013

Pin diagram (c) Raspberry PI foundation.

 

TODO : add more findings.

Let try it 

With now the WIFI on board, I had to try something. In the document :  Connecting to the internet with Raspberry Pi Pico W small webserver example program in MicroPython, and although I normally program in C / C++, I thought  it would be great to try some other language. So this was me trying MicroPython for the first time, and have say it works nice.

Maybe I'm going to work more with it. 

import network
import socket
import time
import uasyncio as asyncio
from machine import Pin

led = Pin(15, Pin.OUT)
onboard = Pin("LED", Pin.OUT, value=0)
 
ssid = 'YOURSSID'
password = 'YOURPASSWD'
 
html = """<!DOCTYPE html>
<html>
    <head> <title>Pico W</title> </head>
    <body> <h1>Pico W</h1>
        <p>Current state : %s</p>
        <p><a href="/light/on">Set LED on<a/><p>
        <p><a href="/light/off">Set LED off<a/><p>
    </body>
</html>
"""
wlan = network.WLAN(network.STA_IF)

def connect_to_network():
    wlan.active(True)
    wlan.config(pm = 0xa11140) # Disable power-save mode
    wlan.connect(ssid, password)

    max_wait = 10
    while max_wait > 0:
        if wlan.status() < 0 or wlan.status() >= 3:
            break
        max_wait -= 1
        print('waiting for connection...')
        time.sleep(1)

    if wlan.status() != 3:
        raise RuntimeError('network connection failed')
    else:
        print('connected')
        status = wlan.ifconfig()
        print('ip = ' + status[0])
 
    
async def serve_client(reader, writer):
    print("Client connected")
    request_line = await reader.readline()
    print("Request:", request_line)
    # We are not interested in HTTP request headers, skip them
    while await reader.readline() != b"\r\n":
        pass

    request = str(request_line)
    led_on = request.find('/light/on')
    led_off = request.find('/light/off')
    print( 'led on = ' + str(led_on))
    print( 'led off = ' + str(led_off))

    stateis = ""
    if led_on == 6:
        print("led on")
        led.value(1)
        stateis = "LED is ON"

    if led_off == 6:
        print("led off")
        led.value(0)
        stateis = "LED is OFF"

    response = html % stateis
    writer.write('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
    writer.write(response)

    await writer.drain()
    await writer.wait_closed()
    print("Client disconnected")

async def main():
    print('Connecting to Network...')
    connect_to_network()

    print('Setting up webserver...')
    asyncio.create_task(asyncio.start_server(serve_client, "0.0.0.0", 80))
    while True:
        onboard.on()
        print("heartbeat")
        await asyncio.sleep(0.25)
        onboard.off()
        await asyncio.sleep(5)

try:
    asyncio.run(main())
finally:
    asyncio.new_event_loop()

 Source code converted to html with http://hilite.me/  and I have put the source code in this zipfile.