Your MicroPython Board Can Be Your Tinkering Peripheral

screenshot from the video linked, showing example code that lights up an LED, and in a small window, also shows the LED lit up on a small Pi Pico board connected over USB

[Brian Pugh] has shared a cool new project that simultaneously runs on desktop Python and MicroPython – the Belay library. This library lets you control a MicroPython device seamlessly from your Python code – interacting with real-world things like analog/digital trinkets, servos, Neopixels and displays, without having to create your own firmware or APIs.

You need a serial-connected MicroPython board – even an ESP8266 should do. Then, you can intersperse your Python code with MicroPython-written functions, and call them whenever you need your connected device to do something – keeping the entire logic of your project within a single device. [Brian] provides quite a few examples, even for more complex things like displays. No doubt, there are limitations, but this looks to be a powerful tool in a hacker’s arsenal.

Readers might be reminded of an Arduino library called Firmata – an old-time way to do such connectivity. We’ve also previously covered a Pi Pico firmware that does a similar thing, and even features a breakout board for all your experimentation needs!

18 thoughts on “Your MicroPython Board Can Be Your Tinkering Peripheral

  1. Hmmm… Do I rely need Belay? Let’s say I have an ESP32 running MicroPython that already exposes MicroPython’s REPL interactive interface via a UART connected to GPIO pins. I can use a UART/USB bridge cable to control the ESP32 interactively via a PC just as if I was doing so locally via an instance of something like the Arduino IDE’s Serial Monitor tool. Instead on the PC I would use a terminal emulator program. I can automate programming the ESP32 from the PC by playing macros on the terminal emulator. No need to install Python on the PC. If I use an ESP32-S2 with its native USB OTG port, I can eliminate the UART/USB bridge cable too. Just typing as I think… Anyone see a problem here?

    1. This is a bit different.

      It allows you to mix seamlessly code executed on your computer with code executed on the micropython device. Y

      ou can for example have a jupyter notebook that executes partly on your board, gathering sensor data for example, and process those data in your notebook, displaying curves and graphics there.

      I need to give it a run, for the moment i use different kernels (normal python and micropython) and the integration is not that tight..

    2. This is different. The point here is to seamlessly integrate python code running on your computer with micropython code running on your board.

      I´ll give a try with a Jupyter notebook gathering data from sensors attached to a couple of micropython boards, with triggers and execution control in the main python code, and displaying neat graphs in the notebooks.

      Very flexible test automation possibilities, indeed.

  2. Belay is just a library to automatically use the REPL interface from Python code running on PC.
    A typical task could be capturing some data and then using the more powerful CPU to process it and to display the results.

    If you have no need to run Python code on PC, you don’t need it.

  3. Interesting to see that Firmata is an “old-time way” to do such things. Has it been superseded nowadays ? I remember using it tne years ago but didn’t follow along and I’ll be happy to tinker with new tools like this one.

    1. Several of my clients use Firmata with PJRC’s Teensy boards in factory ATE that changes daily or weekly.

      I use firmata for ad-hoc monitoring of about 100 various types of environmental sensors in my house and those scattered around a 40 acre area (approx 16 hectares).

  4. Hmm, I don’t quite understand. mpremote – and pyboard.py – are officially supported tools from the MicroPython core team that allow you to execute code on a MicroPython device.

    You can execute files, eval snippets or execute code in-line from CPython. Perhaps we just need to make it easier to use or add better documentation?

    1. Internally this uses pyboard.py from micropython. This is basically an extension to that functionality to execute and sync code in an easier, more efficient, more pythonic way.

      1. (BTW, wasn’t trying to undermine your good work Brian!)

        Perhaps we should look to integrate something like what you’ve built in Belay upstream? Maybe extend mpremote/pyboard to do the job…

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.