1

Architecture

System Setup

Wiring Diagram

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.

"Random" system freezes happen only once I attach the K30...

Once the K30 is attached to I2C, the system will run fine, recording and displaying data from all sensors (including the K30) 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 (see library here). Usually that while loop executes a few times, the screen updates, and the program continues, but not when it freezes.

write_to_screen() Function

Screens are cycled using the blue button that increments the screen_page var.

// display info on oled screen
//
// - many different displays available, cycled using button one
//
void write_to_screen() {
  Serial.println(F("  - writing to screen"));
  display.clearDisplay();
  display.setCursor(0,0);

  // default data display
  if(screen_page == 0) {
    display.setTextSize(2);
    // print co2
    display.print(F("CO2:"));
    display.println(co2);
    // resize text
    display.setTextSize(1);
    // print temp
    display.print(F("Temp: "));
    display.print(temperature_c);
    display.print(F("C "));
    display.print(temperature_f);
    display.println("F");
    // print humidity
    display.print(F("Humi: "));
    display.print(humidity);
    display.println(F("%"));
    // print pressure
    display.print(F("Pres: "));
    display.print(pressure);
    display.println(F(" hPa"));
    // print altitude
    display.print(F("Alti: "));
    display.print(gps.altitude.meters());
    display.println("m (GPS)"); // gps altitude is presumably more accurate/precise
    // print lat/lon
    display.print(F("LtLn: "));
    display.print(gps.location.lat());
    display.print(F(", "));
    display.println(gps.location.lng());
    // print time
    display.print("Time: ");
    display.print(gps_to_time());

  // k30
  } else if(screen_page == 1) {
    display.setTextSize(2);
    display.println(F("K30"));
    display.print(F("CO2:"));
    display.println(co2);
    display.setTextSize(1);
    display.println(F("\n\nAdd a time graph?"));

  // bme280
  } else if(screen_page == 2) {
    display.setTextSize(2);
    display.println(F("BME280"));
    display.setTextSize(1);
    // print temp
    display.print(F("Temp: "));
    display.print(temperature_c);
    display.print(F("C "));
    display.print(temperature_f);
    display.println(F("F" ));
    // print humidity
    display.print(F("Humi: "));
    display.print(humidity);
    display.println(F("%"));
    // print pressure
    display.print(F("Pres: "));
    display.print(pressure);
    display.println(F(" hPa"));
    // print pressure based Altitude
    display.print(F("Alti: "));
    display.print(altitude);
    display.println(F("m"));
    // print gps based altitude
    display.print(F("Alti: "));
    display.print(gps.altitude.meters());
    display.println(F("m (GPS)"));

  // gps
  } else if(screen_page == 3) {
    display.setTextSize(2);
    display.println(F("GPS"));
    display.setTextSize(1);
    if( is_gps_valid() ) {
      display.println(gps_to_datetime());
      // print sats
      display.print(F("Sats: "));
      display.print(gps.satellites.value());
      display.println(F(" (# of)"));
      // print lat/lon
      display.print(F("LtLn: "));
      display.print(gps.location.lat());
      display.print(F(", "));
      display.println(gps.location.lng());
      // print gps based altitude
      display.print(F("Alti: "));
      display.print(gps.altitude.meters());
      display.println(F("m"));
      // print pressure based altitude
      display.print(F("Alti: "));
      display.println(altitude);
      // print hdop
      display.print(F("HDOP: "));
      display.println(gps.hdop.value()/100.0);
    } else {
      display.println();
      display.println(F("Sats: 0 (NO SAT LOCK)"));
      display.println(F("LtLn:"));
      display.println(F("Alti:"));
      display.print(F("Alti: "));
      display.print(altitude);
      display.println(F("m (BME)"));
      display.println(F("HDOP:"));
    }

  // init statuses
  } else if(screen_page == 4) {
    display.setTextSize(1);
    display.print(F("Carbon Cutter "));
    display.print(ccversion);
    display.print(F("\nby Dan & Brian"));
    display.println(gps_to_datetime());

    // display init statuses
    // I2C and screen -- if we're reading data here, they are working
    //display.println("I2C Init:" + get_init_status(i2c_init) );
    //display.println("Screen Init:" + get_init_status(screen_init) );
    display.println(F("K30:    DEV"));
    display.print(F("BME280: "));
    display.println(get_init_status(bme280_init));
    display.print(F("GPS:    "));
    display.println(get_init_status(gps_init));
    display.print(F("SD:     "));
    display.println(get_init_status(sd_init));
    display.print(F("File:   "));
    display.println(get_init_status(file_init));
  }

  display.display();
  Serial.println(F("  - done writing to screen"));
}

Unplugging SDA Wire Unfreezes I2C

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.

System / I2C Working Fine

System / I2C Working Fine

System / I2C Frozen

System / I2C Frozen

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.

0 Answers0