On Github todayispotato / micropython-talk
Who had heard of it before?
And who used it before?
For something serious?
For something that is running right now?
MicroPython is a lean and fast implementation of the Python 3 programming language that is optimised to run on a microcontroller.
Mainly due to RAM usage. Examples:
>>> print('Hello world!')
Hello world!
>>> with open('pygrunn.txt') as f:
>>>     f.write('Hello PyGrunn!')
>>> try:
>>>     1/0
>>> except ZeroDivisionError as e:
>>>     print("Oh, you!")
Oh, you!
                    
                
>>> import functools
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: no module named 'functools'
>>> import this
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: no module named 'this'
                    
                Specific ports provides specific hooks, REPL and custom modules
async def ping_pygrunn():
    return await ping_server('pygrunn.org')
                    
                128kb ROM / 8kb RAM (after subtracting other software)
Around 280kb flash
Written in Python
$ micropython -m upip install micropython-functools
$ ./micropython 
MicroPython v1.7-116-g8dd704b on 2016-04-19; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import functools
>>> dir(functools)
['__name__', 'reduce', 'partial', 'update_wrapper', '__file__', 'wraps']
                    
                    https://github.com/micropython/micropython-lib
                A tagged pointer is a pointer (concretely a memory address) with additional data associated with it
@micropython.asm_thumb
def led_on():
    movwt(r0, stm.GPIOA)
    movw(r1, 1 << 13)
    strh(r1, [r0, stm.GPIO_BSRRL])
                        
                    
@micropython.native
def foo(self, arg):
    # code
                        
                        Roughly twice as fast, but larger binary
http://hinch.me.uk/html/reference/speed_python.html
@micropython.viper
def foo(self, arg: int) -> int:
    # code
                        
                        Now actually called Zerynth and kind of confusing
Accerelometer, RTC, 4 LEDs, 2 switches, 30 GPIO
16kb RAM, 256kb flash, Cortex M0 @ 16 MHz
Supplied to 1 million school children
256kb RAM, 2Mb flash, 25 GPIO, Cortex M4 @ 80 MHz
“Small and light to fit in any cavity” ★Dual processor + WiFi radio SoC. ★MCU: Texas Instrument CC3200, Cortex-M4 @ 80MHz ★Network processor handles the WiFi connectivity and the IP stack. ★Main processor entirely free to run the user application. External libraries -Blynk: SMTP, MQTT, URLLIB, ONEWIRE, Accelerometer, Event loop MicroPython PyMakr - Pycom IDELoRa + Python
It depends on your board
But it's amazing for prototyping!
Or for embedding in games and apps
We have Python on microcontrollers.
And it works!
Questions?