Library to read values from the MPU6050 MotionTracking device by InvenSense.
The library
The device connected to the Arduino Multi Function Shield
Wiring for the Tests
MPU6050 = Arduino Uno (Wirecolor)
VCC = +5v (red)
GND = GND (black)
SCL = D5 [PWM] (Arduino Uno, Leonardo), D5 [PWM] (MEGA2560) (yellow)
SDA = D6 [PWM] (Arduino Uno, Leonardo), A5 (MEGA2560) (brown)
MPU6050 = Multi Function Shield
VCC = +5v (red)
GND = GND (black)
SCL = pin5 (Arduino UNO, Leonardo), pin5 (MEGA2560) (yellow)
SDA = pin6 (Arduino UNO, Leonardo), A5 (MEGA2560) (brown)
Example
Output
A in g :: X=0,Y=0,Z=0
G deg/s :: X=-1,Y=0,Z=0
T degC=24.6000
A in g :: X=-1,Y=0,Z=0
G deg/s :: X=-183,Y=-249,Z=249
T degC=24.6000
ChangeLog
20170212 v1.0
The library
- is based on open source project http://www.cohesivecomputing.co.uk/hackatronics/arduino-multi-function-shield/
- enables to read the temperature (degC), acceleration in g and the gyro angular velocity (deg/s)
- supports I2C addresses: 0x68 (the default) or 0x69.
- tested with sensor model GY-521 from Sunfounder connected to 1) an Arduino Uno and 2) Arduino Multi Function Shield placed on an Arduino MEGA.
- requires the classes (included in the MPU6050 folder): SoftI2C, II2C, I2C, MPU6050
- http://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf
- https://www.mpja.com/download/hackatronics-arduino-multi-function-shield.pdf
The device connected to the Arduino Multi Function Shield
Wiring for the Tests
MPU6050 = Arduino Uno (Wirecolor)
VCC = +5v (red)
GND = GND (black)
SCL = D5 [PWM] (Arduino Uno, Leonardo), D5 [PWM] (MEGA2560) (yellow)
SDA = D6 [PWM] (Arduino Uno, Leonardo), A5 (MEGA2560) (brown)
MPU6050 = Multi Function Shield
VCC = +5v (red)
GND = GND (black)
SCL = pin5 (Arduino UNO, Leonardo), pin5 (MEGA2560) (yellow)
SDA = pin6 (Arduino UNO, Leonardo), A5 (MEGA2560) (brown)
Example
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private mpu As MPU6050_I2C
Private Timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
'Init the MPU first via SoftI2C with low address 0x68
mpu.InitializeSoftI2C(mpu.ADDRESS_AD0_LOW,0,0,0)
'Init the timer
Timer1.Initialize("Timer1_Tick", 1000)
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
'Temperature in deg C
Dim t As Double = mpu.GetTemp10th / 10
Log("T degC=", t)
'Acceleration in g (1g = 9.8 m/s/s)"
mpu.GetAccelRaw
Log("A in g :: X=", mpu.Accel_X_Raw, ",Y=", mpu.Accel_Y_Raw, ",Z=", mpu.Accel_Z_Raw)
'Gyro angular velocity in degrees / second")
mpu.GetGyroRaw
Log("G deg/s :: X=", mpu.Gyro_X_Raw, ",Y=", mpu.Gyro_Y_Raw, ",Z=", mpu.Gyro_Z_Raw)
End Sub
Output
A in g :: X=0,Y=0,Z=0
G deg/s :: X=-1,Y=0,Z=0
T degC=24.6000
A in g :: X=-1,Y=0,Z=0
G deg/s :: X=-183,Y=-249,Z=249
T degC=24.6000
ChangeLog
20170212 v1.0
Attachments
Last edited: