How to connect external RTC to Razor IMU?

I am trying to connect a DS3231 RTC to Sparkfun Razor IMU and using Adafruit’s RTCLib.

However, the time is not shown correctly (I tried testing the RTC to an Arduino Nano and it shows the time correctly there). Plus, the sampling becomes really slow if I connect any I2C device to the I2C ports of the Razor IMU regardless whether the external device is being read or not.

Hi swapnilsayansaha,

According to the [GitHub Repository, the library should work with SAMD21-based microcontrollers so it is not a problem of compatibility with the microcontroller but I am afraid we cannot help troubleshoot using other companies’ products with SparkFun boards. If you can provide more information, specifically what exactly the RTC is printing out and any errors you are getting, we or other users here may be able to help but if not, you may need to troubleshoot this on your own by adding in debug statements to the code.](GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library)

Dear Mark,

Thank you. The RTC is printing out incorrect date and time and the IMU starts logging data very slowly once I connect the RTC to the IMU. The RTC however, does show the correct time on an Arduino.

Hi. I tried to connect the Razor to an RV-8803 (BOB-16281) board. The connections are correct and so far, I combined the setup code from Example2-Print_Time (from SparkFun_RV8803 library) to the MPU9250_Basic code (from SparkFunMPU9250-DMP library). My program seems to get stuck at the initialization code of the RTC. They have different I2C addresses right? What code should I change to get it started? Thanks.

The RV-8803 has an I2C address of 0x64 and the IMU on the razor has an address of 0x68 so both can coexist on the same I2C bus and be happy.

There’s probably something wrong in your code.

Yes, it is in the code. My IMU gets stuck at if(!rtc.begin()). I forgot to mention that I am also using SD.h, although I don’t think they have something to do with the problem, since it uses SPI. I also connected Serial1 Tx/Rx pins to a BlueSMiRF. Here is my code up to the setup():

#include <SD.h>
#include <SparkFunMPU9250-DMP.h>
#include <SparkFun_RV8803.h>

#define BTSerial Serial1
#define SD_CHIP_SELECT_PIN 38

MPU9250_DMP imu;
RV8803 rtc;

#define DEBUG_PRINT

bool toggleRead;              // To toggle read mode for MCU
String dataStr;               // String for storing data in SD

void setup() 
{
  BTSerial.begin(115200);
  
  while (!BTSerial); // wait for serial port to connect. Needed for native USB port only
  BTSerial.println("Serial initialized");

  if (!rtc.begin()) {
    BTSerial.println("Something went wrong, check wiring");
    // don't do anything more:
    while (1);
  }
  else {
    BTSerial.println("RTC online!");
    if (rtc.setToCompilerTime()) 
      BTSerial.println("Time updated to compile time.");
  }

  BTSerial.print("Initializing SD card...");

    // see if the card is present and can be initialized:
  if (!SD.begin(SD_CHIP_SELECT_PIN)) {
    BTSerial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  BTSerial.println("card initialized.");

  if (imu.begin() != INV_SUCCESS)
  {
    while (1)
    {
      BTSerial.println("Unable to communicate with MPU-9250");
      BTSerial.println("Check connections, and try again.");
      BTSerial.println();
      delay(5000);
    }
  }
  imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
  imu.setGyroFSR(2000); // Set gyro to 2000 dps
  imu.setAccelFSR(2); // Set accel to +/-2g
  imu.setLPF(5); // Set LPF corner frequency to 5Hz
  imu.setSampleRate(4); // Set sample rate to 4Hz
  imu.setCompassSampleRate(4); // Set mag rate to 10Hz
  
  toggleRead = false; 
}

I don’t think it’s the Serial1, where I display my output, because it works without the RTC codes. It’s not because of how I use SERCOM, right? Any ideas?

YellowDog:
The RV-8803 has an I2C address of 0x64 and the IMU on the razor has an address of 0x68 so both can coexist on the same I2C bus and be happy.

There’s probably something wrong in your code.

You're right. It was just a matter of adding **Wire.begin()** before the **if(!rtc.begin())**. My problem has been resolved. Thanks for confirming about the addresses.