IoT Made Simple – All in Python

The Pico W

The Pico W

Today we’re launching a toolkit for building web apps that connect to the Raspberry Pi Pico W, using the Anvil web app builder.

The Pico is a microcontroller – that is, a small computer designed for low-level programming. It costs just $6, and it’s pretty small, with just 2 megabytes of Flash and 264 kilobytes – yes, kilobytes – of RAM. But what it lacks in memory it makes up for with connectivity: it’s bristling with peripherals for connecting to other boards and devices. And, of course, you can program it all in Python. Now, Raspberry Pi have launched a new version with on-board WiFi: the Pico W.

The Pico W hardware is ideal for IoT projects (“Internet of Things” – that is, gadgets with an internet connection). But building the software that connects a microcontroller to a web user interface, database, and so on is very complicated – and, in its default configuration, often terribly insecure.

So today, we’re launching an easy, secure way to connect the Pico W to apps on the Anvil platform – all in Python. You get a drag-and-drop web UI builder, a built-in database, user authentication, email integration, HTTP APIs, and more – and it all talks to your Pico W.

What are we releasing?

We have released a firmware image for the Pico W that connects to the Anvil Uplink, so you can call functions on your Pico from your Anvil web app, and vice versa.

Copy your code onto the Pico

Copy your code onto the Pico

When you install this image, your Pico will show up as an extra USB drive, with sample Python code already present. Open it up, set your WiFi password and Uplink key, and reboot: Your Pico will now connect to your app, and you can call functions on your Pico from a web UI!

We are also releasing a series of tutorials and documentation that show you how to use the Pico W with Anvil’s free app builder and cloud hosting.

And, of course, we’re releasing the source code – because, like the Anvil framework itself, the Pico Uplink is open-source.

How can I get it?

Head to our Getting Started guide for the firmware download, installation instructions, and steps to get a working IoT app in minutes.

You can also check our homepage for the Pico Uplink, with more tutorials, advanced tips and tricks, and links to all the source code on GitHub:

How did we build it?

The anvil-pico firmware image is based on Micropython, a cut-down implementation of Python for microcontrollers. It can do a remarkable amount with very little memory – and although the Pico has some limitations compared to the classic Uplink, you can still do some pretty advanced things.

However, out of the box, the Micropython build for the Pico W did not support TLS certificate validation. This meant that projects built with it were entirely unsafe on the open internet. (If you are from a traditional development background, this might be shocking, but it’s disturbingly common in microcontroller development.) So we patched the Pico W’s Micropython build to enable TLS validation.

However, we also wanted a bit more protection: TLS certificates are only valid until a certain date, so that one stolen or mis-issued certificate can’t cause mischief forever. Now, the Pico does have a real-time clock (RTC) module, but it doesn’t remember the time while turned off! Fortunately, if you’re connecting to a cloud service, you by definition have internet access – so we also added an NTP (Network Time Protocol) implementation. The Pico can now find out the current date from the Internet, so it knows which certificates are valid.

Finally, we made a small fix to the Pico W SDK to make USB mass storage mode work. This means that the Pico could present as a USB drive, so you can save your source code right onto it.

Of course, all of this work has been contributed back to the upstream projects, so we hope that the additional security benefits will soon show up across the fast-growing Pico W ecosystem – even if they don’t use Anvil.

Tell me more.

If you’d like a bit more explanation of how the Uplink works, and the security considerations behind TLS validation, check out our How It Works page.

Otherwise, why not grab a Pico W and build your first IoT app now? It only takes a couple of minutes…