Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

How to Use Asyncio in MicroPython (Raspberry Pi Pico) | Digi-Key Electronics

Автор: DigiKey

Загружено: 2021-08-09

Просмотров: 53655

Описание:

At this time, MicroPython does not support full multithreading (with the threading library). However, we can use uasyncio (the MicroPython version of the larger Python asyncio library) to create a cooperative multitasking program.

Uasyncio contains a subset of functions found in the asyncio library. Some parts (like queues) are left out (at the time this video was released).

In the video, we go over how cooperative multitasking compares to preemptive multitasking and how you can use uasyncio to create several tasks in a single program. Specifically, we will use the Raspberry Pi Pico to demonstrate how to read button presses in one loop and blink an LED in another loop. We will also show how to use a queue to pass messages between the tasks.

The full code for this tutorial can be found here: https://www.digikey.com/en/maker/proj...

Asyncio is based around the idea of “coroutines,” which behave like normal functions but have the ability to yield the processor. While a coroutine is paused, the processor is free to perform other activities. This is extremely useful to optimize processor utilization while waiting for things like a response from a sensor, website, etc. or while performing periodic tasks.

We define coroutines using the “async” keyword, which lets the scheduler (a task that runs in the background in charge of telling other tasks to run) know that the containing function is capable of yielding. We can wait for a coroutine to finish executing with the “await” keyword. Finally, we can run a coroutine as a task (e.g. return immediately while letting the coroutine execute) using the create_task() function.

Note that coroutines must be run as part of an “event loop” that includes a scheduler. The scheduler, unlike in preemptive multitasking, only runs when a coroutine explicitly yields (e.g. using the “await” keyword). As a result, the programmer must take great care to ensure that none of the coroutines hog the processor and starve the other coroutines/tasks. This method of “cooperative multitasking” makes it more difficult for (seemingly random) bugs to occur (such as race conditions when working with a preemptive scheduler).

If you would like to learn more about preemptive multitasking, you can check out my Introduction to RTOS series here:    • Introduction to RTOS Part 1 - What is a Re...  

Product Links:
Raspberry Pi Pico - https://www.digikey.com/en/products/d...
Related Videos:
Raspberry Pi Pico and RP2040 playlist -    • Intro to Raspberry Pi Pico and RP2040 - C/...  
Related Project Links:
Getting Started with MicroPython (Raspberry Pi Pico) Part 1: Blink - https://www.digikey.com/en/maker/proj...
Related Articles:
What is a Real-Time Operating System (RTOS) - https://www.digikey.com/en/maker/proj...
Introduction to MicroPython - https://www.digikey.com/en/maker/blog...

Maker.io - https://www.digikey.com/en/maker
Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog
Connect with Digi-Key on Facebook   / digikey.electronics  
And follow us on Twitter   / digikey  

How to Use Asyncio in MicroPython (Raspberry Pi Pico) | Digi-Key Electronics

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

Intro to Raspberry Pi Pico and RP2040 - C/C++ Part 1: VS Code and Blink | Digi-Key Electronics

Intro to Raspberry Pi Pico and RP2040 - C/C++ Part 1: VS Code and Blink | Digi-Key Electronics

Intro to Raspberry Pi Pico and RP2040 - MicroPython Part 1: Blink | Digi-Key Electronics

Intro to Raspberry Pi Pico and RP2040 - MicroPython Part 1: Blink | Digi-Key Electronics

You don't need a Raspberry Pi! (Getting started with Microcontrollers)

You don't need a Raspberry Pi! (Getting started with Microcontrollers)

Intro to Raspberry Pi Pico and RP2040

Intro to Raspberry Pi Pico and RP2040

Что такое

Что такое "Reverse Engineering". Показываю как ломают софт.

Use BOTH Cores  |  Dual Core Programming on the Raspberry Pi Pico

Use BOTH Cores | Dual Core Programming on the Raspberry Pi Pico

Как использовать таймеры на RPi PICO

Как использовать таймеры на RPi PICO

Pico Course for Beginners | Coding, Electronics and Microcontrollers

Pico Course for Beginners | Coding, Electronics and Microcontrollers

Intro to Raspberry Pi Pico and RP2040 - C/C++ Part 3: How to Use PIO | Digi-Key Electronics

Intro to Raspberry Pi Pico and RP2040 - C/C++ Part 3: How to Use PIO | Digi-Key Electronics

Делаю Российские платы из Русских материалов

Делаю Российские платы из Русских материалов

Getting Started with Multicore Programming on the Raspberry Pi Pico

Getting Started with Multicore Programming on the Raspberry Pi Pico

Raspberry Pi Pico W: Wireless Weather Station

Raspberry Pi Pico W: Wireless Weather Station

Multi Thread Coding on the Raspberry Pi Pico in MicroPython - Threads, Locks and problems!

Multi Thread Coding on the Raspberry Pi Pico in MicroPython - Threads, Locks and problems!

Raspberry Pi Pico (RP2040) SPI Example with MicroPython and C/C++ | Digi-Key Electronics

Raspberry Pi Pico (RP2040) SPI Example with MicroPython and C/C++ | Digi-Key Electronics

Как работают ДАТЧИКИ ХОЛЛА? Самое понятное объяснение!

Как работают ДАТЧИКИ ХОЛЛА? Самое понятное объяснение!

Power for the Raspberry Pi Pico - Guide to using VBUS, VSYS and 3V3 for external power circuits

Power for the Raspberry Pi Pico - Guide to using VBUS, VSYS and 3V3 for external power circuits

Raspberry Pi Pico W УРОК 66: Создание собственных библиотек в Micropython

Raspberry Pi Pico W УРОК 66: Создание собственных библиотек в Micropython

Hosting And Accessing Websites from the Raspberry Pi Pico W

Hosting And Accessing Websites from the Raspberry Pi Pico W

Финальная версия невидимого ПК

Финальная версия невидимого ПК

The Raspberry Pi Pico WAS Overrated! But that changed!

The Raspberry Pi Pico WAS Overrated! But that changed!

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]