I've got a device running with this architecture:
- BME280 Atmospheric Sensor
- SSD1306 128x64 OLED Screen
- arduino library: GitHub - sparkfun/SparkFun_I2C_GPS_Arduino_Library: Library for reading and controlling MT3333 and MT3339 based GPS modules over I2C.
- SparkFun GPS:
- device: SparkFun GPS Breakout - XA1110 (Qwiic) - GPS-14414 - SparkFun Electronics
- K30 CO2 Sensor:
- device: K30 10,000ppm CO2 Sensor | CO2Meter.com
- arduino library: GitHub - FirstCypress/K30_CO2_I2C_Arduino: Arduino library for connecting a K30 CO2 sensor module over I2C
The system essentially just pulls measurements from these sensors every few seconds (adjustable), and writes them to Serial, to the OLED, and to an SD Card. Everything works fine and essentially forever when the K30 is not attached.
Code is attached... I welcome all thoughts.
Problems happen only once I attach the K30...
Once the K30 is attached, the system will run fine, recording and displaying data from all sensors for an indeterminate amount of time before "freezing." The every-so-often freeze happens during a call to my write_to_screen() function. The system will freeze during the first wire->endTransmission() that is called in the screen library. Usually that while loop executes a few times, the screen updates, and the program continues, but not when it freezes.
I can unplug the K30's SDA wire and the system will resume, again, for some amount of time before it freezes again, when I can once again, unplug the K30 SDA wire and things will resume. Sometimes it will run for ten minutes. Other times for a few seconds/cycles. When it's running, data is pulling fine, and I2C seems to be working fine (I'm testing with a PicoScope). When I unplug the K30 SDA wire, the text on the screen updates and is garbled (sometimes wrong text in the wrong spot, and sometimes just messed up pixels) until I2C resumes working.
I've fixed 50 things in my code that I thought were the root cause here, but none of them have stopped this very specific freeze event. I thought it was a memory issue for a while. I chased that, and don't think that's the problem, but I'm not truthfully sure.
I have a button that cycles through screen layouts. I can induce the problem by pressing that a lot, although it's inconsistent. This leads me to believe there's some sort of overload / confusion / some-other-word-i-don't-know happening on the I2C bus. The system will freeze without me pressing the button too, so it's not the root cause.
Current App as TXT
PicoScope showing I2C when everything is running OK
PicoScope showing I2C when I2C is frozen low
carbon-cutter-v10.ino (22 KB)
carbon-cutter-v10.txt (22 KB)