tockn / mpu6050_tockn Goto Github PK
View Code? Open in Web Editor NEWArduino library for easy communication with MPU6050
Arduino library for easy communication with MPU6050
Angle Z shifted after rotating many times by -40 or 20 or -11 ,...
but X & Y angles didn't effected even when moving fast
you are using coff of Gyro & Acc in Angle X ,Angle Y
but in Z angle you didn't made that , Why?
angleX = (gyroCoef * (angleX + gyroX * interval)) + (accCoef * angleAccX);
angleY = (gyroCoef * (angleY + gyroY * interval)) + (accCoef * angleAccY);
angleZ = angleGyroZ;
thanks alot for your wonderful effort :)
@tockn, could you tell, what is the measurement units of raw data of acceleration and angular velocity?
I mean variables here:
rawAccX = wire->read() << 8 | wire->read();
rawAccY = wire->read() << 8 | wire->read();
rawAccZ = wire->read() << 8 | wire->read();
rawGyroX = wire->read() << 8 | wire->read();
rawGyroY = wire->read() << 8 | wire->read();
rawGyroZ = wire->read() << 8 | wire->read();
Hello, I would like to know the default sensitivity for both the accelerometer and gyroscope in this library and if possible would want to change it. Thank you so much
(full scale ranges)
acceleration: ±2g ±4g ±8g ±16g
rotation: ±250°/s ±500°/s ±1000°/s ±2000°/s.
I'm thinking it might be ±2g and ±500°/s but I might be wrong.
Upon compilation:
Compiling .pioenvs\genericSTM32F103C8\lib0d0\MPU6050_tockn_ID2824\MPU6050_tockn.cpp.o
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp: In member function 'void MPU6050::calcGyroOffsets(bool)':
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:71:53: error: no matching function for call to 'TwoWire::requestFrom(int, int, int)'
wire->requestFrom((int)MPU6050_ADDR, 14, (int)true);
^
In file included from C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/Wire.h:42:0,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.h:5,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:1:
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate: uint8 WireBase::requestFrom(uint8, int)
uint8 requestFrom(uint8, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate expects 2 arguments, 3 provided
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate: uint8 WireBase::requestFrom(int, int)
uint8 requestFrom(int, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate expects 2 arguments, 3 provided
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:73:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:74:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:75:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:76:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp: In member function 'void MPU6050::update()':
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:105:52: error: no matching function for call to 'TwoWire::requestFrom(int, int, int)'
wire->requestFrom((int)MPU6050_ADDR, 14, (int)true);
^
In file included from C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/Wire.h:42:0,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.h:5,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:1:
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate: uint8 WireBase::requestFrom(uint8, int)
uint8 requestFrom(uint8, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate expects 2 arguments, 3 provided
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate: uint8 WireBase::requestFrom(int, int)
uint8 requestFrom(int, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate expects 2 arguments, 3 provided
*** [.pioenvs\genericSTM32F103C8\lib0d0\MPU6050_tockn_ID2824\MPU6050_tockn.cpp.o] Error 1
I'm not entitely sure what's up. I'm using PlatformIO, and building for the STM32F103C Blue Pill.
For example, 180 degrees will gradually change to 0 degrees and negative numbers, and will restore the Angle after stability
是这个时钟的问题吗
`gyroX -= gyroXoffset;
gyroY -= gyroYoffset;
gyroZ -= gyroZoffset;
interval = (millis() - preInterval) * 0.001;
// interval = 0.0001;//次数受芯片时钟影响,将其设置成一个固定值
angleGyroX += gyroX * interval;
angleGyroY += gyroY * interval;
angleGyroZ += gyroZ * interval;`
Is it possible to communicate with more than one MPU6050 on same bus? (i.e. with 2 MPU6050, the 1st has address 0x68, the 2nd has pin AD0 at high level so its address become 0x69).
How is it possible to handle this?
Hi there,
I'm using esp-wroom32 and i just noticed that when we turn the power ON (from usb or from a battery) calibration coef are 2x higher than what they should be. measurment are also 2 times higher.
When i reset the board via the reset bouton, calibration coef are goods, 2 times less than before. Measurment are perfect.
This behavior is hapening every time.
exemple :
when i turn it ON it's : (coefX = 4 / coefY = 2 / coefZ = 2)
Each time i reset it's : (coefX = 2 / coefY = 1 / coefZ = 1)
I can bypass this problem easily but i'd like to know why it's happening so i could not program 2 different behavior...
Any idea ?
Thanks
what is the difference between angleX Vs angleAccX ?
I notice that angleX is using also the gyroscope to calculate the angleX but the angleAccX it doesn't. So the angleX is more accurate to use?
The angleX is the roll and angleY is the Pitch ?
Hi,
First thanks fro the code, it's by far the easiest to use for the MPU, but I have noticed the angles in X and Y are consistently off.
I made a 3D printed block with surfaces at 0, 30, 45, 60 and 90 degrees to test and found that both X and Y have issues.
At 0 degrees the error is 1-2 degrees (Not an issue)
However, at 30 degrees both X and Y read between 23-26,
at 45 both read around 34-37,
at 60 both read 46-48
and at 90 both read about 75.
So about 15-25% error.
Any reason for this? I tried varying the accel/gyro ratio and nothing seemed to effect it.
Thanks in advance.
Hi,
This is not an issue its , just a question!
The normal mpu6050 library does not compile for seeeduino xiao and throws errors, but surprisingly this does , can I know the reason?
There is a way to make it works in a ESP8266 Based Dev Board?
Thanks...
Modifications at setup:
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin(GYRO_CONFIG_500, ACCEL_CONFIG_16G, MPU6050_ADDR);
mpu6050.calcGyroOffsets(true);
}
Modifications MPU6050_tockn.h:
#ifndef MPU6050_TOCKN_H
#define MPU6050_TOCKN_H
#include "Arduino.h"
#include "Wire.h"
#define MPU6050_ADDR 0x68
#define MPU6050_ADDR1 0x69
#define MPU6050_SMPLRT_DIV 0x19
#define MPU6050_CONFIG 0x1a
#define MPU6050_GYRO_CONFIG 0x1b
#define MPU6050_ACCEL_CONFIG 0x1c
#define MPU6050_WHO_AM_I 0x75
#define MPU6050_PWR_MGMT_1 0x6b
#define MPU6050_TEMP_H 0x41
#define MPU6050_TEMP_L 0x42
#define ACCEL_CONFIG_2G 2
#define ACCEL_CONFIG_4G 4
#define ACCEL_CONFIG_8G 8
#define ACCEL_CONFIG_16G 16
#define GYRO_CONFIG_250 250
#define GYRO_CONFIG_500 500
#define GYRO_CONFIG_1000 1000
#define GYRO_CONFIG_2000 2000
class MPU6050{
public:
MPU6050(TwoWire &w);
MPU6050(TwoWire &w, float aC, float gC);
void begin(int gyros = GYRO_CONFIG_500, int accel = ACCEL_CONFIG_2G, int addr = MPU6050_ADDR);
void setGyroOffsets(float x, float y, float z);
void writeMPU6050(byte reg, byte data);
byte readMPU6050(byte reg);
int16_t getRawAccX(){ return rawAccX; };
int16_t getRawAccY(){ return rawAccY; };
int16_t getRawAccZ(){ return rawAccZ; };
int16_t getRawTemp(){ return rawTemp; };
int16_t getRawGyroX(){ return rawGyroX; };
int16_t getRawGyroY(){ return rawGyroY; };
int16_t getRawGyroZ(){ return rawGyroZ; };
float getTemp(){ return temp; };
float getAccX(){ return accX; };
float getAccY(){ return accY; };
float getAccZ(){ return accZ; };
float getGyroX(){ return gyroX; };
float getGyroY(){ return gyroY; };
float getGyroZ(){ return gyroZ; };
void calcGyroOffsets(bool console = false);
float getGyroXoffset(){ return gyroXoffset; };
float getGyroYoffset(){ return gyroYoffset; };
float getGyroZoffset(){ return gyroZoffset; };
void update();
float getAccAngleX(){ return angleAccX; };
float getAccAngleY(){ return angleAccY; };
float getGyroAngleX(){ return angleGyroX; };
float getGyroAngleY(){ return angleGyroY; };
float getGyroAngleZ(){ return angleGyroZ; };
float getAngleX(){ return angleX; };
float getAngleY(){ return angleY; };
float getAngleZ(){ return angleZ; };
private:
TwoWire *wire;
int16_t rawAccX, rawAccY, rawAccZ, rawTemp,
rawGyroX, rawGyroY, rawGyroZ, mpuAddr;
float gyroXoffset, gyroYoffset, gyroZoffset;
float temp, accX, accY, accZ, gyroX, gyroY, gyroZ;
float angleGyroX, angleGyroY, angleGyroZ,
angleAccX, angleAccY, angleAccZ;
float angleX, angleY, angleZ;
long interval, preInterval;
float accCoef, gyroCoef, gyrosFactor, accelFactor,
gForce, gForceInv;
};
#endif
Modifications MPU6050_tockn.ccp:
#include "MPU6050_tockn.h"
#include "Arduino.h"
MPU6050::MPU6050(TwoWire &w){
wire = &w;
accCoef = 0.02f;
gyroCoef = 0.98f;
}
MPU6050::MPU6050(TwoWire &w, float aC, float gC){
wire = &w;
accCoef = aC;
gyroCoef = gC;
}
void MPU6050::begin(int gyros, int accel, int addr){
int gyrosConfig;
int accelConfig;
mpuAddr = addr;
switch (gyros) {
case 250:
gyrosConfig = 0x00;
gyrosFactor = 131.0f;
break;
case 500:
gyrosConfig = 0x08;
gyrosFactor = 65.5f;
break;
case 1000:
gyrosConfig = 0x10;
gyrosFactor = 32.8f;
break;
case 2000:
gyrosConfig = 0x18;
gyrosFactor = 16.4f;
break;
default:
gyrosConfig = 0x08;
gyrosFactor = 65.5f;
break;
}
switch (accel) {
case 2:
accelConfig = 0x00;
accelFactor = 16384.0f;
gForce = 2.0f;
gForceInv = -2.0f;
break;
case 4:
accelConfig = 0x08;
accelFactor = 8192.0f;
gForce = 4.0f;
gForceInv = -4.0f;
break;
case 8:
accelConfig = 0x10;
accelFactor = 4096.0f;
gForce = 8.0f;
gForceInv = -8.0f;
break;
case 16:
accelConfig = 0x18;
accelFactor = 2048.0f;
gForce = 16.0f;
gForceInv = -16.0f;
break;
default:
accelConfig = 0x00;
accelFactor = 16384.0f;
gForce = 2.0f;
gForceInv = -2.0f;
break;
}
writeMPU6050(MPU6050_SMPLRT_DIV, 0x00);
writeMPU6050(MPU6050_CONFIG, 0x00);
writeMPU6050(MPU6050_GYRO_CONFIG, gyrosConfig);
writeMPU6050(MPU6050_ACCEL_CONFIG, accelConfig); // 0x18 = 16G | 0x00 = 2G
writeMPU6050(MPU6050_PWR_MGMT_1, 0x01);
this->update();
angleGyroX = this->getAccAngleX();
angleGyroY = this->getAccAngleY();
Serial.println("=================");
Serial.println(accCoef);
Serial.println(gyroCoef);
}
void MPU6050::writeMPU6050(byte reg, byte data){
wire->beginTransmission(mpuAddr);
wire->write(reg);
wire->write(data);
wire->endTransmission();
}
byte MPU6050::readMPU6050(byte reg) {
wire->beginTransmission(mpuAddr);
wire->write(reg);
wire->endTransmission(true);
wire->requestFrom((uint8_t)mpuAddr, (size_t)2/*length*/);
byte data = wire->read();
wire->read();
return data;
}
void MPU6050::setGyroOffsets(float x, float y, float z){
gyroXoffset = x;
gyroYoffset = y;
gyroZoffset = z;
}
void MPU6050::calcGyroOffsets(bool console){
float x = 0, y = 0, z = 0;
int16_t rx, ry, rz;
if(console){
Serial.println("calculate gyro offsets");
Serial.print("DO NOT MOVE A MPU6050");
}
for(int i = 0; i < 5000; i++){
if(console && i % 1000 == 0){
Serial.print(".");
}
wire->beginTransmission(mpuAddr);
wire->write(0x43); // from GYRO_XOUT_H to GYRO_ZOUT_L
wire->endTransmission(false);
wire->requestFrom((int)mpuAddr, 6, (int)true);
rx = wire->read() << 8 | wire->read(); // GYRO_XOUT_H | GYRO_XOUT_L
ry = wire->read() << 8 | wire->read();
rz = wire->read() << 8 | wire->read(); // GYRO_ZOUT_H | GYRO_ZOUT_L
x += ((float)rx) / gyrosFactor; // 500: 65.5
y += ((float)ry) / gyrosFactor;
z += ((float)rz) / gyrosFactor;
}
gyroXoffset = x / 5000;
gyroYoffset = y / 5000;
gyroZoffset = z / 5000;
if(console){
Serial.println("Done!!!");
Serial.print("X : ");Serial.println(gyroXoffset);
Serial.print("Y : ");Serial.println(gyroYoffset);
Serial.print("Z : ");Serial.println(gyroYoffset);
Serial.print("Program will start after 3 seconds");
delay(3000);
}
}
void MPU6050::update(){
wire->beginTransmission(mpuAddr);
wire->write(0x3B); // from ACCEL_XOUT_H to GYRO_ZOUT_L
wire->endTransmission(false);
wire->requestFrom((int)mpuAddr, 14, (int)true);
rawAccX = wire->read() << 8 | wire->read(); // ACCEL_XOUT_H | ACCEL_XOUT_L
rawAccY = wire->read() << 8 | wire->read();
rawAccZ = wire->read() << 8 | wire->read();
rawTemp = wire->read() << 8 | wire->read();
rawGyroX = wire->read() << 8 | wire->read();
rawGyroY = wire->read() << 8 | wire->read();
rawGyroZ = wire->read() << 8 | wire->read(); // GYRO_ZOUT_H | GYRO_ZOUT_L
temp = (rawTemp + 12412.0) / 340.0;
accX = ((float)rawAccX) / accelFactor; // 2G: 16384 | 16G: 2048
accY = ((float)rawAccY) / accelFactor;
accZ = ((float)rawAccZ) / accelFactor;
angleAccX = atan2(accY, accZ + abs(accX)) * 360 / gForce / PI; // 2.0
angleAccY = atan2(accX, accZ + abs(accY)) * 360 / gForceInv / PI; // -2.0
gyroX = ((float)rawGyroX) / gyrosFactor;
gyroY = ((float)rawGyroY) / gyrosFactor;
gyroZ = ((float)rawGyroZ) / gyrosFactor;
interval = millis() - preInterval;
gyroX -= gyroXoffset;
gyroY -= gyroYoffset;
gyroZ -= gyroZoffset;
angleGyroX += gyroX * (interval * 0.001);
angleGyroY += gyroY * (interval * 0.001);
angleGyroZ += gyroZ * (interval * 0.001);
preInterval = millis();
angleX = (gyroCoef * angleGyroX) + (accCoef * angleAccX);
angleY = (gyroCoef * angleGyroY) + (accCoef * angleAccY);
angleZ = angleGyroZ;
}
Hi, in you example sketches the angle X and Y do not update and are always zero. Only Z updates.
Hi
I edit the library for my project since I have 2 mpu6050 but the roll value after 180 decrease quickly till get to -180. I'm using this for calculation of link angle and this can cause some problems for me. I've found some other libraries that after 180, it just shows -180 and you can easily map it between 0 to 360. I couldn't fix that in your library
How can I get the sensor's data? I want to drive dc motor. What commands can I use?
hi, at first sorry for my bad English. I want to read MPU6050 and RTC at same time, i am using Wemos Lolin32. It work if separated, but MPU can't update if combine with RTC. The data in MPU is shown but change in very slow (not responsive). Data in RTC work normally. If i turn off rtc.now(), MPU working fine
Here the code :
`#include <Wire.h>
#include "RTClib.h"
#include <MPU6050_tockn.h>
#define I2C_SDA 17
#define I2C_SCL 16
TwoWire I2CMPU = TwoWire(0);
MPU6050 mpu6050(I2CMPU);
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup() {
Serial.begin(115200);
Wire.begin();
I2CMPU.begin(I2C_SDA, I2C_SCL, 100000);
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
I2CRTC.begin(I2C_SDA, I2C_SCL, 100000);
bool status;
status = rtc.begin(&I2CRTC);
// put your setup code here, to run once:
if (! status) {
Serial.println("Couldn't find RTC");
while (1);
}
rtc.adjust(DateTime(DATE, TIME));
// rtc.adjust(DateTime(2022,11,2,12,1 9,00));
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
Serial.println(String(daysOfTheWeek[now.dayOfTheWeek()]) + "," + String(now.hour(), DEC) + ":" + String(now.minute(), DEC) + ":" + String(now.second(), DEC));
mpu6050.update();
Serial.print("angleX : ");
Serial.print(mpu6050.getAngleX());
Serial.print("\tangleY : ");
Serial.print(mpu6050.getAngleY());
Serial.print("\tangleZ : ");
Serial.println(mpu6050.getAngleZ());
}`
I've written a function for the library that reduces current need.
It sets the MPU6050 in low power/sleep mode and disables the sensors.
You have still access to the registers.
void MPU6050::sleep(bool sleep)
{
byte b = readMPU6050(0x6B);
bitWrite(b, 6, sleep);
writeMPU6050(0x6B, b);
b = readMPU6050(0x6C);
for(uint8_t i = 0; i < 6; i ++)
{
bitWrite(b, i, sleep);
}
writeMPU6050(0x6C, b);
}
Hi,
MPU6050 temperature does not match the specific BMP280 temperature measurement.
The current calculation for the temperature is:
temp = (rawTemp + 12412.0) / 340.0;
But the datasheet (MPU-6000-Register-Map1.pdf) specifies:
Temperature in degrees C = (TEMP_OUT Register Value as a signed quantity)/340 + 36.53
36.53 * 340 = 12420020, so the error should be in the formula.
Using this calculation will give the right value:
temp = rawTemp / 340.0 + 36.53;
In this case, the small difference vs. BMP280 can be justified as the internal heat of the gyro.
Thank you.
The library is not working on the last version of the SDK (3.2).
The serial output is always:
=======================================================
temp : 36.51
accX : 0.00 accY : 0.00 accZ : 0.00
gyroX : 0.00 gyroY : 0.00 gyroZ : 0.00
accAngleX : 0.00 accAngleY : 0.00
gyroAngleX : 0.00 gyroAngleY : 0.00 gyroAngleZ : 0.00
angleX : 0.00 angleY : 0.00 angleZ : 0.00
=======================================================
I used the following example:
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
long timer = 0;
void setup()
{
Serial.begin(9600);
Wire.begin(33,32);
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
}
void loop()
{
mpu6050.update();
if(millis() - timer > 1000)
{
Serial.println("=======================================================");
Serial.print("temp : ");Serial.println(mpu6050.getTemp());
Serial.print("accX : ");Serial.print(mpu6050.getAccX());
Serial.print("\taccY : ");Serial.print(mpu6050.getAccY());
Serial.print("\taccZ : ");Serial.println(mpu6050.getAccZ());
Serial.print("gyroX : ");Serial.print(mpu6050.getGyroX());
Serial.print("\tgyroY : ");Serial.print(mpu6050.getGyroY());
Serial.print("\tgyroZ : ");Serial.println(mpu6050.getGyroZ());
Serial.print("accAngleX : ");Serial.print(mpu6050.getAccAngleX());
Serial.print("\taccAngleY : ");Serial.println(mpu6050.getAccAngleY());
Serial.print("gyroAngleX : ");Serial.print(mpu6050.getGyroAngleX());
Serial.print("\tgyroAngleY : ");Serial.print(mpu6050.getGyroAngleY());
Serial.print("\tgyroAngleZ : ");Serial.println(mpu6050.getGyroAngleZ());
Serial.print("angleX : ");Serial.print(mpu6050.getAngleX());
Serial.print("\tangleY : ");Serial.print(mpu6050.getAngleY());
Serial.print("\tangleZ : ");Serial.println(mpu6050.getAngleZ());
Serial.println("=======================================================\n");
timer = millis();
}
}
Only changed the I2C pins to SDA = 33 and SCL = 32.
What is going on?
mpu6050.update();
if(millis() - timer > 100){
avg_acc = sqrt(pow(mpu6050.getAccX(),2) + pow(mpu6050.getAccY(),2) +pow(mpu6050.getAccZ(), 2));
// Serial.print("avacc");
Serial.println(avg_acc);
timer = millis();
}
This code gives me the acceleration magnitude, and it works fine. But the issue s that sometimes when I raise the sensor above a certain level the magnitude goes down to 0 and gets stuck there. Can anyone help?
Please add new methods to be able to change the sensors sensitivity settings.
Information on MPU6050 sensitivity settings: https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/
Thanks
Why do you need to wait?
Is this line necessary?
`void MPU6050::calcGyroOffsets(bool console){
float x = 0, y = 0, z = 0;
int16_t rx, ry, rz;
delay(1000);`
I don't quite understand the role of this wait.
Hey guys,
I am trying to build stabilisation fins for an airplane. I want the rotationangle of the fins to be in a direct relation to the angle of the slipping aircraft. Therefore I need the calculated offsetpoints.
Can I read them or do I in this case have to use the setOffset function?
Hello,
great job, works nice. sorry if my issue is unrelated but I am trying to make a self-balancing robot and I am getting drifting on gyro angle like it is initially 0.01 degree and after a couple back and forth movements the gyro angle becomes 0.20 in stationary position.. is this fixable or totally my own issue?
thank you for your time!
note: in README.md exaple codes, the #include <MPU6050_tockn> does not include .h so I got issues while uploading. if you can change them to #include <MPU6050_tockn.h> would be better :)
works fine with standard Nano, but if I substitute a Nano "Every" it hangs at the "mpu6050.begin();" statement. I have tried it with the ATMEGA328 emulation on and with it off. Any suggestions?
Hello there,
I have tested the library for MPU6050 on three different sensors. I have faced a common issue where the angle given by getangleZ() kept on increasing after decimals which eventually generates a bigger difference. This is a kind of cumulative error.
After the clock of the arduin PWM pin is set to 32KHZ, the Angle will jump greatly, and the accumulation will occur. Is it affected by setting the wave clock frequency.
Hey, I just wanted to use your code for my esp8266, and I realised after looking at it that there is not Yaw Transfer ongoing. As far as I know, if you pitch your device and then yaw it the pitch will be not correct anymore.
You can see why in this video clip. I´ve already added a time mark.
https://youtu.be/4BoIE8YQwM8?t=606
Maybe I just was blind and didn´t see it and you´ve already added it.
Maybe if have the time I can change it myself
I'm using mpu6050.calcGyroOffsets(); on setup while it's resting on my table.
The acceleration I get (with the example code only) are:
accX : -1.50 accY : -1.19 accZ : -2.00
X and Y are weird because it's sitting still on my table, but they at least change.
the Z stays at -2.00 no matter how I wiggle it.
it's a gy521 connected with I2C to ESP32 dev board.
any ideas on how to debug it?
Calculating offsets gave me:
X : -370.80
Y : 1.26
Z : -5.39
if that somehow helps.
The method void MPU6050::calcGyroOffsets()
contains the following line:
rx = wire->read() << 8 | wire->read();
and similar lines for ry
and rz
. The same idiom is used in MPU6050::update()
.
This kind of expression should be avoided, as it does not guarantee the endianness of the retrieved data. This is because, in C++, the order of evaluation of the arguments of the |
operator is unspecified.
Presumably, the current version of gcc, when invoked with the options passed by the current version of the Arduino IDE, generates assembly that orders the bytes in the expected way. But this cannot be relied upon, and can very well depend on the compiler, compiler version, compiler options, or even surrounding code. This is the kind of software error that cannot be unveiled by testing, as the code can “just work” even if it is incorrect.
The simplest solution is to issue the calls to wire->read()
within separate statements. Unlike the arguments of the |
operator, separate statements have a well define order of evaluation:
rx = wire->read() << 8;
rx |= wire->read();
See also this post on the Arduino forum.
This Library is compatible with ESP32?.
Can you sendme a example with ESP32 and conections?
I am planning on using an MPU6050 on a robotic leg to get position information.
Your code is by far the simplest and easy to use that I have found for the MPU. However there are some issues I am having a few issues with outputs of the angle values.
This issue does not occur in the GetAllData example however the angleX value here does not seem to respond to changes in the X axis but instead changes with the Z axis.
I am not very advanced in my coding capabilities and don't really have any suggestions to fix this.
Hi.
I saw the power management MPU6050_PWR_MGMT_1 is fixed at 1: PLL X axis gyro.
It would be better to default it at 0: int 8MHz, and add the parametrization, so to give the possibility to enable the ext 32MHz external oscillator from a RTC.
Thanks.
Interface the MPU-6050 Inertial Measurement Unit Sensor with TivaC Launchpad using InterIntegrated Circuit (I2C) communication protocol by configuring its registers.
Display the three axis measurements of gyroscope and accelerometer on serial terminal of
PuTTY.
Ciao,
First o fall many thanks for your good work - Make handling of MPU6050 really easy ;o)
After Updating to new version of ESP32-HAL-I2C I realized that READ from MPU6050 did not work any more. (got only NULL values)
After research and comparision with different other includes like I2C-EEPROM, I2C-Display, etc. I realized that your access seems wrong designed and worked until now only by accident.
Real Bugfix is the wrong parameter in "endTransmission", further I added e rought "error detection/handling".
Simple Bugfix in MPU6050_tockn.cpp:
Change Line 71 in MPU6050::calcGyroOffsets from:
wire->endTransmission(false)
to:
byte rxStatus = wire->endTransmission(true);
if (rxStatus != 0) Serial.println("MPU6050::update EC: " + String(rxStatus));
Same Bugfix in MPU6050_tockn.cpp:
Change Line 105 in MPU6050::update from:
wire->endTransmission(false)
to:
byte rxStatus = wire->endTransmission(true);
if (rxStatus != 0) Serial.println("MPU6050::update EC: " + String(rxStatus));
Afterwards it worked really fine.... :o)
Kind regards
Michi
hello.
I want to read multiple mpu6050 at the same time with TCA9548A I2C Multiplexer.
How is this possible?
(on Arduino DUE)
As stated https://stackoverflow.com/a/29135050/2715780
in this answer, 3 '!' marks in a row causes the Mega 2560 bootloader to go into Monitor mode from which it can not finish programming. Therefore the code doesn't upload and causes the error
stk500v2_ReceiveMessage(): timeout
I manually located the .cpp file in my arduino library and changed "done!!!" to "done!", now it uploaded
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.