Daily tips and tricks from the experts at Adafruit!
View this email in your browser

Last week’s newsletter mentioned the release of MicroPython 1.9 firmware.  This is the latest version of MicroPython and includes optimizations that reduce memory usage, among many other fixes.  One big thing to note about the 1.9 version of MicroPython is that it is not compatible with older .mpy bytecode modules generated from previous MicroPython versions.  For example if you used the mpy-cross tool in the past to build a .mpy file of a Python module you won’t be able to use that same .mpy file with the latest MicroPython 1.9 firmware.  However not all is lost, you can rebuild your .mpy file with MicroPython 1.9’s mpy-cross tool!

To build a .mpy file check out this page from the SAMD21 MicroPython guide for some pointers on how to build and run the tool.  You’ll need the MicroPython 1.9 sourcecode on your machine, and you’ll need to be running a POSIX compatible operating system like Linux or Mac OSX.  On Windows you might be able to use the new Linux subsystem in the latest versions or Windows 10, or use Vagrant to create a small Linux virtual machine.  Once you have MicroPython source navigate to the mpy-cross folder inside it and run the make command.  This will build the mpy-cross tool and you’re ready to start converting MicroPython .py files to .mpy files.  To run mpy-cross just point it at a .py file and it will by default build a .mpy version.  For example mpy-cross foo.py would generate a foo.mpy from the contents of foo.py.  That’s all there is to rebuilding .mpy files for the latest version of MicroPython!