User:Chattons2/ENES100/PROJECT drei

Project Preference

 * Beat Bearing
 * Wireless Electricity
 * LEGO

Problem Statement
Our goal is to continue where we left off.

Project Plan
During this project cycle I will continue to work with the arduino. I will find codes to control the switches and pots. After that I will work with Mahmud, who is currently learning about different drum beats and sounds. I will use the code I found to control the beats he chose.

Week 1 Narrative
This week my goal was to get the potentiometer connected on pin A1 to control the volume of a beat sample.

While working with the arduino, I encountered one problem that was hard to solve. I was not able to upload codes into the arduino, even though there was nothing wrong with the codes. Whenever I tried to upload a code, I received an error message: "avrdude stk500_getsync not in sync resp=0x00"; apparently this happens a lot with windows 8

I looked for solutions online and this is what I found:

1) You can reset the arduino (the reset button is on the right upper corner of the arduino)

2) if that does not work you can Update the driver;

Instructions 1

instructions 2

I tried those two things but the message was still showing up. I then removed the shield from the arduino and uploaded the code. After the code was successfully uploaded into the arduino, I placed the shield back on. Although it worked, I will still need to find a better solution because it is annoying to have to remove the shield every time before uploading codes.

I tried different codes but I was not able to find one that will help control the volume. However, while playing around with different codes I was able to control the pitch. I will assign that to a pin attached to a switch and I will keep on testing different codes to control volume using the second pot.

Week 2 Narrative
My task this week was to get the second pot to control the volume. I thought I would be able to do that by using the MIDI volume code that I found on the arduino website. I merged that code with the previous code I had and uploaded it. It did not work. When I tested (turned) the potentiometer, the volume did not change. Instead, I noticed that the note had changed. When the pot was on low, the midi was playing on a high note. When I increased the pot's range, a lower note was played.

To fix it, it turned out all I had to do was to edit the velocity section of the previous code had. That section functioned using hex numbers. A hexadecimal (hex) number is positional numeral system with a base of 16. it uses the numbers 0-9 to represent values from 0-9 and uses A-F to represent values from 10-15. For instance the number 10 in hex would be 0xA. This website converts normal numbers to Hex numbers. For more information about hex numbers, visit the Hexidecimal wikiedia page.

With the help of my instructor, we found the right hex numbers to use and mapped it to the second potpin.

Here is the new code:

/* MIDI note player */ int potPin = 0;   // select the input pin for the potentiometer int Speed = 13;  // select the pin for the Speed int val = 0;      // variable to store the value coming from the sensor const int sensorMin = 23;     // sensor minimum, discovered through experiment const int sensorMax = 1000;   // sensor maximum, discovered through experiment int volume=50; int val2;      // second potentiometer

void setup { // Set MIDI baud rate: Serial.begin(31250); // pinMode(Speed, OUTPUT); // declare the Speed as an OUTPUT } void loop{

//Note on channel 1 (0x90), some note value (note), middle velocity (0x45): noteOn(0x90, 0x43, volume); delay(100); val2=analogRead(1); volume=map(val2,0,1000,0,100); // takes range on val2 and converts to pot range. val = analogRead(potPin);   // read the value from the sensor digitalWrite(Speed, HIGH); // makes song faster delay(val);                 // stop the program for some time digitalWrite(Speed, LOW);  // Slows down Speed delay(val);                 // stop the program for some time

}

// plays a MIDI note. // cmd is greater than 127, or that data values are  less than 127: void noteOn(int cmd, int pitch, int velocity) { Serial.write(cmd); Serial.write(pitch); Serial.write(velocity); }

Another thing I had to fix was the error code I received every time I tried to upload a code into the arduino. Here is the message I keptgetting every time I tried to upload a code into the arduino.

To fix it, I usually just disconnected the shield from the arduino itself. It worked but it was annoying. And apparently doing that could have destroyed the arduino completely. Thus I had to find another solution. My instructor noticed that there was a switch on the middle of the shield (right next to MIDI IN). At the moment the button was on RUN. We simply switched it to Program and just like that, I stopped getting that error message.

My next task is to assign a role to the switch buttons on the MIDI shield and get with my group so we can assemble our pieces.

Week 3 Narrative
This week, I worked with Mahmud and Yasmine. One of our tasks was to improve the code that we had created last week. Our plan was to take one of the codes that the previous group had created and control the volume and speed of the song it played. We chose to do that in hope to make it easier for the next group. That way, they will know how to use the code we created to control volume/speed of any drum beat they decide to use in the future.

Here is one of the codes from the previous group:

To get the volume to work with this code, we had to add val2=analogRead(1);      Volume=map(val2,0,1000,0,100); at the beginning of every NoteOn section. We tried to get the speed to work as well but it wouldn't work with this song...I am not sure why. when we added the code for speed, it changed the note of the keyboard instead. We will work on it again next week.

Here is the final code:

This video shows the volume change. Because it was just an example, we didn't use the entire code that the previous group had left. We cut it short.

As for the buttons, we were not able to get them to work. We were planning on getting the first one to turn the song on and off. We started with the AnalogInput example from the arduino software and modified it but we were not able to get the switch button to turn the music on and off. Next week we will test other codes.

Moreover, I realized that I made a mistake on the code I uploaded on the WEEK TWO update. I copied that code and tried to upload it this week (when working on my tasks) but it did not work. Hence, here is the correct/cleaner code:

Lastly, This week I also helped Jake and John work on the board for a little bit. They had to build a sample for a new design (for the board) since they had a problem with the board they built last week. I helped them start building the new sample board by cutting some of the washers in halves, drilling holes on the board, and gluing the runners on the plexiglass using hot glue.  File:Drilling the holes.JPG|Drilling the holes after being marked with the template. 

Week 4 Narrative
This week we tried to get the switch pin to work but we couldn't. We found a code on lesson five of the arduino section, on the Ladyada website. The lesson taught how to get a switch to turn an LED on and off. We were hoping to use that code to get the switch on the MIDI to turn the songs (played from the keyboard) on and off. Here is the first code we used: We modified the code a bit and uploaded it into our arduino. As we clicked the on/off button, the song would stop but then continue on after a couple seconds. So we knew something was working, but it just needed more work.

Therefore, we thought we needed to start simple and figure out where the problem was. We removed the the code for the SAIL song and started with an easy/simple beat instead. After we tested it, the switch button was still not working. We are doing something wrong but unfortunately we just cant figure out what it is.