Hi
I am looking at possibly introducing some CircuitPython into our curriculum for 3rd and 4th year undergraduates. We already teach C and to be honest, so far I have not really seen a strong argument for moving to Python on an embedded platform (i don't find python particularly easier than C to write on an embedded system).
However, with an open mind, I have been programming a few boards in standard Arduino C and also CircuitPython and the performance hit for I/O manipulation is HUGE.
I mean HUGE, as in beyond what seems reasonable.
On an M4 Feather Express 32-bit board with 120MHz clock, I could toggle an output pin at 37.8kHz.. On a standard 8-bit Uno I could toggle a bit in C at 148kHz. On the feather Express M4 in C, I could toggle the bit at just over 1.098MHz (1098kHz).
All code was a loop doing nothing except toggle the output bit on each pass through it.
Literally, I set up the pins as outputs, then entered a loop around changing the output pin value for 1 to 0 to 1 to 0 to 1 to 0 to.........
no other code being run
Summary
M4 with circuit python 37.8kHz
Arduino Uno in C 148kHz
M4 in C 1098kHz
I expect the reason is a lot of abstraction going on so that circuit python can map all I/O on all variations of boards as it runs code, but this is clearly either a bad idea or implemented badly, given the above numbers. Surely it is pretty easy to just create clean, fast, I/O libraries for each chip (or board)?
So, is this something that is being addressed?
Are fast I/O libraries available?
Is there a way to avoid what is clearly a very inefficient set of abstraction layers? (without having to read datasheets, write directly to addresses etc - might as well use C if one is going that way and easily get a 1000 fold speed increase)
I/O speed is very poor - question for circuit python team
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- imolas3
- Posts: 7
- Joined: Wed Jun 16, 2021 5:27 pm
Please be positive and constructive with your questions and comments.