MicroPython: Future or Fad?
MicroPython is a way to compile and run Python directly on small and inexpensive microcontrollers, such as ARM Cortex M4 devices (~$7) - which are traditionally programmed in C and compiled into a hex file.
The programming is so simple that it is intriguing. But can you really do anything useful with it? It certainly doesn’t appear to be well suited for real-time applications, since there are garbage collection and other background tasks going on. Nevertheless, there is a LOT of activity in this area, so it can't just be dismissed.
Here are some examples of the simplicity of Python. Toggling an I/O pin:
from machine import Pin
# create an I/O pin in output mode
p = Pin('X1', Pin.OUT)
# toggle the pin
p.high()
p.low()
Which, admittedly isn't that exciting, but look how simple it is to talk to I2C devices:
from machine import Pin, I2C
# creat an I2C bus
i2c = I2C(scl=Pin('X1'), sda=Pin('X2'))
# scan for list of attached devices
dev_list = i2c.scan()
# write to and read from a device
i2c.writeto(0x42, b'4')
data = i2c.readfrom(0x42, 4)
# memory transactions
i2c.writeto_mem(0x42, 0x12, b'')
data = i2c.readfrom_mem(0x42, 0x12, 2)
And here is all it takes to read/write to an SD card:
import os
# list root directory
print(os.listdir('/'))
# print current directory
print(os.getcwd())
# open and read a file from the SD card
with open('/sd/readme.txt') as f:
print(f.read())
Here's an interesting Digikey article on installing MicroPython onto an STM32F4 Discovery board: https://www.digikey.com/en/articles/techzone/2017/sep/develop-real-time-mcu-based-applications-micropython
You can also buy boards like the Adafruit STM32F405 pyboard with MicroPython already installed.
Anyone have experience with this trend? I can't tell if it is the future, or just a fad?
Can you get low-power performance? Bootup reliability, which is the mainstay of embedded systems? What are your thoughts? Let me know in the comments.