It's easy to use the NAU7802 with Python or CircuitPython, and the CedarGrove CircuitPython NAU7802 module. This module allows you to easily write Python code that reads the value from the NAU7802 ADC.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.

CircuitPython Microcontroller Wiring

First, wire up a NAU7802 to your board exactly as shown below. Here's an example of wiring a Feather M4 to the sensor with I2C using one of the handy STEMMA QT connectors:

  • Board 3V to ADC VIN (red wire)
  • Board GND to ADC GND (black wire)
  • Board SCL to ADC SCL (yellow wire)
  • Board SDA to ADC SDA (blue wire)

You can also use the standard 0.100" pitch headers to wire it up on a breadboard:

  • Board 3V to ADC VIN (red wire)
  • Board GND to ADC GND (black wire)
  • Board SCL to ADC SCL (yellow wire)
  • Board SDA to ADC SDA (blue wire)

Python Computer Wiring

Since there's dozens of Linux computers/boards you can use, below shows wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported

Here's the Raspberry Pi wired to the ADC using I2C and a STEMMA QT connector:

  • Pi 3V to ADC VIN (red wire)
  • Pi GND to ADC GND (black wire)
  • Pi SCL to ADC SCL (yellow wire)
  • Pi SDA to ADC SDA (blue wire)

Finally here is an example of how to wire up a Raspberry Pi to the ADC using a solderless breadboard:

  • Pi 3V to ADC VIN (red wire)
  • Pi GND to ADC GND (black wire)
  • Pi SCL to ADC SCL (yellow wire)
  • Pi SDA to ADC SDA (blue wire)

Python Installation of NAU7802 Library

You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!

Once that's done, from your command line run the following command:

  • git clone https://github.com/CedarGroveStudios/CircuitPython_NAU7802

This clones the CircuitPython_NAU7802 repository from GitHub. Then, you'll need to copy the cedargrove_nau7802.py library file to your Python packages folder running the following command:

  • sudo cp -r ~/CircuitPython_NAU7802/cedargrove_nau7802.py /usr/local/lib/python3.9/dist-packages

CircuitPython Usage

To use with CircuitPython, you need to first install the NAU7802 library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.

  1. First, download the latest CircuitPython Community Bundle
  2. Copy the cedargrove_nau7802.mpy file to the CIRCUITPY/lib folder.
  3. Copy the nau7802_simpletest.py file from the examples folder to the CIRCUITPY drive.
  4. Rename nau7802_simpletest.py to code.py.

Next, download the latest CircuitPython Library bundle. Copy the adafruit_bus_device and adafruit_register library folders to the CIRCUITPY/lib folder.

Your CIRCUITPY/lib folder should contain the following folders and file:

  • adafruit_bus_device/
  • adafruit_register/
  • cedargrove_nau7802.mpy

Python Usage

Once you have the library installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:

python3 code.py

Example Code

If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!

If running Python: The console output will appear wherever you are running Python.

Attach a strain gauge with four wires to the four terminal inputs. Now try applying force on the gauge to see the values change!

First you import the necessary modules and libraries. Then you instantiate the sensor on I2C.

Then you're ready to read data from the ADC, including the initial information printed to the serial console.

Finally, inside the loop, you check the value from the ADC.

The terminal inputs' raw value will print to the REPL. You'll see the number increase or decrease depending on the amount of force you apply to the strain gauge.

That's all there is to using the NAU7802 with CircuitPython!

This guide was first published on May 29, 2022. It was last updated on May 21, 2024.

This page (Python & CircuitPython) was last updated on Mar 08, 2024.

Text editor powered by tinymce.