Close

Log #24: MIDI out (again)

A project log for lalelu_drums

Gesture controlled percussion based on markerless human-pose estimation with an AI network from a live video.

lars-friedrichLars Friedrich 03/14/2026 at 16:370 Comments

The approach to create low latency MIDI output that was used so far in lalelu_drums is shown in an early log entry. Unfortunately, this approach recently stopped working. In the following, the problem is explained and an alternative solution is presented. 

the problem

The original approach relied on a PCI card based COM port that was used with a specific linux driver provided by the manufacturer. With the help of this driver it was possible to configure the specific baud rate that is required for MIDI (31250).

At some time between November 2025 and January 2026 an automatic update brought the system based on ubuntu server 22.04 into a state where the driver was not working any more. It was not possible to make it work again (see below for a list of attempts).

The PCI card based COM port can be used with the linux kernel builtin driver, but in this mode it only supports standard baud rates that do not include the one required for MIDI. 

the solution

As an alternative approach to create MIDI output, a USB-UART bridge is used. It can be used without special drivers and supports the MIDI baud rate.

Figure 1: As an adaption to the MIDI definition, two 220 Ohm resistors are used and the jumper on the device is configured to output 5V signals. 

With this configuration a total system latency in the range of 20-22ms could be confirmed, similar to the results obtained with the earlier approach.

the rest of the story

The following attempts were taken to make the driver for the PCI card based COM port work

In conclusion, the automatic updates that are active by default for a ubuntu server system create a risk for the system not to work that is not acceptable if it is planned to be used for live performances. Since the lalelu_drums backend is much less exposed to the internet than a typical server, it seems to be the better choice to disable automatic updates, for example using the following command.

dpkg-reconfigure --priority=low unattended-upgrades

Before switching to the USB-UART bridge, a different workaround was implemented to restore the MIDI out function. The PCI card based COM port was used with the kernel driver at a high baud rate (115200) and a raspberry pi pico was used as a baud rate translator. It was nice to see how easy this application could be implemented using micropython:

from machine import UART, Pin

uartIn = UART(1, baudrate=115200, tx=Pin(4), rx=Pin(5),
              bits=8, parity=None, stop=1)

uartOut = UART(0, baudrate=31250, tx=Pin(0), rx=Pin(1),
               bits=8, parity=None, stop=1)

while True:
    c = uartIn.read(1)
    if c:
        uartOut.write(c)

An oscilloscope measurement shows that the translation introduces as little as 109µs of additional latency, which is negligible for this usecase.

Figure 2: Input and output of the baud rate translator. Vertical cursors show latency.

However, the solution with the USB-UART bridge is significantly less complex and also cheaper.

A final hurdle before reaching the original latency was that the default configuration of the fresh ubuntu server system (22.04) lead to a significant reduction of the CPU frequency compared to its upper limit of 3.9GHz. While the lalel_drums application was running, cpupower frequency-info reported values between 1.39GHz and 3.86GHz To achieve optimal results the following command restores full CPU speed:

cpupower frequency-set -g performance

In this case the reported actual frequency was in the range of 3.86GHz to 3.89GHz.

Discussions