I2C Connection Issues with ESP32 MCU and Notecard WiFi

Hello,

I’m working on my first project using Notecard, and I’m having some trouble with the I2C connection between the Notecard and my microcontroller. I’m using an ESP32-WROOM and the Notecarrier XS with the Notecard WiFi (v2.1) and a Starnote. The MCU and Notecarrier are powered separately through USB power, and the two are connected through the QWIIC port on the Notecarrier, as shown below.

I’ve tested the Notecard on it’s own by following the setup guide, and it has no issues, but the problem arises when I try to send messages from the MCU. Or rather, when the MCU tries to receive messages from the Notecard. The MCU is capable of sending a message to the Notecard, and that message is sent on to Notehub, but the MCU starts throwing errors in the serial log about not being able to receive from the Notecard:

[ERROR] serial-over-i2c|rx: unexpected protocol byte count {io}{i2c}
[WARN] i2c: reattempting to read Notecard response
[ERROR] serial-over-i2c|rx: unexpected protocol byte count {io}{i2c}
[WARN] i2c: reattempting to read Notecard response

These errors will repeat over and over, and sometimes the MCU will even resend the message to the Notecard. I have searched this forum for similar issues and have tried the solution from a similar problem of adding 10k pullup resistors to the SDA and SCL lines, but the result did not change. It may be worth noting that I have in rare cases seen the MCU send a few of these errors when first powering on, before sending a request and receiving the response just fine, but this is rare.

Also, for reference, the code I am using is shown below. If it’s important, my firmware and arduino libraries are up to date.

#include <Notecard.h>

#define usbSerial Serial

Notecard notecard;

void setup() {
  delay(2500);
  usbSerial.begin(115200);
  
  notecard.begin();
  notecard.setDebugOutputStream(usbSerial);

  delay(2500);

  J *req = notecard.newRequest("hub.sync");
  if (req != NULL) {
    notecard.sendRequest(req);
  }
}

void loop() {

}

I removed all of the sensors and other parts of the project and simplified the code as much as possible so I could isolate this issue. As I mentioned above, I’m able to send data to Notehub, so I’ve been able to upload sensor data despite this issue, but I can only do so once since the MCU will get stuck looping on these errors.

Any help would be appreciated.

1 Like

eddy_w,

Just wondering on the I2C lines you have pull-ups?

Warm Regards,
Rob Oudendijk

I had already tested with and without pullups before, but I just tried with them again just to make sure. I think in doing so I actually ended up figuring out the problem. In my testing just now, I found that the MCU could read the response just fine. However, I was able to replicate the error by unplugging / plugging back in the MCU and Notecard too many times. When I left them both off for enough time, they communicated fine again. Based on this, I think that my error was actually a combination of problems I had seen on this forum already:

  1. Pullup resistors: Since the Note-ESP and my ESP32 both have no pullup resistors on the I2C lines, I needed to add my own.
  2. Cold-boot: As I’ve seen elsewhere on the forum, the Notecard isn’t meant to be turned off and back on again so quickly and so many times in a row, so doing so caused some communication errors.
  3. Not enough delay between MCU startup, notecard.begin(), and notecard.sendRequest(): The errors were much more likely when I took out the delay at startup. Not 100% sure about the delay between begin() and sendRequest(), but in my previous testing when I was first seeing the error I had no delay here.

Anyways, thanks Rob for asking about the resistors, testing with them again helped me to figure the issue out (I think). I’ll come back and ask if I end up having any more issues.

Thank you,

eddy_w

2 Likes