Arduino Library messing with I2C even when not using I2C

I keep having to use version 1.5.4 because I keep having the same issue with later verions. I am using a notecard with UART. I have fuel gauges and a battery charger that are using I2C. Anytime I upgrade the library, I lose all I2C

I am initializing the library and notecard before I even start to initialize the I2C devices. I have also tried initializing the I2C devices first as well.

Can someone please let me know what I should be doing? From where I sit, it seems like the library shouldn’t even be touching I2C peripheral if I am not using I2C at all for it

Hi @dane!

Welcome to our forums, you’ve come to the right place.

That is unexpected. Can you please share as much information with me as you are willing and able?

  • What version of the Notecard firmware are you using?
  • Can you share your firmware, or at least the minimum amount of code to reproduce the issue?
  • Can you share a picture of your prototype hardware?

I’m here to help, and together we’ll get to the bottom of this for you.

Cheers,
Zak

Modem firmware I’ve tried has been 7.1 or 7.2 (most of the field devices are at ^7)
and the latest (using notecard firmware update) [9.1.1.17181]

Yes, here are the hardware specs

ESP32-S3-WROOM-1U-N16R8
I2C GPIO are GPIO15 and GPIO16 for SDA/SCL
GPIO17 and GPIO18 are the UART lines to the modem
SCL and SDA on notecard are NC

For the software side, the modem gets it’s own thread, and the I2C gets its own thread (since only the battery charger and fuel gauge are using I2C)

Here’s how I start the UART for the notecard

Serial1.begin(9600);
Serial1.setPins(MCU_MODEM_SERIAL_RX, MCU_MODEM_SERIAL_TX);
pinMode(MODEM_ATTENTION_PIN, INPUT);
attachInterrupt(MODEM_ATTENTION_PIN, modemAlertISR, RISING);

and here’s how I initialize the modem

notecard.begin(Serial1, 9600);

J *hubSetRequest = notecard.newRequest("hub.set");
    if (hubSetRequest) {
      JAddStringToObject(hubSetRequest, "product", PRODUCT_UID);
      JAddStringToObject(hubSetRequest, "sn", uniqueId);
      // JAddStringToObject(hubSetRequest, "mode", "continuous");
      JAddStringToObject(hubSetRequest, "mode", "off");
      JAddBoolToObject(hubSetRequest, "sync", true);

      if (!notecard.sendRequestWithRetry(hubSetRequest, 5)) {
          ESP_LOGE("Cellular Thread", "hubsetRequest Initialization Error.");
          return false;
      }
    }

J *auxModeSetRequest = notecard.newRequest("card.aux");

    if (auxModeSetRequest) {
        JAddStringToObject(auxModeSetRequest, "mode", "dfu");
        if (!notecard.sendRequest(auxModeSetRequest)) {
            ESP_LOGE("Cellular Thread", "Bad response during aux mode request");
        }
    } else {
        ESP_LOGE("Cellular Thread", "Couldn't create aux mode request");
    }

    ESP_LOGD("Cellular Thread", "Starting DFU Set");

    J *dfuSetRequest = notecard.newRequest("card.dfu");

    if (dfuSetRequest) {
        JAddStringToObject(dfuSetRequest, "name", "esp32");
        JAddBoolToObject(dfuSetRequest, "on", true);

        return notecard.sendRequest(dfuSetRequest);
    }

and here’s how I start the battery thread (after the modem thread has initialized the modem)

Wire.end();
Wire.setPins(SDA_PIN, SCL_PIN); 
Wire.begin(SDA_PIN, SCL_PIN); // Also tried just Wire.begin()

I am using the adafruit/Adafruit MAX1704 library for the fuel gauge and a custom one for the battery charger

if (!fuelGauge.begin(&Wire)) {
        ESP_LOGE(BATTERY_THREAD_TAG, "No MAX17048G found");
    }

The battery charger would get initialized similar to this


These devices have been in the field for a couple years on some of them, the issue has been around for a while, I just pin the library version to get by, but I would like to use the latest library

Thanks for your help

Nothing suspicious there. I’ll try to reproduce your issue.

I’ll report back my findings this afternoon.

~Zak

Hi @dane,

Unfortunately, I couldn’t reproduce your findings.

As you can see below, I modified the BME280 example Arduino application as a proof of concept:

/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface. The device's I2C address is either 0x76 or 0x77.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
  See the LICENSE file for details.
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Notecard.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

Notecard notecard;

void setup() {
    Serial.begin(9600);
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));
    
    notecard.begin(Serial1);

    J * req = notecard.newRequest("hub.set");
    JAddStringToObject(req, "product", "com.zakoverflow.test");
    notecard.sendRequest(req);

    unsigned status;
    
    // default settings
    status = bme.begin();  
    // You can also pass in a Wire library object like &Wire2
    // status = bme.begin(0x76, &Wire2)
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
    
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}


void loop() { 
    printValues();
    delay(delayTime);
}


void printValues() {
    J* req = notecard.newRequest("note.add");
    J* body = JAddObjectToObject(req, "body");

    float temp = bme.readTemperature();
    JAddNumberToObject(body, "temp", temp);
    Serial.print("Temperature = ");
    Serial.print(temp);
    Serial.println(" °C");

    float hPa = bme.readPressure() / 100.0F;
    JAddNumberToObject(body, "hPa", hPa);
    Serial.print("Pressure = ");
    Serial.print(hPa);
    Serial.println(" hPa");

    float alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
    JAddNumberToObject(body, "alt", alt);
    Serial.print("Approx. Altitude = ");
    Serial.print(alt);
    Serial.println(" m");

    float rh = bme.readHumidity();
    JAddNumberToObject(body, "rh", rh);
    Serial.print("Humidity = ");
    Serial.print(rh);
    Serial.println(" %");

    notecard.sendRequest(req);
    Serial.println();
}

I’m using note-arduino v1.6.6, and I’m connected to the Notecard over Serial1 and I’m talking to the BME280 over I2C. It’s reporting correct environmental readings to Notehub on a regular interval.

Can you create a minimal example to reproduce your issue and share it with me?

Thanks,
Zak