[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!
Interpreted IOIO
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?
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..
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.
…and as long as you put off learning to code, you’ll always be dependent upon others for their libraries.
That’s why I implement my own printf() on every platform I develop for.
I see my point is wasted on you. Never mind, someone gets it.
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.
I’d say this is the best summary of Belay. I’ll update the README to reflect this.
well.. yes! if you don’t need to use a PC, you don’t need PC compatibility. that said, ‘just’ a library seems to be underselling it IME, it’s quite cool!
why stop there? could run Windows 10.
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.
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).
it’s been around for longer, for sure – I’ve used it in my own testing in 2014. I’d rather pick this one ngl!
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?
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.
(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…
why on this board no power?
look at OrangeCrab board, normal lipo power on board
WHY not here?