---
slug: pico-ws
title: "Pico Ws"
date: "2022-11-11T05:30:53-04:00"

pics:
  reel:
    css: "image"
    tip: "Reel of Raspberry Pi Pico Ws."
    sources:
      - src: "/files/posts/pico-ws/pico-w-reel.jpg"
        width: 1024
        height: 768
  single:
    css: "image"
    tip: "Individual Pico W."
    sources:
      - src: "/files/posts/pico-ws/pico-w-single.jpg"
        width: 1024
        height: 768
  testing:
    css: "image"
    tip: "Advanced Pico W testing facility."
    sources:
      - src: "/files/posts/pico-ws/pico-w-testing.jpg"
        width: 1024
        height: 768
---
Last month I got a reel of [Raspberry Pi Pico Ws][pico-w].  Several
will eventually be paired with [BME280s][bme280] and used to measure
temperature, humidity, and barometric pressure throughout the house.

That project will have to wait a few weeks until I can unpack my
soldering iron.

In the mean time I've been fiddling [MicroPython][].  My thoughts so far
are below...

### Ordering and Delivery

Ordering was a bit of a headache.  The sites that I normally buy
from all had one or more of the following annoyances:

* Ridiculous markup
* Outrageous shipping fees
* Comically low quantity limit

The [Pico][] and [Pico W][pico-w] are not supply chain constrained like
the [Raspberry Pi 4B][pi-4b] and [Raspberry Pi Zero 2 W][pi-zero-2-w],
so I'm not sure why retailers are doing this.

I finally checked [DigiKey][], and they had plenty of [Pico Ws][pico-w]
in stock and none of the aforementioned shenanigans.  I ordered a reel
of 20 [Pico Ws][pico-w] for $6.00 apiece on October 3rd.  The package
arrived on October 5th.

As of this writing, [DigiKey][] still has [over 15,000 Pico Ws in
stock][stock].

### Hardware

Thoughts:

* 264 kB of RAM feels quite roomy on a microcontroller.
* Built-in [wifi][] is incredibly useful because you don't have to
  sacrifice a bunch of pins for external communication.
* PIO looks promising, although I haven't really used it yet.
* The onboard temperature sensor is not very accurate.

### Flashing [MicroPython][]

Flashing via [USB mass storage][] is great.  I didn't have to install an
[SDK][], fight with finicky wiring, or use an obscure microcontroller
flashing tool.

To get up and running with [MicroPython][], you can follow [these
instructions][flash-instructions].  The basic steps in [Linux][] are as
follows:

1. Press the BOOTSEL button on the [Pico W][pico-w].
2. Connect the [Pico W][pico-w] to your computer via [USB][].  It
appears as [USB mass storage][] device.
3. Mount the mass storage device.  Many distributions will automatically
mount the device for you as `/media/RPI-RP2`.
4. Copy a [UF2][] image to the mounted disk.
5. The [Pico W][pico-w] will flash itself and reboot.

If you've flashed [MicroPython][], then at this point you can connect to
a [REPL][] via [USB][] serial (e.g. `screen /dev/ttyACM0`).

The [Pico][] and [Pico W][pico-w] have [SWD][] pins, so you can still
flash via [SWD][] if you want to; instructions are available in the
[documentation][].

### MicroPython

[MicroPython][] is fantastic.  I was able to blink the onboard [LED][],
read the onboard temperature sensor, connect to [wifi][], and make web
requests less than an hour after unpacking the [Pico W][pico-w].

#### Example: Blink [LED][]

```python
MicroPython v1.19.1 on 2022-10-06; Raspberry Pi Pico W with RP2040
Type "help()" for more information.
>>> led = machine.Pin('LED', machine.Pin.OUT) # get LED
>>> led.toggle() # enable LED
>>> led.value() # check status
1
>>> led.toggle() # disable LED
>>> led.value() # check status
0
>>>
```
 

#### Example: Connect to [Wifi][] and send an [HTTP][] request

```python
MicroPython v1.19.1 on 2022-10-06; Raspberry Pi Pico W with RP2040
Type "help()" for more information.
>>> import network
>>> wifi = network.WLAN()
>>> wifi.active(True) # enable wifi
>>> wifi.connect('ssid', 'password') # replace 'ssid' and 'password' with your SSID and password
>>> wifi.status() # wait until wifi is connected (e.g., status = 3)
3
>>> import urequests
>>> data = urequests.get('https://pablotron.org/').content # send http request, get response body
>>> len(data) # print number of bytes received
48693
```
 

One useful tip: `machine.unique_id()` returns a unique ID for the
device.  This is useful because it allows you to flash the same image to
several [Pico Ws][pico-w] and then use `machine.unique_id()` to uniquely
identify them.  Example:

```python
>>> import binascii
>>> binascii.hexlify(machine.unique_id())
b'e6614c311b867937'
```
 

Miscellaneous [MicroPython][] notes:

