Belay Aims to Make PC-Based Python Hardware-Software Interfaces Quick and Easy via MicroPython

Talking to any MicroPython board via serial, Belay lets you integrate hardware interaction into your Python programs in a minimum of code.

Developer Brian Pugh has launched a tool designed to get MicroPython physical computing projects up and running as quickly as possible: Belay, a new library designed to tie external hardware into host-based software.

"Belay is a library that enables the rapid development of projects that interact with hardware via a MicroPython-compatible board," Pugh explains. "Belay is for people creating a software project that needs to interact with hardware. Examples include: Control a motor so a webcam is always pointing at a person; turn on an LED when you receive a notification; read a potentiometer to control system volume."

Belay is, essentially, designed to abstract the fact you're running code on an external microcontroller away from the developer. Host-based Python programs simply import the belay library and assign one or more serial ports as devices. Once assigned, these devices are used to communicate with the external microcontroller boards — which require nothing beyond MicroPython itself to be installed.

Belay aims to make it easy to tie hardware into the Python programs running on your desktop or laptop. (📹: Brian Pugh)

"Turning on an LED with Belay takes only six lines of code," Pugh explains. "Functions decorated with the task decorator are sent to the device and interpreted by the MicroPython interpreter. Calling the decorated function on-host sends a command to the device to execute the actual function."

Pugh has already developed a series of examples, which focus on the use of the Raspberry Pi Pico microcontroller board — but that should also be compatible with other MicroPython hardware. These include reading from on-board analog to digital converters (ADCs), threaded execution, exception handling, the use of external modules, interfacing with a display, and — naturally — blinking both standard and RGB LEDs.

More information on the project is available on the Belay GitHub repository, where the source code is published under the permissive Apache 2.0 license.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire:
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles