Transports and Synchronization
Understanding Storage: let, const, @state, @param
Using the Audio Plugin/Desktop Application Template
Programming a Custom UI with JUCE
RNBO Raspberry Pi OSCQuery Runner
Adding Potentiometers to your Raspberry Pi with RNBO
Unlike boards like the Arduino, the Raspberry Pi doesn't have an Analogue-to-Digital (ADC) converter to convert analogue signals to digital. In this article we'll learn how to use an ADC integrated circuit chip with the RPi to read in multiple Potentiometers at once and control a RNBO patcher.
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:
- 1 x MCP3008 IC (or equivalent Analog to Digital Converter)
- 1+ x (breadboard friendly) Potentiometers*
- Hook up wires
* linear taper :
B type potentiometers can be a little more versatile than audio taper (type
A) , but we'll learn a trick in RNBO for how to adapt to either.
We'll start by exporting the following patcher to the Raspberry Pi target:
To control the
resonance parameters of this patcher with our two potentiometers, we'll write a quick python script on the Raspberry Pi to use alongside the rnbo runner.
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.
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_2Pots.py by using
nano or any other text editor you prefer.
$ nano RNBOPi_2Pots.py
Paste in the following script, then save the file.
from gpiozero import MCP3008 import liblo as OSC import sys # send all messages to port 1234 on the local machine try: target = OSC.Address(1234) except OSC.AddressError as err: print(err) sys.exit() # start the transport via OSC OSC.send(target, "/rnbo/jack/transport/rolling", 1) # read from last two channels potA = MCP3008(channel=6) potB = MCP3008(channel=7) while True: print("Pot A", potA.value, "Pot B", potB.value) OSC.send(target, "/rnbo/inst/0/params/res/normalized", potA.value) OSC.send(target, "/rnbo/inst/0/params/res/normalized", potB)
sudo poweroff the RPi, and disconnect the power. Let's create our circuit:
3.3v(red) from the RPi connects to the
GND(black) from the RPi connects to the ground bus rail
Vdd(red) from the MCP3008 to the
Vref(red) from the MCP3008 to the
AGND(black) from the MCP3008 to the ground bus rail
CLK(purple) from the MCP3008 to RPi
Dout(blue) from the MCP3008 to RPi
Din(yellow) from the MCP3008 RPi
CS/SHDN(orange) from the MCP3008 to RPi
DGND(black) from the MCP3008 to ground bus rail
CH6(white) from MCP3008 to wiper (centre pin)
CH7(pink) from MCP3008 to wiper (centre pin)
GND(left pin) from
PotBto ground bus rail
+Vcc(right pin) from
The readings from the MCP3008 channels are already normalized - so we can use these directly to control the each parameter via their
normalized osc addresses. If you take a look in the patcher, you will see there is some logarithmic scaling of this via
@fromnormalized which makes it feel more natural for the
cutoff parameter. If you're using audio taper potentiometers (type
A) then you should remove this scaling (the pot's taper is doing it for you).
Switch the Pi back on and at the terminal run the script:
$ python RNBOPi_LDR.py
Now you should be able to wiggle some knobs and do some filter sweeps!
As you can see, the MCP3008 has a total of eight channels you can use to read any analogue signal into the Raspberry Pi. You're not limited to only using Potentiometers here, there's a whole world of analogue signals you can mix and match. There's also plenty of other ADC chips you can explore with greater resolution and with greater or fewer channels.
Materials in this article