B4R Library rMPU6050_I2C - MotionTracking

Library to read values from the MPU6050 MotionTracking device by InvenSense.
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
Documentation used
Recommend to read the datasheet to explore more about this device.

The device connected to the Arduino Multi Function Shield
upload_2017-2-13_10-8-8.png


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

  • rMPU6050_I2C.zip
    9.3 KB · Views: 659
Last edited:

rbghongade

Active Member
Licensed User
Longtime User
Dear rwblinn,
Thanks for your wonderful turorials and libraries!
However I have a problem with using the rMPU6050 library with ESP8266 (Wemos D1 R2). The compiler throws an error as shown below:
B4X:
B4R version: 1.80
Parsing code.    (0.00s)
Compiling code.    (0.01s)
Building project    (0.01s)
Compiling & deploying Ino project (WeMos D1 R2 & mini - COM25)    Error

In file included from sketch\SoftwareI2C.cpp:31:0:
C:\Users\RAJESH\Documents\Arduino\libraries\NewliquidCrystal/SoftI2CMaster.h:55:20: fatal error: avr/io.h: No such file or directory
#include <avr/io.h>
                    ^
compilation terminated.
exit status 1
Error compiling for board WeMos D1 R2 & mini.
Can you please look into the matter,
Thanks and regards,
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

have checked out from here (the Arduino Library from which the B4R is wrapped): the library is for dedicated use with the Arduino Multi-function Shield.

Have not found (yet) a suitable library for use with the ESP8266.

Thanks for the feedback = appreciated :)
 
Last edited:
Top