BoldizarF / ariot19

Other
0 stars 0 forks source link

Implement extra sensors on car #27

Open BoldizarF opened 5 years ago

ddjohn commented 5 years ago

I2C Scanner:

#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);
}
ddjohn commented 5 years ago

Sensor: MPU-6050 (Accelerometer + Gyro + Magnetometer + DMP) Library: https://playground.arduino.cc/Main/MPU-6050 Address: 0x68 (I2C)

Pins: VCC - 5V GND - GND SCL - Serial clock line SDA - Serial data line XDA (AUX_DA) - Not tested (advanced) XCL (AUX_CL) - Not tested (advanced) ADO - Not tested (advanced) INT - Not tested (advanced)

Registers: 0x3B/3C - Accelerometer X 0x3D/3E - Accelerometer Y 0x3F/40 - Accelerometer Z 0x41/42 - Temperature 0x43/44 - Gyro X 0x45/46 - Gyro Y 0x47/48 - Gyro Z 0x6B - Wakeup (value:0)

platisd commented 5 years ago

Ah, you are considering the mighty MPU6050 I see!

Unless you want to work with the raw values and infer the tilt of the car or something, or create your own algorithm to calculate the car's orientation (don't...), I would look into this sketch which uses the digital motion processor on the MPU6050 itself so to get the absolute orientation from the beginning of the measurement.

Alternatively, you could use the GY-50 gyroscope that can be found (it's detachable as well) on the shield that I left with you.