Go Down

Topic: Code pour obtenir les données d'un gyro ADXRS. (Read 664 times) previous topic - next topic

Tholsadum

Bonjour,

Je tente de lire les données captées par un gyroscope/accéléromètre (IMU) branché sur mon micro-contrôleur (Arduino Mega), mais je n'y arrive pas.

Voici mon code:

Code: [Select]
/*
 ADXL3xx
 
 Reads an Analog Devices ADXL3xx accelerometer and communicates the
 acceleration to the computer.  The pins used are designed to be easily
 compatible with the breakout boards from Sparkfun, available from:
 http://www.sparkfun.com/commerce/categories.php?c=80
 http://www.arduino.cc/en/Tutorial/ADXL3xx
 The circuit:
 5v = analog 4 = 59
 ground = analog 5 = 60
 rate = analog 6 = 61
 Volt = analog 7 = 62
 st2 = analog 8 = 63
 st1 = analog 9 = 64
 st3 = analo 10 = 65
 y accel = analog 11 = 66
 x accel = analog 12 = 67
*/
// these constants describe the pins. They won't change:
const int groundpin = 60;             // ground = analog 5 = 60
const int powerpin = 59;              // 5v = analog 4 = 59
const int xpin = 67;                  // x-axis of the accelerometer
const int ypin = 66;                  // y-axis
const int ST1 = 64;                   // self-test 1
const int ST2 = 63;                   // self-test 2
const int ST3 = 65;                   // self-test 3
const int Rateout = 61;               // Rate pin
const int Volt = 62;                  // Volt pin

void setup()
{
  // initialize the serial communications:
  Serial.begin(9600);
  // Provide ground and power by using the analog inputs as normal
  // digital pins.  This makes it possible to directly connect the
  // breakout board to the Arduino.  If you use the normal 5V and
  // GND pins on the Arduino, you can remove these lines.
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW);
  digitalWrite(ST1, LOW);
  digitalWrite(ST2, LOW);
  digitalWrite(ST3, LOW);  
  digitalWrite(powerpin, HIGH);
}
void loop()
{
 
 // print the sensor values:
  Serial.print("xpin: ");
  Serial.print(analogRead(xpin));
  Serial.print("\t");
  Serial.print("ypin: ");
  Serial.print(analogRead(ypin));
  // print a tab between values:
  Serial.print("\t");
  Serial.print("Gyro: ");
  Serial.print(analogRead(Rateout));
     // print a tab between values:
  Serial.print("\t");
  Serial.print("Volts: ");
  Serial.print(analogRead(Volt));
  Serial.print("\t");
  Serial.print("\n");
  delay(1000);
}


Pourquoi, lorsque je l'upload sur le micro-contrôleur, la valeur pour les axes X et Y varient de la bonne façon, alors que celle du gyroscope reste toujours à 1019?

Merci.

Go Up