Can't Get Past setup() When Combining I2C Sensor Chain

I'm working on a project where I am logging sensor data from the following sensors/logger in an i2c qwiic chain:

I can't make it out of my setup() when I have my code aggregating all the readings. I sprinkled some Serial.println("test") in different places and always get some kind of partial repetition (E.g. TETETE.) However, without making any changes to the chain of sensors, all of the examples for the individual sensors work as expected. I've also verified that there are no conflicting addresses.

This is my first time working with I2C sensors- Am doing something incorrectly?

#include <Wire.h>                             // Include wire library for I2C
#include <SparkFun_GridEYE_Arduino_Library.h> // AMG8833 Grideye Thermopile
#include <Adafruit_LIS3DH.h>                  // Accelerometer sensor
#include <Adafruit_Sensor.h>    // Adafruit sensor library used for accelerometer(?)
#include <RTClib.h>   // PCF8523 RTC
#include <SparkFun_Qwiic_OpenLog_Arduino_Library.h>     // Openlog

OpenLog myLog;      // Create log instance
GridEYE grideye;    // Init grideye
Adafruit_LIS3DH lis = Adafruit_LIS3DH();    // init accelerometer
RTC_PCF8523 rtc;        // Init RTC

char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};    // Array to hold days of the week


void setup()
{
  Wire.begin();       // Init I2C
  delay(500);
  Serial.begin(9600);
  delay(500);
  grideye.begin();
  delay(500);
  Serial.print("TEST");
  rtc.start();
  lis.setRange(LIS3DH_RANGE_4_G);     // 2, 4 ,8, or 16 G
  lis.setDataRate(LIS3DH_DATARATE_50_HZ);      // 1, 10, 25, 50, 100, 200, 400 Hz
  myLog.begin();        //Open connection to OpenLog (no pun intended)

  /* Header Info*/
  DateTime now = rtc.now();
  myLog.print("-- Time --");
  myLog.println("Power-on timestamp =");
  myLog.print("/t");
  myLog.print(daysOfTheWeek[now.dayOfTheWeek()]);
  myLog.print(", ");
  myLog.print(now.month(), DEC);
  myLog.print("/");
  myLog.print(now.day(), DEC);
  myLog.print("/");
  myLog.print(now.hour(), DEC);
  myLog.print("/");
  myLog.print(now.minute(), DEC);
  myLog.print("/");
  myLog.print(now.second(), DEC);
  myLog.println("Unix Time=");
  myLog.print("/t");

  /* Accelerometer */
  myLog.println("-- Accelerometer--");
  myLog.println("Data Rate =");
  myLog.print("/t");
  switch (lis.getDataRate())
  {
    case LIS3DH_DATARATE_1_HZ:
      myLog.println("1 Hz");
      break;
    case LIS3DH_DATARATE_10_HZ:
      myLog.println("10 Hz");
      break;
    case LIS3DH_DATARATE_25_HZ:
      myLog.println("25 Hz");
      break;
    case LIS3DH_DATARATE_50_HZ:
      myLog.println("50 Hz");
      break;
    case LIS3DH_DATARATE_100_HZ:
      myLog.println("100 Hz");
      break;
    case LIS3DH_DATARATE_200_HZ:
      myLog.println("200 Hz");
      break;
    case LIS3DH_DATARATE_400_HZ:
      myLog.println("400 Hz");
      break;

    case LIS3DH_DATARATE_POWERDOWN:
      myLog.println("Powered Down");
      break;
    case LIS3DH_DATARATE_LOWPOWER_5KHZ:
      myLog.println("5 Khz Low Power");
      break;
    case LIS3DH_DATARATE_LOWPOWER_1K6HZ:
      myLog.println("16 Khz Low Power");
      break;
        
  }

Your sketch of Post-1 is not being compiled. I found the following defects:
1. It should be rtc.begin() in place of rtc.start().
2. There is no loop() function. I have placed an aribitrary loop() function -- sift it as needed.

#include <Wire.h>                             // Include wire library for I2C
#include <SparkFun_GridEYE_Arduino_Library.h> // AMG8833 Grideye Thermopile
#include <Adafruit_LIS3DH.h>                  // Accelerometer sensor
#include <Adafruit_Sensor.h>    // Adafruit sensor library used for accelerometer(?)
#include <RTClib.h>   // PCF8523 RTC
#include <SparkFun_Qwiic_OpenLog_Arduino_Library.h>     // Openlog

OpenLog myLog;      // Create log instance
GridEYE grideye;    // Init grideye
Adafruit_LIS3DH lis = Adafruit_LIS3DH();    // init accelerometer
RTC_PCF8523 rtc;        // Init RTC

char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};    // Array to hold days of the week


