# Make a String Instrument - Raspberry Pi

3,629

35

1

Have you ever wish to make your own music instrument? Here, you'll see that with few efforts, making a simple music instrument will be super easy.

Your instrument will be able to produce a sound, depending on the frequency of the rope. In order to receive the frequency of a rope we'll use a piezoelectric sensor.

All you have to do is to follow this tutorial step by step, so let's get started!

Note: This project has been held by an embedded system specialization from Polytech Paris-UPMC.

A video will be available soon :).

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Material Needed

(The image above is only an illustration)

This is the list of material you need to get to build this instrument:

Mechanical Part:

• 2 polystyrene plates;
• a guitar string;
• a small rewinder;

Electrical Part:

• Piezoelectric sensor;
• 2 Capacitors of 20µ;
• 2 Capacitors of 20n;
• 2 diodes;
• Resistors: 1 of 15k, 3 of 1.5k, 1 of 330k;
• AOP UA741;
• a voltage converter: ICL7660;
• 2 voltage regulators: 5V S7V8F5;
• Transistor JFET-N 2N5432
• a speaker;

Computing Part:

• Altium Designer Software;
• A computer with Windows and Linux installed;
• an ADC (analogue to digital converter) : MCP3008;
• a Rapsberry Pi 2 or 3;
• a USB to TTL cable;

We will use two batteries holder cases for 6x1.5V AA.

(If you don't have a machine to print PCB, an other breadboard will do the job, you'll have to skip step 4)

Now as we have all our furnitures, we can go to the next step.

## Step 2: Making of the Mechanical Part

Instrument's body:

We explain below, step by step, how to realize the mechanical part:

1. Cut a rectangle of 25x30cm and two of 5x10cm in the polystyrene plates;
2. Stick the side of the little rectangle's long edge to the side of the big one;
3. Attach the plastic bar to the side of the large. The bar must be placed on its side.
4. Wrap some of the rope in the rewinder with a strong glue
5. Place a wooden shaft in a corner opposite to the bar.
6. Place the reel on the wooden shaft.
7. Attach the other part of the rope to the end of the plastic bar that is diagonally in the retractor.

8. Stick the other two rectangles parallel and on either side of the rope, leaving a space (large enough for place the breadboard) between the rectangles.

9. Put the beadboard in the space between the rectangles

10. Attach the piezo to the rope and connect the piezo to the breadboard.

11. Connect two wires to the piezo through the breadboard.

You can see above, an image of what you'll may have.

## Step 3: Electronic Diagram

Start Altium on Windows, and create a new project. You will have to make the diagram above.

As mentioned previously, we use a piezoelectric sensor. The signal delivered by this sensor can be quite variable, so we chose to put an automatic gain control circuit that will allow us to obtain an amplified signal depending on the input voltage.

Automatic Gain Control

Resistors R1, R2 at 1.5k were chosen to obtain an amplification of 11.
In the AGC circuit, we have a peak detector which can detect the max voltage and adjust the gain. A capacity of 15nF and a resistor of 1.5k have been taken to have a time constant lower than the variation of the informative signal.

Low-Pass Filter

Knowing that the frequencies we have do not exceed 300 Hz, we placed a low-pass filter at the very end of our amplification circuit to keep the desired frequencies.

Power Supply

We power our circuit with 6 AA batteries. The amplifier needed -5V to work well so we decided to take a voltage converter which converts the voltage from 5V to -5V. The Raspberry also has its own power supply, indeed it is better to separate it from the rest of the circuit.

Analog to Digital Converter

We use a Raspberry Pi 2 model B, which does not have analog ports. We have to convert our analog data into digital data. That's why we use an ADC. Details of the ADC connections will be explained in step 5.

The explanation of the electrical diagram is now over, let's go the making of the PCB.

## Step 4: PCB (Printed Circuit Board)

(If you already have downloaded the zip file in the previous step, you can skip this part)

PCB Design

You can choose the size you prefer for the making of the PCB.

After placing the components on the PCB, trace the tracks that will join them. Try to put everything on the bottom layer.
Choose:

• track width : >= 0.5mm
• hole size : >= 0.85mm.

For the ground plane carry out the following steps:

1. Go to the Place tab,
2. Polygon Pour,
3. Cick on the contours of the PCB,
4. Press Esc
5. Press Enter.

Gerber files generation

To create the gerber files, follow tuto_gerber.pdf

## Step 5: Digital Acquisition

(From now on, use a PC with Linux installed)

With the PCB now printed, we will moove on to the digital acquisition using an MCP3008.

The data sent by this ADC will be read by the Raspberry.

First connect the TTL cable to the Raspberry as follows:

• Black to PIN06;
• White to PIN08;
• Green to PIN10.

Do not connect the red cable because the raspberry is already powered by the micro USB port.

Connect the ADC to Raspberry as follows:

• CLK to PIN23;
• DOUT to PIN21;
• DIN to PIN19;
• CS to PIN24.

The Raspberry and the ADC are respectively Master and Slave. That's why we have connected DOUT to PIN21 and DIN to PIN19, because those pins are used for the input and the output of the master and the slave.

Information sent by the MCP will be read using the SPI BUS. The Raspberry (Master) will generate the clock (CLK) and send requests to the MCP (the slave), which are here read requests, and the slave will then respond to the requests of the Raspbery.

The code is available here: http://shaunsbennett.com/piblog/?p=266

Once the library is installed and the code is put into the Raspberry, run the program to acquire the data and verify that the electronic circuit is working properly.

Note: To access the Raspberry from the terminal type the following command:

screen /dev/ttyUSB0 115200

## Step 6: Fast Fourier Transform - GNU + GSL

Now that we know we are abble to acquire data, we use the Fast Fourier Transform to convert our signal into a frequency spectrum and determine the frequency with the bigger amplitude. The FFT is an algorithm created to compute the discrete Fourier transform of a sequence, this is what we need in our case. Knowing where amplitude is the most important, we can find our frequency and play a note accordingly.

To use this FFT in C language, you have to install 2 packages from the GSL library: libgsl0ldbl and libgsl0-dev.

Use these commands on your raspberry:

• sudo apt-get install libgsl0ldbl
• sudo apt-get install libgsl0-dev

The default location for the gsl directory is /usr/local/include/gsl .

The compilation command for an example.c file with GNU and the gcc compiler is:

• gcc -Wall -I / usr / local / include -c example.c

In order to do the links and get our executable, we must use this command:

• gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm

## Step 7: Sound Generation

For the sound generation we will use the ALSA (Advanced Linux Sound Architecture) library.

To do this, we fill a buffer which has a size of 256 points, with a sinusoidal signal at the frequency played by our string multiplied by 100. Once the buffer is full, the sound is played through the jack port.

To enable the jack port do as follow:

1. sudo raspi-config
3. A9 Audio
4. Choose 3.5mm jack

To install the ALSA library:

• sudo apt-get install libasound2-dev

And to use it, add " -lasound " when you want to compile your file.

The whole program for step 6 and 7 can be downloaded below: CordiMousiki.c

## Step 8: How to Play

To play the instrument be sure that it is powered.

1. Place your left hand on the reel to keep the rope taut.
2. With the help of your right hand vary the length of the rope by pushing it against the side bar, and vibrate the rope with your index finger.

You should hear different notes coming out of the speaker depending on the cord tension.

This tutorial is now over, all you have to do now is to enjoy your instrument!

Thank You!

183 9.9K
28 3.9K
1 449 75K

## Discussions

Fun! I'd love to see a video of it playing :)