micro:bit as norns MIDI friend

micro:bit as a small little MIDI companion. An unengineered proof of concept for those who like to have a bit of fun on the command line and dream up bespoke computations. The below is kind of advanced and complicated. Not live-coding, but interactive coding anyway in Python on micro:bit. The teletype is an inspiration.

Overview of the process is that we will livecode Python which emits MIDI data from micro:bit over USB serial connection and pipe incoming MIDI to norns parameters.

The below is typed from sketchy notes, I’ll correct if errors are discovered.

Step 1. Prepare micro:bit

Get Micropython on micro:bit. Now you can connect to Python REPL over serial connection for on-device programming.

Step 2. Prepare norns

Install ttymidi, a little utility which reads and writes MIDI from serial to ALSA.

Step 3. Connect norns and micro:bit

Plug micro:bit to norns with a USB cable. ssh into norns over wifi. Open serial connection from norns to micro:bit with screen /dev/ttyACM0. Press enter to get the familiar Python >>> prompt.

Step 4. Define MIDI function on micro:bit

I did something simple for the sake of demonstration, a function which sends MIDI cc to channel 1.

from microbit import *

def cc(control, value):
    msg = bytes([0xb0, control, value])
    uart.write(msg)

Step 5. Write a MIDI controller and run it

I dreamed this one, it sends kind of random MIDI cc data on channel 1 for CCs 1 and 2, the latter in kind of ratchets, reacting to movements of the micro:bit.

while True:
    cc(1, running_time() % 127)
    if running_time() % 2 == 0:
        display.show(Image.DIAMOND)
    else:
        display.show(Image.DIAMOND_SMALL)
    for r in range(4):
        cc(2, (running_time() - 15) % 127)
        sleep(running_time() % 100)
    sleep((running_time() % 7) * compass.heading())

It will start to output garbage like this

��      �'�c�y���^�!�A�j�]�{�<�V�����.�D�7�C�W� �z�N��*�l�_�o��X�|�o�<�r�x�v�h

That’s MIDI.

Step 6. Connect micro:bit output to norns MIDI input

Only one process can read the USB serial connection at a time, so exit the screen terminal connection with C-a k. Collect the streaming MIDI data from micro:bit to norns with

$ ttymidi -s /dev/ttyACM0 &
$ aconnect 129:0 128:0

Make sure the virtual is one the devices in SYSTEM > DEVICES > MIDI on norns.

Step 7. Map MIDI cc data to norns parameters

Via the usual norns param mapping.

Step now-you-do-it. Modify MIDI emitting code on micro:bit

Stop the MIDI data collection from micro:bit with kill $(pidof ttymidi). Reconnect to micro:bit with screen /dev/ttyACM0. Interrupt the running Python code with C-c.

Jump to step 5 above and build another MIDI cc source, or 4 if you want more functionality like clock or MIDI notes. micro:bit has interactions like rotation, two buttons, screen etc and can connect to electronics or an audio source.

Step fin or if something crashes. Restart norns

Sleep and restart your norns. Nothing has been changed on the system, so it’ll heal from any confusions or dyings. Mine just crashed because Mouse was getting MIDI input too much too fast.

9 Likes