Accelerometer: Adafruit ADXL345 [link]
Gyroscope: Adafruit L3GD20 [link]
For the Arduino Uno, SCL: A5 and SDA: A4
This is just a simple code to run the accelerometer and gyroscope at the same time. It is mostly adapted from the library.
Gyroscope: Adafruit L3GD20 [link]
For the Arduino Uno, SCL: A5 and SDA: A4
This is just a simple code to run the accelerometer and gyroscope at the same time. It is mostly adapted from the library.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345.h>
#include <Adafruit_L3GD20.h>
#define USE_I2C
#define debug false
Adafruit_L3GD20 gyro;
Adafruit_ADXL345 accel = Adafruit_ADXL345(12345);
void setup() {
Serial.begin(9600);
Wire.begin();
#ifdef debug
if (!gyro.begin(gyro.L3DS20_RANGE_250DPS))
// if (!gyro.begin(gyro.L3DS20_RANGE_500DPS))
// if (!gyro.begin(gyro.L3DS20_RANGE_2000DPS))
{
Serial.println("Oops ... unable to initialize the L3GD20. Check your wiring!");
while (1);
}
if (!accel.begin()){
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}
#endif
accel.setRange(ADXL345_RANGE_4_G);
// displaySetRange(ADXL345_RANGE_8_G);
// displaySetRange(ADXL345_RANGE_4_G);
// displaySetRange(ADXL345_RANGE_2_G);
}
void loop() {
// reading for gyroscope
gyro.read();
Serial.print("gyro_X: "); Serial.print((int)gyro.data.x); Serial.println(" ");
Serial.print("gyro_Y: "); Serial.print((int)gyro.data.y); Serial.println(" ");
Serial.print("gyro_Z: "); Serial.print((int)gyro.data.z); Serial.println(" ");
// reading for accelerometer
sensors_event_t event;
accel.getEvent(&event);
Serial.print("accel_X: "); Serial.print(event.acceleration.x); Serial.println(" ");
Serial.print("accel_Y: "); Serial.print(event.acceleration.y); Serial.println(" ");
Serial.print("accel_Z: "); Serial.print(event.acceleration.z); Serial.println(" ");
delay (100);
}