Wednesday, September 30, 2009

Lab 2: Theramin

Checkout the Video of "Mary Had a Little Lamb" on our electric instrument programmed on an Arduino MEGA board.


We have a small pressure pad that acts as a volume pedal, and we can select predefined tones from the knob (potentiometer). The tones were defined as the one octave scale in the natural key of C (see code below). The potentiometer sensor produces an analog input to our Arduino board, and the Arduino board was programmed to produce a digital output corresponding to the frequency of the note. The volume pedal is in series with the speaker.

We noticed the pedal was a create user-interface. It provided smooth, continuous feedback and was very easy to operate. Although we didn't get around to it, it could make a good controller for pitch due to it's continuous response to force (although sustaining extreme notes requiring high force input may be uncomfortable).

Here's a schematic of our instrument:


Here's the code we programmed into the Arduino, based on Arduino's Melody example:
/* Melody
* (cleft) 2005 D. Cuartielles for K3
* Modified by Andrew Rohr, Anish Joshi, Michael Woon
*
* This example uses a piezo speaker to play melodies. It sends
* a square wave of the appropriate frequency to the piezo, generating
* the corresponding tone.
*
* The calculation of the tones is made following the mathematical
* operation:
*
* timeHigh = period / 2 = 1 / (2 * toneFrequency)
*
* where the different tones are described as in the table:
*
* note frequency period timeHigh
* c 261 Hz 3830 1915
* d 294 Hz 3400 1700
* e 329 Hz 3038 1519
* f 349 Hz 2864 1432
* g 392 Hz 2550 1275
* a 440 Hz 2272 1136
* b 493 Hz 2028 1014
* C 523 Hz 1912 956
*
* http://www.arduino.cc/en/Tutorial/Melody
*/

#include

int tone=0;
int addr = 0;
int speakerPin = 9;
int ledPin = 13;
int sensorPin = 0; //Analog Input ~0-5V
float sensorValue = 0;
char n = 'c';
char n1='c';

int length = 15; // the number of notes
float prevval=0;
float val=0;
int j=2;

void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
}

void loop() {


sensorValue = analogRead(sensorPin)/100;

if(prevval!=sensorValue)
{
EEPROM.write(addr,sensorValue);
addr=addr+1;
}


if(addr == 512)
addr=0;

if (sensorValue <= 1){ n1 = 'c'; digitalWrite(ledPin,HIGH); //playNote(n); } if (sensorValue > 1 && sensorValue <= 2){ digitalWrite(ledPin,LOW); n1 = 'd'; //playNote(n); } if (sensorValue > 2 && sensorValue <= 3){ n1 = 'e'; digitalWrite(ledPin,HIGH); //playNote(n); } if (sensorValue > 3 && sensorValue <= 4){ n1 = 'f'; digitalWrite(ledPin,LOW); //playNote(n); } if (sensorValue > 4 && sensorValue <= 5){ n1 = 'g'; digitalWrite(ledPin,HIGH); // playNote(n); } if (sensorValue > 5 && sensorValue <= 6){ n1 = 'a'; digitalWrite(ledPin,LOW); // playNote(n); } if (sensorValue > 6 && sensorValue <= 7){ n1 = 'b'; digitalWrite(ledPin,HIGH); //playNote(n); } if (sensorValue > 7 && sensorValue <= 8){ n1 = 'C'; digitalWrite(ledPin,LOW); //playNote(n); } char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; n=n1; // play the tone corresponding to the note name for (int i = 0; i < tone="tones[i];" j="2;">0)
{
int sensor = 0;
sensor=analogRead(sensorPin);
if(sensorValue!=sensor)
j=-1;
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);

}

}

}

n1 ='d';
prevval=sensorValue;
}

n1 ='d';
prevval=sensorValue;
}

Lab 2: Labview I/O

Working with the Labview portion of the lab required the configuration of analog inputs along with both analog and digital outputs. A couple pictures along with videos are located below serving as simple examples to our accomlishments with the Labview interface.



The figure directly below exemplifies three important concepts. Using the DAQ Assistant block in Labview, analog I/O along with digital output was configured. Refering to the figure, the bottom lop represents analog input to the NI-PCI-6230. A wave from was generated to verify the functionality of the analog input. The while loop in the upper left corner of the figure indicates the setup used to control digital output with the flip of a toggle switch in Labviews virtual interface. The while loop in the upper right corner of the figure indicates analog output from Labview. In this instance we simply generated a sine wave to verify functionality of the analog output DAQ Assistant.




The front panel of labview is shown below. The generated sine wave can be seen, and it's characteristics such as frequency and amplitude can be controlled by the user. The toggle switch controls the on/off capability of the digital output. A blinking LED in the video below shows the user toggling the switch back and fourth controlling the LED to turn off and on.





In the video below labview was programmed to output an analog signal which the team used to power a speaker.





Analog signals from the potentiometer and photo cell were also input into Labview to gain an additional understanding of how to control analog inputs.


Monday, September 28, 2009

Lab 2 - Servo motor control using Aruduino

We were able to successfully control the servo motor using the melody program found under examples on the Arduino website. A video demonstrating this statement is below.

Lab 2 - Sensor to Arduino board interface

Tasks one through four have been completed.

Simple circuits have been designed for each sensor in order to connect the sensor to the arduino board. Sensor functionality was tested and verified. From there the digital signals from each sensor; hall effect, FSR, photocell, and potointerrupter were all taken into the ardino board, and having the ability to affect the blinking LED ensured us of a working sensor to arduino board interface utilizing both digital inputs and digital outputs on the board.

Bringing in analog signals to the arduino board from the petentiometer, the photoresister (configured as a voltage divider), and the hall effect sensor was a simple task. However, understanding how to use EEPROM to write and read accross the serial port has been challenging. We currently are able to write data. Then we have separately run the EEPROM read script in order to obtain values stored in the boards internal memory.

A video of the potentiometer controlling the LED is below as an example of our progress.



Lab 2 Group Members

Lab 2 Group 5 team members included:

Anish Joshi
Andrew Rohr
Michael Woon

Wednesday, September 23, 2009

Lab 1 - Our device as a Musical Instrument

The device we created does indeed function as a musical instrument as it outputs sound based on human input. However, the device left much to be desired. First, the variable resistor only had a fixed range and therefore only allowed a distinct range of sound to be produced by the circuit. Also, since the slider had a short stroke, it was very difficult to make very small changes in output pitch. Additionally, because the slider was continuous, it was difficult to arrive at the same location consistently. This made the output sound different every time.

Hearing the final device perform as it was intended was somewhat rewarding, though. Knowing that we made a circuit that worked as we desired provided positive re-enforcement towards our knowledge base. Additionally, it exposed some of the uses these types of circuits can have when they are integrated with each other.

We realize that in future work that the interface between the device and the human will be just as important as the circuit itself. This device showed this principle because it was an awkward device to manipulate and use. While it did perform its function well, its form was neglected. This will be an important part of the final project.

Lab 1: Slideophone-The Required Blog Write-up Bit

In addition to being a tremendously expressive musical instrument, the Slideophone (aptly named after its ingenious sliding potentiometer interface and robust clarity of sound) provides great utility to any band in need of that special kind of sound reminiscent of a baby's scream mixed with a little southern twang. And for the one time price of $1152 (3 grad students @ $32/hr (stipend & tuition) * 12 hours (class & lab)), it had better have a great deal of value. If bleeding ear-drums could stand, the Slideophone's performance would receive a standing ovation.

So come on down to the Mechatronics lab when you can witness a miracle (it actually was successfully created), and see the satisfied smiles on our faces as we are no doubt rewarded with great honors--or at least an A.