void setup()
{
  Wire.begin();       // Init I2C
  delay(500);
  Serial.begin(9600);
  delay(500);
  grideye.begin();
  delay(500);
  Serial.print("TEST");
  rtc.begin();//start();
  lis.setRange(LIS3DH_RANGE_4_G);     // 2, 4 ,8, or 16 G
  lis.setDataRate(LIS3DH_DATARATE_50_HZ);      // 1, 10, 25, 50, 100, 200, 400 Hz
  myLog.begin();        //Open connection to OpenLog (no pun intended)
}

void loop()
{
  /* Header Info*/
  DateTime now = rtc.now();
  myLog.print("-- Time --");
  myLog.println("Power-on timestamp =");
  myLog.print("/t");
  myLog.print(daysOfTheWeek[now.dayOfTheWeek()]);
  myLog.print(", ");
  myLog.print(now.month(), DEC);
  myLog.print("/");
  myLog.print(now.day(), DEC);
  myLog.print("/");
  myLog.print(now.hour(), DEC);
  myLog.print("/");
  myLog.print(now.minute(), DEC);
  myLog.print("/");
  myLog.print(now.second(), DEC);
  myLog.println("Unix Time=");
  myLog.print("/t");

  /* Accelerometer */
  myLog.println("-- Accelerometer--");
  myLog.println("Data Rate =");
  myLog.print("/t");
  switch (lis.getDataRate())
  {
    case LIS3DH_DATARATE_1_HZ:
      myLog.println("1 Hz");
      break;
    case LIS3DH_DATARATE_10_HZ:
      myLog.println("10 Hz");
      break;
    case LIS3DH_DATARATE_25_HZ:
      myLog.println("25 Hz");
      break;
    case LIS3DH_DATARATE_50_HZ:
      myLog.println("50 Hz");
      break;
    case LIS3DH_DATARATE_100_HZ:
      myLog.println("100 Hz");
      break;
    case LIS3DH_DATARATE_200_HZ:
      myLog.println("200 Hz");
      break;
    case LIS3DH_DATARATE_400_HZ:
      myLog.println("400 Hz");
      break;

    case LIS3DH_DATARATE_POWERDOWN:
      myLog.println("Powered Down");
      break;
    case LIS3DH_DATARATE_LOWPOWER_5KHZ:
      myLog.println("5 Khz Low Power");
      break;
    case LIS3DH_DATARATE_LOWPOWER_1K6HZ:
      myLog.println("16 Khz Low Power");
      break;
  }
}
2 Likes

Add a Serial.flush(); after each message. If the sketch crashes and resets, any characters still in the output buffer are lost. The .flush() waits for all characters to leave the output buffer.

1 Like

many of those .begin() function return a value indicating success/failure. You should print those values as well as your test statements.

1 Like

What does the compiler show as the memory usage for program storage space and dynamic memory?

I do not see lis.begin() anywhere.

That's my bad- I assumed because it wasn't making out of setup() that anything after didn't matter. Regardless, you were right about rtc.begin. Not sure how that got in there as I compared to the libraries many times- thank you!

There are a few more problems. If it is not reliable, you might want to read these notes:

  1. The Sparkfun Openlog is a ATmega328P running at 16MHz at 3.3V. It works, but not according to the datasheet.
  2. The Adafruit STEMMA QT is the same connector as the Sparkfun Qwiic. However, the Qwiic is only 3.3V and the STEMMA QT can be both (more or less). The voltage regulator of the Adafruit module will lower the voltage by about 250mV.
  3. Both the STEMMA QT and Qwiic are wrong. See page 54 of the standard I2C document UM10204.

[ADDED] I also noticed that the Sparkfun OpenLog has AREF connected to VCC. That is a fault. It causes a internal shortcut when the internal voltage reference is selected. The board is missing a diode from /RESET to VCC, that might result in a corrupted bootloader when the /RESET pins enters the High Voltage mode by a pulse at DTR.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.