Piolin Electronic Musical Instrument
by coventrymakerspace in Circuits > Electronics
5869 Views, 66 Favorites, 0 Comments
Piolin Electronic Musical Instrument
Hi! John from Coventry Makerspace here! When we were kindly given five Raspberry Pis by Instructables, I came up with the idea of using one to create a unique musical instrument. Using some salvaged wood and electrical components, plus a few other bits and bobs, I created the Piolin! The code was created with Scratch with the intention of using a Raspberry Pi. But once I got into the nitty gritty of the project, I realised that actually a Raspberry Pi was not a good fit for what I wanted to do as it has no analogue outputs, and that actually a PicoBoard or Arduino was a far simpler solution. But by then, the Piolin name had stuck. So really it should be called the not-quite-a-Pi-olin! ;-)
Tools and Materials
To complete this project you will need:
- any old scrap wood, plus scrap wood or metal for the 'bow'
- saw and plane to work the wood, plus clamps and wood glue
- stiff wire (we used salvaged mains wire)
- resistors
- Raspberry Pi or PC to program with
- PicoBoard or Arduino
Woodwork
We used scraps and offcuts of wood to fashion a 'bridge' for our piolin, and an offcut of decking for the neck/fret of our piolin (of course, unlike a real violin, the size, shape, and type of wood you use won't affect the sound of the finished instrument, so just go mad and create whatever shape you like from whatever wood you have!)
Glue and screw the pieces together, clamping the pieces together while the glue dries. We made sure to add support to strengthen the joins. Please ignore the wires in the last picture - we forgot to take a photo until after ;-)
Wiring
Drill holes along the length of the fret - you will need four sets of two holes for the strings on the 'bridge' and fourteen sets of two holes along the fret. You will need to measure to space the holes out, the frets will need to be close together enough that a resistor reaches between each fret and its neighbour, but not so close that you can't fit the resistor between them easily.
Feed separate lengths of wire through each set of two holes. Each length needs to be long enough to feed through from the front of the fret and then fold back on itself to form a loop, as shown. We experimented to find the correct length of wire then cut them all the same size before feeding them through the drilled holes.
Add Resistors
We soldered our resistors into place - but don't worry if you can't solder. You could also wrap the resistors tightly between the fret wires then fold them over and secure them with a thumb tack. To calculate the correct resistors to use, we need to take a look at Scratch (which we did using a Raspberry Pi but you can also do on a PC).
Further on in the Instructable there is a lot more information on how to program Scratch for this project, so it is suggested that you read all the way through if you are not familiar with it. To play a note in Scratch, you select sound and then play note [selecting your chosen frequency/note] for the desired length. When you do so, a piano diagram shows. Scratch value of 60 is middle C. 0 is very low and 100 is painfully high!
To play a tune you can string a number of “play note” commands together, but to make a live instrument, such as the Piolin, we are using a PicoBoard / Arduino to sense where the bow is on the bridge and the ring on the frets. Looking at the input curve of the PicoBoard, to get Middle C (a value of 60) you would need a resistor value of about 15,000 ohms (15KΩ), but it would be near impossible to wire a load of resistors in series/parallel to get exactly the right value... and to maintain that value! So, this design gets values from the instrument and maps them to the octaves and notes. In this way the actual values from the hardware do not matter so much, as long as they are moderately stable and repeatable.
The PicoBoard has an on-board 10KΩ pull-up resistor, the onboard A-D converter takes an analogue input voltage and converts it to a value between 0 and 1023, then Scratch converts it to a value between 0 and 100. The input characteristics of the PicoBoard are therefore not linear. Please see the scratch value graph pictured.
You can check out Warwick University "Sensing Our World" for some useful resources, including a fuller discussion of using the PicoBoard, selecting input sensors etc. (Please note, I plotted and produced the curve above as part of the Sensing Our World workshop in 2012, therefore I am allowed to reproduce it here...and it is a good opportunity to point those interested in Scratch to a useful set of resources)
When choosing your resistors, the goal is to get a reasonable spread of scratch values that are as linear as possible. By a bit of trial and error we found our values, which are mapped in one of the pictures shown.
Now, we have wires and chains of resistors...in the real world these pick up noise (...especially from the mains) so the Scratch value can “waver” slightly, so early in the design phase I decided to “tune” the instrument, by mapping the Scratch values then taking a mean between these values to perform the test on – to determine where the bow and ring are on the bridge and fret respectively.
There are only 14 fret connectors, the last resistor in the chain is connected to the connector block so is not really accessible (hence the N/A – not available) ...you will notice however there are nominally 16 “mean values” ... this is significant because we can use them in a binary search within the Scratch script. A binary search is deterministic, it takes the same time each time as there is always 4 tests (with 16 values), if we were merely hunting up the value list a low value would match well before a higher value.
Using the same process, we determined that we should use 1kΩ resistors to connect the bridge.
Creating Chords
Scratch does a good job of synthesizing instrument sounds, but to give things a little extra depth I decided to make each 'string' of the Piolin play a simple chord. Simple chords work by counting 5 notes (to include the black sharp notes) and 5 white notes.
In the Scratch script I therefore have a list of note values and corresponding “semi - tone” values, i.e. one list does the top and bottom row and one the middle row as shown above. A sprite will “play”, e.g. the “C” note from the first list, another sprite the “E” note from the second list and t he third sprite the “C+5” note from the first list ( a s computers count from 0 its actually “C+4”). Earlier we saw that the Scratch values are 0 to 100, with 60 as middle C. The neck has 14 frets so , even with 4 “strings” on the bridge , we cannot access the full range. So, we need to choose which octaves we would like and where we want Middle C. The second image above shows the mapping for the octaves I decided to work with.
Sprites
My scratch project has one sprite to hold the two lists of notes, one for the fret control, one for the bridge control, one sprite – called instrument – which sets global values for the instrument – to make it sound like a violin for instance. There are also twelve sprites which I have called string_1 to string_12. These sprites, when triggered, look up the corresponding note value from the appropriate list and then “play” it.
Notes and Semis Sprites
Pictured is the two lists of note values, called notes and semis respectively.
So the chord in middle C, would be:
Item 35 of Notes (=60=C)
Item 35 of semis (=64=E)
Item 39 of Notes (=67=G)
Instrument Sprite
The strum octave is an offset into the Notes and semis lists, global instrument is set to 41 – which is the violin instrument in scratch. Remember Notes is indexed from 0, hence Item 20 of Notes is value 35 – which is B, shown at the start of the red arrow in the keyboard diagram above. 27 is B starting at the green arrow, 34 is B – yellow arrow and 41 is B on the blue arrow.
Bridge Sprite
Above is the script for the bridge sprite, remember the value table with the test values, these can be seen at the start of the script. This makes the design data driven/portable, if your hardware gives different value then just change the test values, hence the values in the ‘bridge_vals’ list. Even with these four values, we can use a binary search to speed up the testing of the values. To help you understand the script, it is shown mapped to a flow chart below
Fret Sprite
The fret sprite performs the binary search on the fret_vals list . As can be seen, a lightweight de-bounce is also performed on the value read from the frets before setting the global variable to let everything else know which fret is selected, therefore which chord.
Strings
There are 12 String sprites, arranged as group of three. As you can see from the above they take the global value supplied by the fret sprite add their offset into the Notes or semis list (plus 4 as appropriate) and then play that note. The appropriate group of three is triggered by the bridge sprite broadcasting the appropriate STRUM signal. They have two costumes, quiet (costume 3) and strummed (costume 2).
Make Your Bow
We made our bow from a scrap of hardwood that was shaped into an oval and drilled, with a metal strut from an old venetian blind (we were going to use a fibre-glass tent strut, but the owner of the strut objected!) More stiff wire formed the 'hair' of the bow.
Make a Finger Connector for the Fret
The connector ring connects with the fret to complete the circuit. To make it, all we did was loop a lot of bare wire around a ring of insulated wire, that can be worn on the finger to complete the circuit on the desired fret.
We wanted to make sure there were no sharp ends to stick out and that good connection would be ensured at all times.
Connect Everything Together: PicoBoard Version
Connect one ground of the PicoBoard to the start of the resistor chain that forms the frets of the Piolin, the other to the start of the resistor chain that forms the bridge. Leave the other end of each resistor chain unconnected.
The PicoBoard 'A' sense input connects to the finger ring that is used against the frets. The 'B' sense input connects to the bow. We used coloured tape to make sure that we could identify our connections easily. When these make contact with the wires on the fret and bridge, the circuits complete and provide the PicoBoard with an input.
Connect Everything Together: Arduino Version
If you don't have a PicoBoard you can use an Arduino with scratchboard emulation. The code is written by Kevin Osborn - full credit to him for the emulator, not me! - and the sketch can be downloaded here.
The resistor chains that form the fret and the bridge of the Piolin are each connected to a ground on the Arduino, with the other end of each chain left unconnected.
The finger ring is connected to analogue A0 and the bow is connected to analogue A1.
Chin Rest
The piolin proved uncomfortable to play, so we made a chin rest using an old sock and some stuffing. Rhesus Hoseus Coventry-Makerspacius (that's our sock monkey mascot to you and I) looked on as one of his cousins was pressed into service as a quick fix. If we'd had more time to make it pretty we would have done, but during a Pi Jam you just make do ;-)
Download the Scratch Code!
The full scratch code can be downloaded from the Coventry Makerspace website here.
I hope you enjoy the piolin!
This Instructable is entered into the reuse competition - if you like it, please vote for it!