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

Building on last week’s mention of bitwise operators for unsigned math, did you know Python and MicroPython have excellent support for converting to and from C language types like int, long, float and more?  If you’ve struggled with converting raw bytes to and from numeric values then the struct and ustruct module might be your new best friend!

In Python the struct module is used to ‘pack’ and ‘unpack’ C language types to and from byte strings.  This is incredibly useful for talking to hardware devices like sensors that return bytes of data typically in C types like 16-bit signed integers, 32-bit floating point values, and more.  Check out this description of the struct module from the excellent Python module of the week site for how to use the module.

In MicroPython most of the struct module has been ported to the ustruct module.  It’s up to each port to add the module but for the most part all MicroPython ports support its use (including CircuitPython).  Compared to the Python struct module the MicroPython ustruct module only implements the basic pack and unpack functions.  However with just those two functions you’re all set to start talking to hardware that expects C language types.  Grab sensor readings, write registers, and more with ease using MicroPython’s ustruct module!

In other news CircuitPython saw a new 0.9.1 release this week.  Check out the release for more bug fixes and a nice flash memory savings on SAMD21 boards.

And if you’re looking for an IDE to develop MicroPython code inside check out this demo of OpenMV’s new support for MicroPython boards.