tockn / MPU6050_tockn

Arduino library for easy communication with MPU6050
226 stars 89 forks source link

Mpu and RTC didn't work at same time #49

Open IkhwalSyukur opened 1 year ago

IkhwalSyukur commented 1 year ago

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

include "RTClib.h"

include

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());

}`