As an enthusiast, maker and engineer I have always been curious about microcontrollers and their power to do things. With the dawn of Arduino and micropython the things got a lot more insteresting, but at the same time may have got more "slow".
The things is, the overhead created by the Arduino and micropython code makes the microcontroller take more time to do stuff. At least this is what they say. But I want to figure that out by myself.
Then I had an idea: to get to know how long it takes for a Raspberry Pi Pico input to activate an output, since it goes from low to high up until the output goes from low to high.
But for what? well, for one to understand what is the maximum frequency an Arduino or micropython can possibly work at. Also to visualize that things take time in microcontroller code, even in MHz-driven code.
The simulation with Arduino code is here: https://wokwi.com/projects/397907576413737985
Both codes (Arduino and micropython) are on Github.
The setupI have connect a push button to pin 16 of the Pi Pico and a LED to pin 17. The push button does not need an external resistor because I am activating its internal pull down.
Using an oscilloscope with 2 channels I put channel 1 on the push button and channel 2 on the LED.
Then I configured the scope trigger to channel 1 (push button) and pressed the button.
Oscilloscope measurements below shows that Arduino can execute the button-to-LED in 2uS, while the micropython code takes 18uS.
It means that micropython is roughly 9x slower than the Arduino code, at least for this specific code. Theoretically then the Arduino code could run at 500KHz (1/2uS) and micropython could run at 55.5KHz (1/18uS).
In embedded systems (specially the critial ones) such times are sometimes not acceptable, systems may react way faster than this. My measurements prove that some languages are just not fast enough for given applications.
Future workThis is only the beginning, I plan to test more platforms (ESP32, PIC16F, STM32C0) and more softwares (ESP-IDF, CircuitPython). Stay tuned at https://fritzenlab.net/ .
Comments