Learn Light up some LEDs with RNBO on the Raspberry Pi

Getting Started

Welcome to RNBO

Quickstart

RNBO Basics

Key Differences

Why We Made RNBO

Coding Resources

Fundamentals

Audio IO

Messages to rnbo~

Using Parameters

MIDI in RNBO

Messages and Ports

Polyphony and Voice Control

Audio Files in RNBO

Using Buffers

Using the FFT

Export Targets

Export Targets Overview

VST/AudioUnit
Max External Target
Raspberry Pi Target
The Web Export Target
The C++ Source Code Target

Code Export

Working with JavaScript
Working with C++

Special Topics

Sample Accurate Patching
Scala and Custom Tuning

RNBO and Max for Live

RNBO Raspberry Pi OSCQuery Runner

Metadata

Export Description

Raspberry Pi GPIO

Working with Photoresistors (LDRs) on the Raspberry Pi with RNBO

Adding Potentiometers to your Raspberry Pi with RNBO

Light up some LEDs with RNBO on the Raspberry Pi

Using a Gyroscope/Accelerometer module over i2C with RNBO on the RPi

Updating the RNBO Package

Light up some LEDs with RNBO on the Raspberry Pi

You've just made your own desktop synthesizer with RNBO and the Raspberry Pi, you're ready to switch the lights off and jam out - but there's no visual feedback... If there's a bleep in a dark studio but there's no pulses of twinkling light - did it even happen?

NOTE: This article is intended as a guide to help you extend the use of the RPi. Though the information here is accurate and correct, when working with electronics there is always the risk of damaging your device or components. While the voltage in the RPi is low enough not to pose any threat to your physical safety, the device itself could be damaged. Cycling 74 cannot be held responsible for any damages resulting from attempts to complete the following project. We also cannot provide technical support for RPi beyond basic setup of the image and loading RNBO patchers. Please proceed with caution and at your own risk.
Before attempting this tutorial, make sure you’re already familiar with the basics of exporting your RNBO patchers to the RPi and that your audio interface is working correctly with it.

Things you'll need:

  • 8x through-hole LEDs
  • 8x 220 ohm resistors*
  • 1x 12mm push button momentary switch (optional)
  • Breadboard
  • Hook up wires

*this is a general approximate resistor value for these current limiting resistors (without them, you can burn out your pins on your RPi or blow the LEDs) if you really want to be precise, this tool from digikey is really handy.

We'll start by exporting the following patcher to the Raspberry Pi target:​

We're going to use the LEDs to light up the current step of the sequence. If you've also got a momentary push button handy we'll add that as a little transport control start/stop button.

We'll write a quick python script on the Raspberry Pi to use alongside the rnbo runner that's running the sequencer patcher.

ssh in, or connect up a keyboard and monitor. We'll use a library that should already be on your RPi image called gpiozero and another for communicating with the runner via OSC. You can use any OSC library you like, this example will use pyliblo3. We've used this library before - so if you've done this in a previous tutorial - you can skip this step.

To install pyliblo3 run the following two commands from the terminal on your RPi.

$ sudo apt install liblo-dev
$ pip install pyliblo3

Now create a file called RNBOPi_LEDSeq.py by using nano or any other text editor you prefer.

$ nano RNBOPi_LEDSeq.py

Paste in the following script, then save the file.

from gpiozero import LEDBoard, Button
import liblo as OSC
import sys

# set up OSC client - send all messages to port 1234 on the local machine (rnbo runner)
try:
    target = OSC.Address(1234)
except OSC.AddressError as err:
    print(err)
    sys.exit()# set up OSC server - listening on port 4321

try:
    server = OSC.Server(4321)
except OSC.ServerError as err:
    print(err)

def update_transport_state(path, args):
    i = args[0]
    global transport_running
    transport_running = bool(i)

def handle_step(path, args):
    i = args[0]
    global transport_running
    print("current step:", i)
    led_vals = [0] * len(leds)
    led_vals[i] = 1
    leds.value = tuple(led_vals)

def fallback(path, args, types, src):
    print("got unknown message '%s' from '%s'" % (path, src.url))
    print("don't panic - probably just the runner echoing back your changes :)")
    for a, t in zip(args, types):
        print("argument of type '%s': %s" % (t, a))

# register callback methods for server routes
server.add_method("/rnbo/jack/transport/rolling", None, update_transport_state)
server.add_method("/rnbo/inst/0/messages/out/step", 'i', handle_step)

# Finally add fallback method for unhandled OSC addrs
server.add_method(None, None, fallback)

# Set up RNBO OSC listener
OSC.send(target, "/rnbo/listeners/add", f"127.0.0.1:4321")

# create a button object
button = Button(21)

# create an LEDBoard object representing our array of LEDs
leds = LEDBoard(17, 27, 22, 5, 6, 13, 19, 26)

def toggle_transport():
    global transport_running
    transport_running = not transport_running
    OSC.send(target, "/rnbo/jack/transport/rolling", transport_running)⁠

button.when_pressed = toggle_transport

transport_running = True
OSC.send(target, "/rnbo/jack/transport/rolling", transport_running)

try:
    while True:
        server.recv(100)        
        
except KeyboardInterrupt:
    print("exiting cleanly...")
                
        

Now sudo poweroff the RPi, and disconnect the power. Let's create our circuit:

Running the script

Power up the Pi again and run the script

$ python RNBOPi_LEDSeq.py

The script will start the transport rolling, you should be able to turn the transport on and off using the button. Try using rnbo.remote to toggle the transport also - you should see the state reflected in the attrui whether you use the button or the toggle.

If you want to control the step values, you can open the Raspberry Pi Debug Interface to control the parameters.

Going further

Now you see that you can control the rnbo runner on the Raspberry Pi via GPIO pins, the rnbo.remote object and the Raspberry Pi Debug interface all at the same time - you should have some ideas about what to try next. Perhaps you want to try Adding Potentiometers to your Raspberry Pi with RNBO?

Materials in this article