Skip to main content

A typed, register-accurate Python driver for the NAU7802 24-bit ADC load-cell amplifier.

Project description

NAU7802

A typed, register-accurate Python driver for the NAU7802 24-bit ADC load-cell amplifier.

This library provides a clean, Pythonic interface to the NAU7802 while preserving a 1:1 mapping to the hardware register model. Every register is represented as a strongly-typed dataclass, enabling safe configuration, introspection, and debugging without hiding how the device actually works.

Designed primarily for Linux SBCs (Raspberry Pi, etc.) using I²C via smbus2.

Features

  • ✅ Typed register definitions (dataclasses)
  • ✅ Full register-level control
  • ✅ Automatic byte packing/unpacking
  • ✅ Signed 24-bit and 32-bit register support
  • ✅ Minimal abstraction — hardware behavior stays visible
  • ✅ CLI utility for quick testing and debugging
  • ✅ Python 3.11+

Philosophy

Many ADC drivers hide device behavior behind opaque APIs.

nau7802 intentionally does the opposite:

The hardware register map is the API.

Each NAU7802 register is modeled explicitly:

  • Bitfields become dataclass fields
  • Reads return structured objects
  • Writes serialize automatically
  • Multi-byte registers behave naturally

This makes debugging with a datasheet straightforward — what you see in Python matches what exists on the chip.

Typed registers prevent invalid bit configurations and make register state inspectable during debugging.

Installation

pip install nau7802[cli]

Or from source:

git clone https://github.com/jbussdieker/nau7802
cd nau7802
pip install -e .

Requirements

  • Python ≥ 3.11
  • Linux I²C support enabled
  • smbus2

Example (Raspberry Pi):

sudo raspi-config
# Enable I2C

Quick Start

import smbus2
from nau7802 import NAU7802

bus = smbus2.SMBus(1)
adc = NAU7802(bus, addr=0x2A)

adc.power_on()
adc.set_gain(7)
adc.set_channel(1)

print(adc.ctrl2)
# REG_CTRL2(chs=False, crs=3, ...)

value = adc.adco.value
print(value)

Command Line Interface

A CLI tool is installed automatically:

nau7802 --help

Power On

nau7802 power_on

Initialize Device

nau7802 init --gain 7 --crs 3

Read ADC Value

nau7802 read

Dump All Registers

nau7802 dump

Example output:

NAU7802
  PU_CTRL      REG_PU_CTRL(...)
  CTRL1        REG_CTRL1(...)
  CTRL2        REG_CTRL2(...)
  ADCO         123456
  REV_ID       REG_REV_ID(...)

Register Model

Registers are first-class objects.

Example:

from nau7802.registers import REG_CTRL1

ctrl1 = REG_CTRL1.read(bus, 0x2A)

ctrl1.pga = 7
ctrl1.write(bus, 0x2A)

Benefits

  • No manual bit masking
  • Self-documenting configuration
  • Datasheet alignment
  • Safe serialization

Supported Register Types

Byte Registers

Automatically mapped bitfields:

REG_CTRL2(
    chs=False,
    crs=3,
)

Multi-Byte Registers

Signed values handled automatically:

  • 24-bit registers (ADCO, OCALx)
  • 32-bit registers (GCALx)

Sign extension is applied transparently.

Device API

Power Control

adc.power_on()
adc.standby()
adc.resume()

Configuration

adc.set_gain(7)
adc.set_crs(3)
adc.set_channel(1)

Reading Data

value = adc.adco.value

Architecture Overview

nau7802/
├── device/
│   ├── power.py        # power sequencing
│   └── setting.py      # configuration helpers
│
├── register/
│   ├── _base.py        # generic register interface
│   └── _byte.py        # 8-bit register specialization
│
└── registers/
    └── REG_*           # typed register definitions

Layering

  1. Register layer — serialization + hardware truth
  2. Device layer — safe operations & sequencing
  3. CLI layer — human interaction

Example: Debugging With Registers

print(adc.ctrl2)

Instead of raw hex values, you see structured state:

REG_CTRL2(chs=False, crs=3, cal_err=False, ...)

Development

Install dev dependencies:

pip install -e .[dev]

Type checking:

mypy src/

Status

Development Status: Pre-Alpha

The API may change as hardware behavior and ergonomics are refined.

Contributing

Issues and pull requests are welcome:

https://github.com/jbussdieker/nau7802/issues

License

MIT License

Author

Joshua B. Bussdieker jbussdieker@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nau7802-0.5.3.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nau7802-0.5.3-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file nau7802-0.5.3.tar.gz.

File metadata

  • Download URL: nau7802-0.5.3.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for nau7802-0.5.3.tar.gz
Algorithm Hash digest
SHA256 d0b180e8d10347c9f0dae659232189bb84fe854f4a1dfba5cc6da9c6f1656f82
MD5 28de96bbede8fbd507de9566cddd11ed
BLAKE2b-256 d41aacae617bc84ee2c441c8e701688d5182273e16be7b955873c2667ddb504f

See more details on using hashes here.

File details

Details for the file nau7802-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: nau7802-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for nau7802-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e3b18c088757a6aa1df5b1c3b28f00a42980c82c4bfc6c0e20142992b9a0cd48
MD5 900eef87449b19e9c612245e248430ad
BLAKE2b-256 0399018da93ac9da1ce10b5362ed30916c0e7a0e397a5802f4b2af2ffd76656d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page