Learn Adding Potentiometers to your Raspberry Pi with RNBO

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

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*
  • Breadboard
  • 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 cutoff and 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.

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_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)

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

  1. 3.3v (red) from the RPi connects to the +V bus rail
  2. GND (black)  from the RPi connects to the ground bus rail
  3. Vdd (red) from the MCP3008 to the +V bus rail
  4. Vref (red) from the MCP3008 to the +V bus rail
  5. AGND (black) from the MCP3008 to the ground bus rail
  6. CLK (purple) from the MCP3008 to RPi SPI SCLK
  7. Dout (blue) from the MCP3008 to RPi SPI MISO
  8. Din (yellow) from the MCP3008 RPi SPI MOSI
  9. CS/SHDN (orange) from the MCP3008 to RPi SPI CE0
  10. DGND (black) from the MCP3008 to ground bus rail
  11. CH6 (white) from MCP3008 to wiper (centre pin) potA
  12. CH7 (pink) from MCP3008 to wiper (centre pin) potB
  13. GND (left pin) from PotA & PotB to ground bus rail
  14. +Vcc (right pin) from PotA & PotB to +V bus rail

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!

Going further

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