Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
IkhwalSyukur opened this issue Nov 19, 2022 · 0 comments
Open

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

IkhwalSyukur opened this issue Nov 19, 2022 · 0 comments

Comments

@IkhwalSyukur
Copy link

IkhwalSyukur commented Nov 19, 2022

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

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant