I wanted to make a project that I'd love and enjoy, this is why I choose music since I've been playing guitar from a young age.
I choose to make a one octave piano that you could easily learn piano on it, with a UI that helps you to learn and visualion of your mistakes, I found the idea here.
I used Fusion 360 software for creating and assembling 2D design for the enclosure of the piano.
While for the keys I got a the STL files from here.
I also used GrabCad website to download some components.
The body has 6 parts. I started sketching with the base, its width has to fit the breadboard width and the length would fit two breadboard & arduino mega, I made a curve at the end trying to replicate a real piano.
The top part was almost a copy of the base except that its length is smaller to leave space in the front for the keys, it also has a small hinge for the curvature of the side.
The two sides are also the same, except that one would have the speaker mounted on it and the other has the arduino power socket cut from it.
It also has a lot of press fit tabs & t-slots to join with the base, front & back parts.
The height was flexible but I made sure it wasn't too short to fit the speaker height also the jumper wires.
The front was basically to hold everything together.
While the back had a straight pattern to make the wood flexible for bending to shape the curve of the base.
Note that the lines that are outside the rectangle should've been trimmed but I had fusion 360 crashing every time I tried to trim it so I edited it on lasercad instead.
We had another sketch for supporting the part that holds all the piano keys, this part was sketched after printing the keys since it was needed only because the octave length wasn't the same as the breadboard so I had to make supports to hold it from both sides.
After sketching each part I had to import each electronic component from GradCad then uploaded them on fusion 360, after that I extruded each sketch 3mm & assembled each part together using joints.
Some parts needed to be sketched over the component using the project option, I had to take in consideration where to place each component, so for the right side I had mounted the speaker and made 4 holes for it while the left side I had to make an opening for the arduino power socket and lastly the base has 4 holes for fixing the arduino.
Both top & back parts that had flexible straight pattern didn't give the required flexibility on fusion this is why I didn't extrude them.
At first I used inkscape to convert some images to dxf using the trace bitmap option.
Then on laser cad, I added all the dxf files to be cut using the parameters as following:
Cutting : speed 20 & power 70
Engraving : speed 300 & power 25
.
Then at the lab, I downloaded the files to the machine and started cutting on MDF sheets and here's how the process went.
For the black keys, the files I found had some hole but I didn't want that so instead I tried to sketch the same key on fusion 360 and extruded it before printing it.
For 3D printing, I opened cura to slice the keys I didn't use supports or adhesion but I scaled down the keys to 75% it took 7gm 38mins to print one white key with 10% infill & 2gm 15mins to print one black key with 20% infill.
I printed 7 white keys, 5 black keys & support keys that's used to hold all the keys together.
The process of printing took a lot of time this is why I printed them on separate days.
Printing the support
Printing the first Black key
Printing the first White key
Printing the other Black keys
Fritzing for drawing the circuit diagram.
Arduino IDE for uploading the code on the board.
Arduino mega to take inputs and perform action.
2 Breadboards for wiring all the components.
Speaker.
RGB leds.
Bluetooth Module to commuincate with Processing.
12 Limit switches representing the piano keys.
Processing for UI
The project has two main inputs, one from the UI representing the user choice of mode & songs while the other is from limit switches.
We have 7 limit switches that represent the 7 white keys from the piano and 7 rgb leds that corresponds to each button, The blue light is to indicate that a button is pressed in basic mode while in learning mode it indicates a correct note and red light indicates wrong one. Whenever you press on a button a note sound is generated on a speaker. There are another 5 limit switches presenting the black keys.
I used a bluetooth module to communicate with processing wirelessly. Arduino mega was needed since it has more I/O pins than arduino uno.
Honestly, the whole circuit diagram is kind of a mess :)
This is a small part of the circuit and the rest is repeated.
We have the limit switches from 2 to 13 digital output pins.
Blue rgb leds are from 14 to 20 while red rgb leds from 21 to 27 and finally the speaker is on 28.
I used 5v adapter since all of my components require no more than 5V.
I also read this article to help me understand more.
I wanted to make a GUI to interface with the player and help them learn some simple songs, I used processing which is very simple to program.
For communicating processing with arduino I used a Bluetooth module, to send characters to the arduino.
I used a library called controlP5 you can find the documentation here, this library helps in drawing many controllers such as Buttons, labels, ListBox, etc.
Since processing was basically java I wasn't so familiar with it, so the way I coded was opening the documentation for each controller and copying the parts I needed in my code.
The very first Scene!
it makes the user choose between the two modes that the piano has, if they choose basic mode, a new scene appears that tells them to play freely, it also sends a certain character for the arduino.
But if they choose the Learning mode, this Scene appears to clarify some information on the piano before starting to learn some songs.
This takes us to the last and final scene!
Here you can choose a song to play and you can also show /hide the notes of each song, or go back to the main menu.
In this scene processing sends the chosen song index to the arduino.
I used a library called "piano" to get the sound of each note, which I found on github.
Then I made an object from the piano class that takes speakerPin as an argument.
After that I defined all the seven white keys, five black keys and 7 RGB leds, I only used the blue and red colors.
This is an array of the songs that are avaliable for the user, each row represents the song index while columns represent the buttons sequence
Then I defined some variables that I'll use later.
In void setup() I defined all the buttons as an input, while the leds as outputs.
speaker.init() is a function used with the piano library to initialize the speaker.
In void loop(), the code waits for processing to send a character aka the user chooses a mode to play in. Arduino receives a character representing the mode and saves it in data variable.
Data:
if it's zero, we're in the basic mode, which means call these two functions, getIndex() which returns the index of the key pressed, notes(key) which plays the corresponding note sound on the speaker. In addition to emitting blue light from rgb leds whenever any white key is pressed.
if it's one, means we're in the learning mode, which calls the same two functions of the basic mode in addition to receiving an int (song) that represents the chosen song index and then call the detectSequence(song, key ) which compares the notes pressed to the correct ones and lights the rgb leds accordingly.
The detectSequence(), this function is used to compare the pressed key by the player with the correct key for a certain song.
The function takes two arrguments, the songRow : song index, key which is the key returned from getIndex() function.
If the key is correct the coressponding led emits blue light, if it's a wrong note, it emits red.
The getIndex() function is used to return the index of the pressed key to be used in other functions.
Note that I'm returning the pin number for each key which for the whitekeys starts from 2 and ends at 8, this is why the array index starts from i-2.
I also turned off all the leds if no white key is pressed.
keyPressed is a variable - could be considered as a flag- to be used in the detectSequence function.
Last function, void notes(key), which is used to call the function of each note corresponding to the pressed key from the piano class.
The default case is to stop the speaker, if no key is pressed.
After uploading the code
So first I wanted to test how the Key would hit the buttons and I figured out we needed an extra part (length) to make sure that when you press the button it press the limit switch.
After that I realized that the jumper wires were too long so I decided to use smaller electric wires.
Testing The basic mode
Testing The learning mode
I'm not gonna lie but this was the HARDEST part, the part where you use rubber bands to fix the keys on the support keys, it took me more than an hour to just mount these keys and it needed so much patience.
After I'm done testing the circuit & mounting all the keys, I started assembling all the parts together.
First mounting the breadboards using tape, then the arduino on the base & the speaker on the side using screws and nuts
After that I assembled the rest of the parts, top & the back.
then I added the extra length for the piano keys.
Testing the basic mode.
Sequence detection of "married life"
Sequence detection of "Happy birthday"
I had feedback from my friends about the UI background and scenes, They told me to change the background that I was using first.
Also Menna told me to add another scene to let the player know the notes names before playing songs.
Programming
At first I wanted to make an array of functions and each index would represent the function note, but that didn't work as the arduino C dosen't support array of pointers to function concept.
Mego helped me to write this function that calls each note function according to the argument it takes.
I came to this solution, It's to find to conditions that occur together only once, the conditions represent when the player releases their hand off the key.
key==0 means currently no keyPressed while keyPressed== true means there was a key pressed before.
I had another problem with detecting the sequence, which was I wanted to increase the index of the array each time the key is pressed, theoretically writing index++ is correct but actually the code gets executed very quickly, which made index increase by a lot in each press.
I had so many problems with processing, I wasn't very familiar with the syntax or the functions for each Controller, so at first every text was capitalized.
From the documentation I found a function called toUpperCase() that takes an argument false to lower case the text.
Circuit & Electronics
The circuit was very simple but I had a problem with the long jumpers when I tried to enclosure the project.
I got a wire and I used this tool to cut the wire with the length I wanted.
I think it's called wire stripper
Before
After
Design & Fabrication
When fabricating the flexible hinge on the top part, it broke every time:(
Sara, The lab specialist told me that I should've used plywood instead of MDF because the curvature was small and it won't hold.
I had struggles assembling the keys with the support keys using rubber bands, luckily sara helped me and we used a tweezer to stretch the rubber band.
Also the back part I made a mistake with it, which was that I had to leave a certain length between the slot and the start of the pattern, which I unknowingly didn't.
Mego helped me fixed this part by removing the tab & it fits as shown.
I would print all the project on a larger scale, because the small scale had the black buttons not reaching the other breadboard.
In addition to increasing the number of octaves to give me the capability of playing more songs and each octave would be separate and portable.
Also I would add button for changing the volume.
Finally, adding SD card and its module to play each song before The player try to learn them.