-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I have a Adafruit NAU7802 connected via JST SH 4-pin cable into an Adafruit FT232H.
The FT232H has its i2c switched to ON.
The FT232H is connected to a windows 11 computer.
when i run the sample:
# SPDX-FileCopyrightText: 2023 Cedar Grove Maker Studios
# SPDX-License-Identifier: MIT
"""
nau7802_simpletest.py 2023-01-13 2.0.2 Cedar Grove Maker Studios
Instantiates two NAU7802 channels with default gain of 128 and sample
average count of 2.
"""
import time
import board
from cedargrove_nau7802 import NAU7802
# Instantiate 24-bit load sensor ADC; two channels, default gain of 128
nau7802 = NAU7802(board.I2C(), address=0x2A, active_channels=2)
def zero_channel():
"""Initiate internal calibration for current channel.Use when scale is started,
a new channel is selected, or to adjust for measurement drift. Remove weight
and tare from load cell before executing."""
print(
"channel {0:1d} calibrate.INTERNAL: {1:5s}".format(
nau7802.channel, str(nau7802.calibrate("INTERNAL"))
)
)
print(
"channel {0:1d} calibrate.OFFSET: {1:5s}".format(
nau7802.channel, str(nau7802.calibrate("OFFSET"))
)
)
print(f"...channel {nau7802.channel:1d} zeroed")
def read_raw_value(samples=2):
"""Read and average consecutive raw sample values. Return average raw value."""
sample_sum = 0
sample_count = samples
while sample_count > 0:
while not nau7802.available():
pass
sample_sum = sample_sum + nau7802.read()
sample_count -= 1
return int(sample_sum / samples)
# Instantiate and calibrate load cell inputs
print("*** Instantiate and calibrate load cells")
# Enable NAU7802 digital and analog power
enabled = nau7802.enable(True)
print("Digital and analog power enabled:", enabled)
print("REMOVE WEIGHTS FROM LOAD CELLS")
time.sleep(3)
nau7802.channel = 1
zero_channel() # Calibrate and zero channel
nau7802.channel = 2
zero_channel() # Calibrate and zero channel
print("READY")
### Main loop: Read load cells and display raw values
while True:
print("=====")
nau7802.channel = 1
value = read_raw_value()
print(f"channel {nau7802.channel:1.0f} raw value: {value:7.0f}")
nau7802.channel = 2
value = read_raw_value()
print(f"channel {nau7802.channel:1.0f} raw value: {value:7.0f}")
I get what appear to be random values being printed out. For example
*** Instantiate and calibrate load cells
Digital and analog power enabled: True
REMOVE WEIGHTS FROM LOAD CELLS
channel 1 calibrate.INTERNAL: True
channel 1 calibrate.OFFSET: True
...channel 1 zeroed
channel 2 calibrate.INTERNAL: True
channel 2 calibrate.OFFSET: True
...channel 2 zeroed
READY
=====
channel 1 raw value: -235
channel 2 raw value: 71
=====
channel 1 raw value: -144
channel 2 raw value: 176
=====
channel 1 raw value: -77
channel 2 raw value: 161
=====
channel 1 raw value: 7309
channel 2 raw value: 116
=====
channel 1 raw value: 2
channel 2 raw value: 135
=====
channel 1 raw value: -67
channel 2 raw value: 172
=====
channel 1 raw value: -21
channel 2 raw value: 29
=====
channel 1 raw value: 64
channel 2 raw value: 204
=====
channel 1 raw value: 27
channel 2 raw value: 74
=====
Just as a test, i disconnected the load cell wires from the NAU7802 and it still prints out random numbers.
Metadata
Metadata
Assignees
Labels
No labels