Adding accelerometer
This commit is contained in:
parent
76fb5d0dcf
commit
2c803918e9
36
src/accel.h
Normal file
36
src/accel.h
Normal file
@ -0,0 +1,36 @@
|
||||
#include <Wire.h>
|
||||
#define MPU_addr 0x68 // I2C address of the MPU-6050
|
||||
|
||||
int16_t AcX = 0;
|
||||
int16_t AcY = 0;
|
||||
int16_t AcZ = 0;
|
||||
int16_t Tmp = 0;
|
||||
int16_t GyX = 0;
|
||||
int16_t GyY = 0;
|
||||
int16_t GyZ = 0;
|
||||
int16_t cels = 0;
|
||||
|
||||
void initAccel() {
|
||||
Wire.begin();
|
||||
Wire.beginTransmission(0x68); // I2C address of the MPU-6050
|
||||
Wire.write(0x6B); // PWR_MGMT_1 register
|
||||
Wire.write(0); // set to zero (wakes up the MPU-6050)
|
||||
Wire.endTransmission(true);
|
||||
}
|
||||
|
||||
|
||||
void readAccel() {
|
||||
Wire.beginTransmission(MPU_addr);
|
||||
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
|
||||
Wire.endTransmission(false);
|
||||
Wire.requestFrom(MPU_addr, 14); // request a total of 14 registers LB : removing stop, no support in tiny wire
|
||||
|
||||
AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
|
||||
AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
|
||||
AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
|
||||
Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
|
||||
GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
|
||||
GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
|
||||
GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
|
||||
cels = Tmp / 340.00 + 36.53; //equation for temperature in degrees C from datasheet
|
||||
}
|
Loading…
Reference in New Issue
Block a user