Vinophonics: Implementation
This page documents the steps for building the Vinophonics instrument.
To review, the Vinophonics controller is comprised of a Vinophonics sequencer, Raspberry Pi 4 with a HiFIBerry Hat, and an Arduino MEGA.
The Raspberry Pi 4 (RPI) is running the following functions:
Reading the slider positions and moving the sliders, via an Arduino mega, to correspond to the blockchain sensor readings
Reading the 3 position "blockchain" switch on the vinophonics panel, and writing the panel LED
Streaming audio-out from Vinophonics to the internet using an IceCast client
Streaming a low-refresh webcam of the vinophonics patch configuration
Connecting Vinophonics to the local wifi network
Here are the high level steps for building the solution.
Setup the Raspberry Pi
Prepare the Arduino Mega
Configure the 3 position blockchain switch
Construct the motorized slider controls
Install the full ethereum node
Configure audio streaming services
Construct the webcam services
Vinophonics Sequencer
On-board Server
Setup the Raspberry Pi
The Raspberry Pi 4 pinouts
The Raspberry Pi 4 pinouts look like this:
GPIO Pinout for Raspberry Pi 4 and Earlier.
(Image credit: Les Pounder)
Deciding which pins will be used on the RPi will be determined by the different uses we require.
For example, reading a 3-position switch will require 2 digital pins, ground, and a 3.3v voltage. Any general purpose input output pins will do for this.
Lighting the blockchain LED will require another general purpose LED and ground pin.
Two PWM pins will be necessary to supplement the lack of sufficient PWM pins on the Arduino Mega.
The HiFiBerry DAC/ADC+ board will suck up the most numbers of required pins.
According to their website:
https://www.hifiberry.com/docs/hardware/gpio-usage-of-hifiberry-boards/
GPIO2-3 (pins 3 and 5) are used by our products for configuration. If you are experienced with I2C, you might add other slave devices. If you a a novice, we don’t recommend this at all. GPIOs 18-21 (pins 12, 35, 38 and 40) are used for the sound interface. You can’t use them for any other purpose.
Accordingly, this is the initial pinout of the RPi:
Description | GPIO | Pin | Pin | GPIO | Description |
---|---|---|---|---|---|
3v3 Power |
| 1 | 2 |
| 5v Power |
HiBerry | 2 | 3 | 4 |
| 5v Power |
HiBerry | 3 | 5 | 6 |
| Ground |
| 4 | 7 | 8 | 14 |
|
GND LED |
| 9 | 10 | 15 |
|
LED | 17 | 11 | 12 | 18 | HiBerry |
| 27 | 13 | 14 |
| GND SW |
Switch1(R) | 22 | 15 | 16 | 23 | Switch2 (L) |
3.3v SW |
| 17 | 18 | 24 |
|
| 10 | 19 | 20 |
| Ground |
| 9 | 21 | 22 | 25 |
|
| 11 | 23 | 24 | 8 |
|
Ground |
| 25 | 26 | 7 |
|
| 0 | 27 | 28 | 1 |
|
| 5 | 29 | 30 |
| Ground |
| 6 | 31 | 32 | 12 | HB8_1,2EN |
HB8_3,4EN | 13 | 33 | 34 |
| Ground |
HiBerry | 19 | 35 | 36 | 16 |
|
| 26 | 37 | 38 | 20 | HiBerry |
Ground |
| 39 | 40 | 21 | HiBerry |
Wiring conventions
Color | Usage |
---|---|
Red | 5v Power |
Orange | 9-12v Power |
Yellow | 3v Power |
White | Ground |
Green | HB*_EN(1,2), SW1 |
Blue | HB*_EN(3,4),SW2 |
Purple | H-Bridge Logic1A, 3A |
Black | H-Bridge Logic 2A, 4A |
Grey | H-Bridge Motor 1Y,3Y |
Brown | H-Bridge Motor 2Y,4Y |
Pink | 2' (Analog slider read) |
Beige | T, LED |
Prepare the Arduino Mega
The Arduino Mega hosts the majority of the wiring connections to the Vinophonics controller.
..because the Arduino Mega has tons and tons of pins.
Configure the 3 position blockchain switch
There is a 3 position switch and red LED on the Vinophonics panel:
This switch and LED are wired to a block connector on the main Vinophonics board here:
This button allows us to select three user states:
Local: Only the local user (performer) can modify the slider positions. No blockchain data are applied to the slider positions.
Local + Remote: In this middle position, the performer can move the sliders and make changes, but the blockchain will override these settings when an update is made. This is the DEFAULT operation mode.
Remote: In the right position, the blockchain data state always overrides the performer. The performer can move the sliders, but they snap back into the blockchain determined positions. This can be a useful setting for performances as a way to jump back to the last blockchain state.
The red LED simply blinks once for 200ms ever time there is a blockchain update. An intermittently blinking LED indicates that blockchain updates are not being received, indicating a loss of blockchain connectivity.,
Pin 2 (grey) - switch 1 Remote (RPI pin 15)
Pin 4+6 (white) - center 3.3v (RPI pin17)
Pin 8 (black) - switch 2 Local (RPI pin 16)
Pin 10 (black) - LED cathode (RPI pin 14)
Pin 9 (brown) - LED anode (RPI pin 11)
The three-position switch and LED seem like a good place to start programming the raspberry pi controller, as these are relatively simple instructions.
The three-position switch
The switch is a double pole double throw switch. It is basically two switches, side-by-side. The center contacts are the common pin. They connect to one of the other two outside pins depending on which way the handle is positioned. Only the center position is off, with no connection made to any pins.
Here is a good example of how to wire and test the switch, except we are using pins 22 and 23 (instead of 23 and 24).
To detect when the switch is on in one of the 2 possible (on) positions we need to use 2 GPIO inputs,
wiring it like this, using external pull-down resistors and an external GPIO protection resistor.
For this example, we can test with this sample code, but first we need to install the Raspberry Pi GPIO Python module. This is a library that allows us to access the GPIO port directly from Python.
Install the python packages for GPIO
pi@vinophonics:~ $ sudo apt-get install python-rpi.gpio python3-rpi.gpio
Add the user to the gpio group in /etc/group
gpio:x:997:pi,mbarrow
Create the test application switch_test.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(22, GPIO.IN)
GPIO.setup(23, GPIO.IN)
while True:
if GPIO.input(22) == 1:
print ("Switch is set to LOCAL")
elif GPIO.input(23) == 1:
print ("Switch is set to REMOTE")
else:
print ("Switch is set to BLOCKCHAIN")
time.sleep(1)
The code will read the switch position once every second and print the result on the screen.
Run this code as root,
sudo python switch_test.py
Otherwise, you might get told you are NOT running on a Raspberry Pi:
mbarrow@vinophonics:~ $ python switch_test.py
Traceback (most recent call last):
File "switch_test.py", line 7, in <module>
GPIO.setup(22, GPIO.IN)
RuntimeError: Not running on a RPi!
The LED
Turning an LED off and on from the Raspberry Pi is simple.
The anode (long leg) of the LED is connected to GPIO pin 17, and the cathode (short log) to ground through a 220Ω resistor.
On the vinophonics connector, as seen above, pin 10 on the block is the cathode, and 9 the anode.
Here is the test code: