The Pico In MicroPython: Asyncio Client
Written by Mike James & Harry Fairhead   
Wednesday, 30 July 2025
Article Index
The Pico In MicroPython: Asyncio Client
Using uasyncio
Async Networking

Implementing a web client is a basic task for anyone wanting to make use of the internet and the best way to do it is to use asyncio. This is an extract from our book all about the Raspberry Pi Pico 2/2W in MicroPython.

Programming the Raspberry Pi Pico/W In MicroPython Third Edition

By Harry Fairhead & Mike James

PicoPython3E360

Buy from Amazon.

Contents

  • Preface
  • Chapter 1 The Raspberry Pi Pico – Before We Begin
  • Chapter 2 Getting Started
  • Chapter 3 Getting Started With The GPIO
  • Chapter 4 Simple Output
  • Chapter 5 Some Electronics
  • Chapter 6 Simple Input
             Extract: Simple Input ****
  • Chapter 7 Advanced Input – Events and Interrupts
  • Chapter 8 Pulse Width Modulation
             Extract: PWM  ****
  • Chapter 9 Controlling Motors And Servos
             Extract: DC Motors ****
  • Chapter 10 Getting Started With The SPI Bus
  • Chapter 11 A-To-D and The SPI Bus  ****
  • Chapter 12 Using The I2C Bus
  • Chapter 13 Using The PIO   
  • Chapter 14 The DHT22 Sensor Implementing A Custom Protocol
             Extract: A PIO Driver For The DHT22   ****
  • Chapter 15 The 1‑Wire Bus And The DS1820
  • Chapter 16 The Serial Port
  • Chapter 17 Using The Pico W - WiFi
             Extract: HTTP Client  ****     
  • Chapter 18 Sockets
             Extract: Sockets ****
  • Chapter 19 Asyncio And Servers
             Extract: Asyncio Client  ***NEW!!!
  • Chapter 20 Advanced Hardware
  • Chapter 21 Direct To The Hardware
             Extract: Direct To The Hardware ****

Also of interest:

Raspberry Pico File System

**** articles from the second edition not yet updated.

<ASIN:B0BR8LWYMZ>

<ASIN:B0BL1HS3QD>

MicroPython has a basic implementation of the Python asyncio module. The asyncio module is very useful in providing asynchronous programming in Python and you might think that it would be exceptionally useful in low-level hardware applications as an alternative to polling or event driven approaches. In fact it isn’t quite as useful as you might expect as there are few existing asynchronous subsystems. In full Python we have a complete filing system and network connections and this means that asynchronous programming can improve efficiency by putting the processor to work while waiting for I/O operations to complete. As the Pico doesn’t have either an operating system or a filing system, there isn’t much opportunity to make use of idle processor time. However, now that the Pico has a network connection via WiFi the asyncio module is suddenly much more useful.

In this chapter we first look at the basic idea of asynchronous programming as implemented by uasyncio, the MicroPython version of asyncio, and then at how to use it to implement a server asynchronously. If you want to know more about asynchronous programming in general and asyncio in particular see Programmer’s Python: Async, ISBN:9781871962765.

In chapter but not in this extract

  • Coroutines and Tasks
  • Await
  • Awaiting Sleep
  • Tasks
  • Sequential and Concurrent
  • Canceling Tasks
  • Dealing With Exceptions
  • Shared Variables and Locks
 


Last Updated ( Wednesday, 30 July 2025 )