Core Electronics Forum

New video by Michael; The Factory | Coding MicroPython Modules That Work With Both Micro:bit & Raspberry Pi Pico

We have been really busy in #TheFactory this week, though I did manage to get this video together :slight_smile: In this episode get hands-on with MicroPython and get a PiicoDev module running on both the Raspberry Pi Pico and Micro:bit. MicroPython is a little different between these boards so we’ll need to come up with a flexible module that can determine which board it’s running on, and adapt to suit.

2 Likes

Please please please reach out to me about this! We’ve already done this with CircuitPython’s 300+ libraries. I’d love to help you get this sorted so you don’t duplicate effort on another ecosystem of Python drivers.

First and foremost, you’ll want to pass in an I2C object into the driver. That will allow you to isolate the conversion code to one place and provide a standard API to each driver. One big advantage of Python is that it doesn’t check types. Instead, it uses any object in the same way. So, you can pass in two different object types and the code using them doesn’t care. In CircuitPython drivers, that is the busio.I2C API that is provided by all ports, Blinka and could be provided on top of the micro:bit API as well.

We have an existing TMP117 driver here: Adafruit_CircuitPython_TMP117/adafruit_tmp117.py at main · adafruit/Adafruit_CircuitPython_TMP117 · GitHub I suspect it’ll be too large for the limited RAM of the micro:bit v1 though. It’ll need to be slimmed down.

2 Likes

Thanks, Scott! Shot you a message. To begin with, we have a couple of upstream reasons to use native MicroPython, though am looking forward to the catch-up.

1 Like

You can use CircuitPython libraries with MicroPython if you maintain a busio.I2C compatible adapter class. (Blinka has one for MicroPython already but not micro:bit.)

1 Like