It’s time to hook up the whole system. The three of us met one final time to set up the flute (our lovely assistant, Box Cat) with grapes and the program Rebecca created to make this project interactive. While the Fruit Hero program was being finished, Amanda and I worked on getting the Arduino and breadboard into the box and ready for play. We ran into some interesting issues here, and we really had no idea why. We put the wires for the grapes up through the top of the box, and put the boards inside the box. We plugged a 9V battery into the board to see if we could make the system wireless, but then the program wasn't working. Touching the wires produced no sound. We thought the wiring was wrong, so we adjusted some things and tried again. Still no sound, or sometimes some notes would work and some wouldn't. We then plugged the board back into the computer, and it worked fine. We scratched our heads in awe, and then went to Google for answers.
Turns out, the problem is in the way the system is grounded. In this forum, a user explains that the system works fine if you touch the battery when touching the sensors, basically allowing your body and floor to be the grounding for the system. So when plugging it in to the computer, the computer acts as the grounding for the system. Pretty neat. Ultimately we went with the plug, since we need the Arduino to be talking and listening to the computer anyway for interaction.
Once Rebecca finished finalizing the Fruit Hero program, we hooked the two up together and played our new game. Read below to learn how we created the Fruit Hero program.
— From Rebecca’s blog, Arduino Hackers
Now we got the grapes playing notes, it’s time to send the note String data over to the computer.
Sending String data from the Arduino to the computer is very easy.
First you need to place this line of code in your setup method:
//Initialize serial communication at 9600 baud rate
Serial.begin(9600);
Serial.begin(9600);
Then to send String data from the Arduino to Processing, you need to use this line of code:
Serial.println(“A”);
delay(10);//delay by 10 miliseconds so we don’t send the String data super crazy fast to Processing
For the purpose of our project, we placed it in the loop method, since we are listening for whenever a grape is touched to produce a note.
On the Processing side, we first need to import a library. You can place this line of code before your setup method in Processing.
import processing.serial.*; //For Arduino to send over the String data to Processing
Then in your setup method, you need to place these lines of code:
//Get the port in the serial list
String portName = Serial.list()[5];// 5 – port number
myPort = new Serial(this, portName, 9600);
String portName = Serial.list()[5];// 5 – port number
myPort = new Serial(this, portName, 9600);
For my MacBook Pro laptop, port 5 is the one I am using on the Arduino side. Your port will be different based on what computer you are using. You can use this line to see what ports are available on your computer:
println(Serial.list()[5]); //5 is the port number. To check, put in 0, 1, 2, etc. until you find the String printed out by this function to match the Serial port description for your Arduino Serial Port. Mine is /dev/tty.usbmodemfa131. You can check what Serial Port you have by clicking on Tools -> Serial Port and see which one is checked.
Finally to get the String data value from the Arduino, you need these lines of code in your draw method:
//If we get data from serial port,
//then read it and store it in a variable
if(myPort.available() > 0)
{
serialPortValue = myPort.readStringUntil(‘\n’);
}
//then read it and store it in a variable
if(myPort.available() > 0)
{
serialPortValue = myPort.readStringUntil(‘\n’);
}
I used this tutorial to get this part working.
—
Some little details came in later, like adding in the “Call Me Maybe” music sheet and a color change for correct and incorrect notes. We also added in fireworks effects and celebration text to make the experience more dynamic. Since was the one who was best practiced at playing the "instrument," they had me demonstrate our project to the class, and they loved it. (Video available here)
Final Project – Complete. Thus, we end our time in Physical Computing.
You can view the entire project and its code here.
–
Rebecca: http://arduinohackers.wordpress.com/