Nice to meet you here. This is my first post here. I am building a prototype on Arduino UNO R3 with a DS3231 clock module and a GY-521(MPU6050) accelerator module. Here is the overall process and the current problem I have.
Here is the code
#include "I2Cdev.h"
#include "MPU6050.h"
#include <DS3231.h>
#include "Wire.h"
MPU6050 accelgyro;
DS3231 Clock;
int16_t ax, ay, az;
int16_t gx, gy, gz;
bool c = false;
void setup()
{
Wire.begin();
Serial.begin(115200);
accelgyro.initialize();
Clock.setSecond(50);
Clock.setMinute(59);
Clock.setHour(11);
Clock.setDoW(5);
Clock.setDate(31);
Clock.setMonth(5);
Clock.setYear(13);
}
void loop()
{
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print(ax); Serial.print('-');
Serial.print(ay); Serial.print('-');
Serial.print(az); Serial.print('-');
Serial.print(gx); Serial.print('-');
Serial.print(gy); Serial.print('-');
Serial.print(gz); Serial.print('\n');
Serial.print("20"); Serial.print(Clock.getYear(), DEC);
Serial.print('-'); Serial.print(Clock.getMonth(c), DEC);
Serial.print('-'); Serial.print(Clock.getDate(), DEC);
Serial.print(' '); Serial.print(Clock.getHour(c, c), DEC);
Serial.print(':'); Serial.print(Clock.getMinute(), DEC);
Serial.print(':'); Serial.println(Clock.getSecond());
delay(1000);
}
This is my first attempt, after the wires are connected, I found that accelerator shows all zero, while the clock shows totally wrong time like year 20149 (I am not sure human exist in 20149)
I found some post about this problem. It seems that the default I2C address for the MPU6050 is 0x68 and the DS3231 happened to be exactly the same address. This is really rare because there are about 120 address available. And I just have 2 of them with same address.
Then someone suggest that the MPU6050 default address can be changed to 0x69 by setting the AD0 to high. So I connect the AD0 to the VCC and I checked with I2C scanner. It worked because now the DS3231 is 0x68 and the MPU6050 is 0x69
But just as I thought that problem can be solved, I found that with the AD0 connected to VCC, the MPU6050 shows all zero on 6 axis.
I removed the DS3231 and stick to the MPU6050, trying to make sense of it. I found that if I attach AD0 to GND(or I just disconnect AD0 because it is set to GND as default), the 6 axis number are correct, and the address is 0x68. If I attach AD0 to VCC, the address will be 0x69 but all 6 axis show zero.
Here somes my question: If I want to use both these 2 module I have to set the MPU6050 to 0x69 but it will be all zero. Is there anything I did wrong? How can I solve this problem?
Thank you very much!