Arduino to MAX
Connect your Arduino Mini to the USB Programmer.
TX to TX, RX to RX.
5V to power. Ground to Ground. Reset to Power.
Put an LED in the from the 13 pin to ground. You do not need a resistor it is built in to the 13 pin. This is to indicate power.
Connect the accelerometer power (VDD pin), connect it to ground. Send the X data to Analog 0, the Y data to analog 1, and the Z data to analog 2. Leave the ST pin alone. Note: I usually use an accelerometer that DOES have 90 degree headers. I used the straight header for the picture so you can see the accelerometer better.
Upload the following program and test it...
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 maxLoop = 3;
int inByte = -1;
void setup () {
pinMode(OUTPUT, ledPin);
Serial.begin(19200); //Open Serial
Serial.println("0,0,0,0");
}
void loop(){
for (int i = 0; i < maxLoop; i++){ //first looop get read data
for (int x = 0; x < avgLimit; x++){ //second loop to accumulate data
accelerometer[i] = analogRead(i); //Reads analog values
accVal = accelerometer[i] + accVal;
}
AVGaccelerometer[i] = accVal/avgLimit; //Calculates Average
accVal = 0; //Reset Acculumator
}
delay(10); //Take a rest Serial Port
if (Serial.available() > 0){ //if data is coming in
int inByte = Serial.read();
for (int i = 0; i < maxLoop; i++){ //Send this out!!
Serial.print(AVGaccelerometer[i],DEC); //Data Away!!!
Serial.print(",");
}
Serial.println(); //Send ASCII 10
}
digitalWrite(ledPin,HIGH); //Is this thing on???
}
0 Comments:
Post a Comment
<< Home