Adafruit NAU7802 Library example crashing Giga R1

I am currently trying to get a load cell working on an Arduino Giga R1.

I have the load cell hooked up to the Adafruit NAU7802 board which is then connected to the Giga R1 via i2c.

When I try to upload the NAU7802 example that comes with the library it complies correctly and uploads to the Giga. However, once uploaded the giga is unresponsive and the red light on the giga flashes indicating the sketch has caused the Mbed OS to crash as described here: https://support.arduino.cc/hc/en-us/articles/7991505987612-If-an-LED-on-GIGA-R1-WiFi-is-flashing-red

I have hooked up the NAU7802 and load cell up to a Unexpected Maker ProS3 and the example works as expected.

I am not sure where to even start to work out why the example does not work on the Giga. Does anyone have any pointers?

Any help will be much appreciated!

Thank you.

Hi @henryverity.

We need to know which library you are referring to.

Did you install the library using the Arduino IDE Library Manager? If so, tell us the exact name of the library, as it is shown in the Library Manager search listings.

Or did you download the library from the Internet? If so, provide a link to where you downloaded it from.

Hi,

Thank you for your reply.

The library was installed using the Arduino IDE Library Manager. Its full name is Adafruit NAU7802 Library and I have version 1.0.4 installed.

Thank you!

Hi @henryverity. I apologize for the slow response.

I was able to reproduce the crash.

Please try this:

  1. Upload this sketch to your GIGA R1 WiFi board:
    #include <Adafruit_NAU7802.h>
    
    Adafruit_NAU7802 nau;
    
    void setup() {
      Serial.begin(115200);
      while (!Serial) {}
      delay(500); // Make sure Serial Monitor has time to initialize.
      if (!nau.begin()) {
        Serial.println("Failed to find NAU7802");
      } else {
        Serial.println("Found NAU7802");
      }
    }
    
    void loop() {}
    
  2. Open the Arduino IDE Serial Monitor.

You should see one of the following messages in Serial Monitor:

  • "Failed to find NAU7802"
  • "Found NAU7802"

Which of the two did you see?


There is a bug in the example sketch:

If the call to nau.begin() returns false, the example sketch prints the helpful "Failed to find NAU7802" message to Serial Monitor. However, it then proceeds to run the rest of the program (including inappropriately printing "Found NAU7802"). The rest of the program can not work correctly if the initialization failed. It will crash the GIGA R1 WiFi under these conditions, which will cause the useful "Failed to find NAU7802" message to not be seen.

This was the cause of the crash when I ran the example on my GIGA R1 WiFi board. The failure of the initialization was expected in my case because I don't own an NAU7802 and thus don't have one connected to my board.

My hypothesis is that the initialization is failing for you (it might fail for a variety of reasons other than simply not having an NAU7802 connected), and this is the cause of the crash you encountered. The output of the sketch I provided in the instructions above will test my hypothesis.


I submitted a pull request to fix the bug in the example sketch:

However, that fix only improves the user experience in the case where the nau.begin() returns false. It doesn't do anything about whatever the root cause of the initialization failure might be.