* Many of the libraries in the [MicroPython standard library][] are
  reasonable subsets of their counterparts from the
  [Python standard library][].
* [MicroPython][] does not have [Pip][] or [PyPI][].  Instead you
  install packages via [mip][].  I used it [mip][] install and use the
  [MQTT][] library.
* You can build a Unix version of [MicroPython][] by following the
  [instructions in the `ports/unix` directory][build-unix] of the
  [MicroPython Git repository][].
* You can exhaust the RAM fairly easily by trying to fetch web content
  which is larger than the available RAM.  Not that I would make such a
  silly mistake...

### Pictures

{{< pe-figure "reel" >}}
{{< pe-figure "single" >}}
{{< pe-figure "testing" >}}

Description of the last picture:

* Foreground: [Pico W][pico-w] connected via [USB][] to a
  [Raspberry Pi 4B (4GB)][pi-4b], sitting in a delivery container.  The
  [Pi 4B][pi-4b] is used for miscellaneous `aarch64` testing like the
  [hash benchmarks from June][hash].
* Background: [Raspberry Pi 3B][pi-3b] in a proper case with a
  [BME280][] soldered to it to the [I²C][i2c] pins.  The [Pi 3B][pi-3b]
  is the bedroom [HTPC][] (running [Kodi][]) and temperature monitor.

[pico]: https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html
  "Raspberry Pi Pico"
[pico-w]: https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html
  "Raspberry Pi Pico W"
[bme280]: https://www.bosch-sensortec.com/products/environmental-sensors/humidity-sensors-bme280/
  "BME280 temperature, pressure, and humidity sensor."
[i2c]: https://en.wikipedia.org/wiki/I%C2%B2C
  "I²C microcontroller serial communication bus"
[micropython]: https://micropython.org/
  "Efficient Python 3 implementation for microcontrollers."
[led]: https://en.wikipedia.org/wiki/Light-emitting_diode
  "Light-emitting diode."
[usb]: https://en.wikipedia.org/wiki/USB
  "Universal Serial Bus"
[usb mass storage]: https://en.wikipedia.org/wiki/USB_mass_storage_device_class
  "USB mass storage device."
[uf2]: https://github.com/microsoft/uf2
  "UF2 flash file format"
[sdk]: https://en.wikipedia.org/wiki/Software_development_kit
  "Software Development Kit"
[pico-sdk]: https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#software-development
  "Raspberry Pi Pico and Pico W SDK."
[flash-instructions]: https://www.raspberrypi.com/documentation/microcontrollers/micropython.html
  "Instructions to flash MicroPython to a Pico W"
[linux]: https://en.wikipedia.org/wiki/Linux
  "Linux operating system"
[repl]: https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop
  "Read Evaluate Print Loop"
[http]: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  "HyperText Transfer Protocol"
[digikey]: https://digikey.com/
  "DigiKey"
[stock]: https://www.digikey.com/en/products/detail/raspberry-pi/SC0918/16608263
  "Raspberry Pi Pico W at DigiKey"
[pi-4b]: https://www.raspberrypi.com/products/raspberry-pi-4-model-b/
  "Raspberry Pi 4B"
[pi-3b]: https://www.raspberrypi.com/products/raspberry-pi-3-model-b/
  "Raspberry Pi 3B"
[pi-zero-2-w]: https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/
  "Raspberry Pi Zero 2 W"
[swd]: https://en.wikipedia.org/wiki/JTAG#Similar_interface_standards
  "Serial Wire Debug"
[documentation]: https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#documentation
  "Raspberry Pi Pico and Pico W Documentation"
[build-unix]: https://github.com/micropython/micropython/tree/master/ports/unix
  "ports/unix directory of MicroPython Git repository"
[micropython git repository]: https://github.com/micropython/micropython
  "MicroPython Git repository"
[wifi]: https://en.wikipedia.org/wiki/Wi-Fi
  "Wireless networking standard"
[micropython standard library]: https://docs.micropython.org/en/latest/library/index.html#python-standard-libraries-and-micro-libraries
  "MicroPython standard library"
[python]: https://python.org/
  "Python programming language"
[python standard library]: https://docs.python.org/3/
  "Python standard library"
[micropython-lib]: https://github.com/micropython/micropython-lib/
  "micropython-lib Git repository"
[mqtt]: https://en.wikipedia.org/wiki/MQTT
  "MQ Telemetry Transport"
[pip]: https://pypi.org/project/pip/
  "Python package installer"
[pypi]: https://pypi.org/
  "Python package index"
[mip]: https://docs.micropython.org/en/latest/reference/packages.html#package-management
  "micropython package management library"
[htpc]: https://en.wikipedia.org/wiki/Home_theater_PC
  "Home theater PC"
[kodi]: https://kodi.tv/
  "Kodi entertainment center"
[hash]: {{< relref "posts/2022-06-10-hash-speeds.md" >}}
  "OpenSSL Hash Benchmarks"