loop speed compared to Arduino...

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
perigalacticon
Posts: 5
Joined: Mon Nov 18, 2019 12:03 am

loop speed compared to Arduino...

Post by perigalacticon » Wed Nov 20, 2019 10:25 pm

When I first saw Adafruit videos about Micropython several years ago I was disappointed because the loop speed was slow, only a few Hz for limited functionality. Now I am considering graduating to Micropython as a long term Arduino user. There are 2 projects I'd like to use it with: 1. Controlling holiday light displays with WS2812B leds and 2. Controlling simple interactive robots with as much functionality as possible (physical, audio and visual outputs, a variety of sensor inputs, and control/interaction via wireless protocol such as TCP, UDP, MQTT, Bluetooth etc.

Before diving into learning the entire system in detail I am trying to assess if a micropython based system would be capable of running and controlling the projects. I would implement these on a ESP32 or higher capable microcontroller, and RPIs.

My questions are:
1. Can you animate led pixel displays (strips and matrices) smoothly such as with FastLED on Arduino? What are practical limits?
2. What practical loop time is possible with many peripherals and computation?
3. What is the quality/speed of WIFI connectivity? Could I broadcast addressable LED data to multiple strands of 100+ leds? simultaneously via UDP?
4. To what extent can the same MicroPython code be run on a RPI as on a microcontroller?
5. In general what is library availability compared to Arduino?

Looking for good examples that show the practical capabilities of MicroPython for my projects.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: loop speed compared to Arduino...

Post by jimmo » Thu Nov 21, 2019 3:08 am

I have done smooth animations with ~100 LEDs (WS2812) on ESP8266 and ~1000 LEDs (APA102) on Pyboard v1.1.

But that said -- it depends greatly on what sort of effects you're doing. So it's not an easy question to answer.

The ESP32 is more powerful than both of them. Also there's some work in progress to make NeoPixel controlling more efficient using RMT. I got some benefits from using @native in a couple of places, and that is now available on ESP32 too.

I have less experience with WiFi on ESP32... but I'm not aware of any MicroPython-specific WiFi issues on ESP32, rather than the hardware in general.

There are two ways to run MicroPython on RPi -- either directly "bare metal", or to run the Unix port as a regular program in Linux (e.g. Raspbian). The first option isn't terribly well supported, the second doesn't have much in the way of direct hardware access (i.e. I'm not sure there's a Neopixel driver for example).
But potentially you can just run regular Python on the RPi and use the same code?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: loop speed compared to Arduino...

Post by jimmo » Thu Nov 21, 2019 3:10 am

perigalacticon wrote:
Wed Nov 20, 2019 10:25 pm
I was disappointed because the loop speed was slow, only a few Hz for limited functionality.
Btw, I'm not sure "a few Hz" was ever the case? Even on the very low end boards like the micro:bit.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: loop speed compared to Arduino...

Post by pythoncoder » Thu Nov 21, 2019 1:41 pm

For high performance applications I would recommend the Pyboard D. WiFi is offloaded to a separate chip so does not impact the CPU speed and is supremely reliable. MicroPython itself runs on "bare metal" and is fast. By contrast the ESP32 runs an underlying OS and is therefore slower. But it is the low cost option.

There are various ways of enhancing MicroPython speed discussed here.

In MicroPython applications the best way to handle concurrency is to use uasyncio. Then you don't have to write an event loop: you write individual tasks. The uasyncio library provides the illusion that they are running concurrently. A Pyboard D running uasyncio can switch tasks in ~100μs.

There is a learning curve but it's a far better way to write asynchronous code. If you want to learn more there is a tutorial here.
Peter Hinch
Index to my micropython libraries.

Post Reply