Dual Accelerometers
I am now trying to use two accelerometers placed at a 90 degree difference to create a more stable orientation. This is a common practice used in robotics and vehicles. Two accelerometers are used in the Nintendo WiiMote as well. Pictures will be up later today. Today's project is to get Processing to understand the data. Currently processing is only receiving the data and doing nothing with it. I am working on the math and will implement it in OPENGL.
Here is the arduino code for the two accelerometers. I used an array to make the programing less messy. I am also averaging the data because the accelerometer kicks out a lot of data that can vary with minute vibrations.
Here is the arduino code for the two accelerometers. I used an array to make the programing less messy. I am also averaging the data because the accelerometer kicks out a lot of data that can vary with minute vibrations.
int ledPin = 13; //Power Pin
int accelerometer[6]; //Array for analog values
int AVGaccelerometer[6]; //Array for Average Values
int avgLimit = 5; //Number values in the Average
int accVal = 0; //Accumulated number for aveerage
int inByte = -1;
void setup () {
pinMode(OUTPUT, ledPin);
Serial.begin(9600); //Open Serial
Serial.println("0,0,0,0,0,0");
}
void loop(){
//first looop get read data
for (int i = 0; i < 6; i++){
//second loop to accumulate data
for (int x = 0; x < avgLimit; x++){
accelerometer[i] = analogRead(i);
//Reads analog values
accVal = accelerometer[i] + accVal;
}
AVGaccelerometer[i] = accVal/avgLimit;
//Calculates Average
accVal = 0; //Reset Acculumator
}
//Take a rest Serial Port
delay(10);
//if data is coming in
if (Serial.available() > 0){
int inByte = Serial.read();
//Send this out!!
for (int i = 0; i < 6; i++){
//Data Away!!!
Serial.print(AVGaccelerometer[i],DEC);
Serial.print(",");
}
//Send ASCII 10 used by Processing
Serial.println();
}
//Is this thing on???
digitalWrite(ledPin,HIGH);
}
0 Comments:
Post a Comment
<< Home