![]() |
Qwiic_NAU7802_Py
2.0.0
Python for SFE Qwiic NAU7802
|
Public Member Functions | |
def | __init__ (self, address=None, i2c_driver=None) |
Constructor. More... | |
def | is_connected (self) |
Determines if this device is connected. More... | |
def | begin (self) |
Initializes this device with default parameters. More... | |
def | available (self) |
Gets whether data is available. More... | |
def | calibrate_afe (self) |
Calibrate analog front end. More... | |
def | begin_calibrate_afe (self) |
Begin asycnhronous calibration of the analog front end. More... | |
def | cal_afe_status (self) |
Returns calibration status of analog front end. More... | |
def | wait_for_calibrate_afe (self, timeout_ms=0) |
Wait for asynchronous AFE calibration to complete with optional timeout. More... | |
def | set_sample_rate (self, rate) |
Set sample rate in Hz. More... | |
def | set_channel (self, channel_number) |
Select between channel 1 and 2. More... | |
def | power_up (self) |
Power up digital and analog sections of scale. More... | |
def | power_down (self) |
Puts scale into low-power mode. More... | |
def | reset (self) |
Resets all registers to power off defaults. More... | |
def | set_ldo (self, ldo_value) |
Sets the onboard low-drop-out voltage regulator to a given value. More... | |
def | set_gain (self, gain_value) |
Sets the gain. More... | |
def | get_revision_code (self) |
Gets the revision code of this IC. More... | |
def | get_reading (self) |
Returns 24-bit reading. More... | |
def | get_average (self, average_amount, timeout_ms=1000) |
Return the average of a given number of readings. More... | |
def | calculate_zero_offset (self, average_amount) |
Calculates and stores zero offset measurement. More... | |
def | set_zero_offset (self, new_zero_offset) |
Sets zero offset mesaurement. More... | |
def | get_zero_offset (self) |
Gets the current zero offset. More... | |
def | calculate_calibration_factor (self, weight_on_scale, average_amount) |
Calculates and stores calibration factor. More... | |
def | set_calibration_factor (self, new_cal_factor) |
Sets calibration factor. More... | |
def | get_calibration_factor (self) |
Gets the current calibration factor. More... | |
def | get_weight (self, allow_negative_weights=False, samples_to_take=8) |
Gets the weight on the scale using the zero offset and calibration factor, so those must be set before using this. More... | |
def | set_int_polarity_high (self) |
Set interrupt pin to be high when data is ready (default) More... | |
def | set_int_polarity_low (self) |
Set interrupt pin to be low when data is ready. More... | |
def | set_bit (self, bit_number, register_address) |
Mask & set a given bit within a register. More... | |
def | clear_bit (self, bit_number, register_address) |
Mask & clear a given bit within a register. More... | |
def | get_bit (self, bit_number, register_address) |
Return a given bit within a register. More... | |
def | get_register (self, register_address) |
Get contents of a register. More... | |
def | set_register (self, register_address, value) |
Send a given value to be written to given address. More... | |
def | millis (self) |
Get the current time in milliseconds. More... | |
Public Attributes | |
address | |
Properties | |
connected = property(is_connected) | |
def qwiic_nau7802.QwiicNAU7802.__init__ | ( | self, | |
address = None , |
|||
i2c_driver = None |
|||
) |
Constructor.
int,optional | address: The I2C address to use for the device If not provided, the default address is used |
I2CDriver,optional | i2c_driver: An existing i2c driver object If not provided, a driver object is created |
def qwiic_nau7802.QwiicNAU7802.available | ( | self | ) |
Gets whether data is available.
True
if data is available, otherwise False
def qwiic_nau7802.QwiicNAU7802.begin | ( | self | ) |
Initializes this device with default parameters.
True
if successful, otherwise False
def qwiic_nau7802.QwiicNAU7802.begin_calibrate_afe | ( | self | ) |
Begin asycnhronous calibration of the analog front end.
Poll for completion with calAFEStatus() or wait with waitForCalibrateAFE()
def qwiic_nau7802.QwiicNAU7802.cal_afe_status | ( | self | ) |
Returns calibration status of analog front end.
def qwiic_nau7802.QwiicNAU7802.calculate_calibration_factor | ( | self, | |
weight_on_scale, | |||
average_amount | |||
) |
Calculates and stores calibration factor.
Must only be called after zero offset has been set, and when a known weight is on the scale.
float | weight_on_scale: Weight currently on the scale, without units |
int | average_amount: Number of measurements to average |
def qwiic_nau7802.QwiicNAU7802.calculate_zero_offset | ( | self, | |
average_amount | |||
) |
Calculates and stores zero offset measurement.
Must only be called when zero weight is on the scale
int | average_amount: Number of measurements to average |
def qwiic_nau7802.QwiicNAU7802.calibrate_afe | ( | self | ) |
Calibrate analog front end.
Takes approximatly 344ms to calibrate, but wait up to 1000ms. It is recommended to recalibrate whenever the gain, sample rate, or channel number is changed
True
if successful, otherwise False
def qwiic_nau7802.QwiicNAU7802.clear_bit | ( | self, | |
bit_number, | |||
register_address | |||
) |
Mask & clear a given bit within a register.
int | bit_number: Bit index to clear |
int | register_address: Register address |
def qwiic_nau7802.QwiicNAU7802.get_average | ( | self, | |
average_amount, | |||
timeout_ms = 1000 |
|||
) |
Return the average of a given number of readings.
Gives up after timeout
int | average_amount: Number of measurements to average |
int,optional | timeout_ms: Timeout in milliseconds, defaults to 1000 |
def qwiic_nau7802.QwiicNAU7802.get_bit | ( | self, | |
bit_number, | |||
register_address | |||
) |
Return a given bit within a register.
int | bit_number: Bit index to get |
int | register_address: Register address |
def qwiic_nau7802.QwiicNAU7802.get_calibration_factor | ( | self | ) |
Gets the current calibration factor.
def qwiic_nau7802.QwiicNAU7802.get_reading | ( | self | ) |
Returns 24-bit reading.
Assumes available() has been checked and returned True
def qwiic_nau7802.QwiicNAU7802.get_register | ( | self, | |
register_address | |||
) |
Get contents of a register.
int | register_address: Register address |
def qwiic_nau7802.QwiicNAU7802.get_revision_code | ( | self | ) |
Gets the revision code of this IC.
Should be 0x0F
def qwiic_nau7802.QwiicNAU7802.get_weight | ( | self, | |
allow_negative_weights = False , |
|||
samples_to_take = 8 |
|||
) |
Gets the weight on the scale using the zero offset and calibration factor, so those must be set before using this.
Uses a simple linear calculation following y=mx+b
bool,optional | allow_negative_weights: Whether negative weights are allowed, defaults to False |
int,optional | samples_to_take: Number of measurements to average, defaults to 8 |
def qwiic_nau7802.QwiicNAU7802.get_zero_offset | ( | self | ) |
Gets the current zero offset.
def qwiic_nau7802.QwiicNAU7802.is_connected | ( | self | ) |
Determines if this device is connected.
True
if connected, otherwise False
def qwiic_nau7802.QwiicNAU7802.millis | ( | self | ) |
Get the current time in milliseconds.
def qwiic_nau7802.QwiicNAU7802.power_down | ( | self | ) |
Puts scale into low-power mode.
def qwiic_nau7802.QwiicNAU7802.power_up | ( | self | ) |
Power up digital and analog sections of scale.
True
if successful, otherwise False
def qwiic_nau7802.QwiicNAU7802.reset | ( | self | ) |
Resets all registers to power off defaults.
def qwiic_nau7802.QwiicNAU7802.set_bit | ( | self, | |
bit_number, | |||
register_address | |||
) |
Mask & set a given bit within a register.
int | bit_number: Bit index to set |
int | register_address: Register address |
def qwiic_nau7802.QwiicNAU7802.set_calibration_factor | ( | self, | |
new_cal_factor | |||
) |
Sets calibration factor.
Useful if the calibration factor has already been calculated
float | new_cal_factor: Calibration factor |
def qwiic_nau7802.QwiicNAU7802.set_channel | ( | self, | |
channel_number | |||
) |
Select between channel 1 and 2.
int | channel_number: Channel number. Can be NAU7802_CHANNEL_1 or NAU7802_CHANNEL_2 |
def qwiic_nau7802.QwiicNAU7802.set_gain | ( | self, | |
gain_value | |||
) |
Sets the gain.
int | gain_value: Gain. Can be NAU7802_GAIN_1, NAU7802_GAIN_2, NAU7802_GAIN_4, NAU7802_GAIN_8, NAU7802_GAIN_16, NAU7802_GAIN_32, NAU7802_GAIN_64, or NAU7802_GAIN_128 |
def qwiic_nau7802.QwiicNAU7802.set_int_polarity_high | ( | self | ) |
Set interrupt pin to be high when data is ready (default)
def qwiic_nau7802.QwiicNAU7802.set_int_polarity_low | ( | self | ) |
Set interrupt pin to be low when data is ready.
def qwiic_nau7802.QwiicNAU7802.set_ldo | ( | self, | |
ldo_value | |||
) |
Sets the onboard low-drop-out voltage regulator to a given value.
int | ldo_value: LDO voltage. Can be NAU7802_LDO_2V4, NAU7802_LDO_2V7, NAU7802_LDO_3V0, NAU7802_LDO_3V3, NAU7802_LDO_3V6, NAU7802_LDO_3V9, NAU7802_LDO_4V2, or NAU7802_LDO_4V5 |
def qwiic_nau7802.QwiicNAU7802.set_register | ( | self, | |
register_address, | |||
value | |||
) |
Send a given value to be written to given address.
int | register_address: Register address |
int | value: Register value |
def qwiic_nau7802.QwiicNAU7802.set_sample_rate | ( | self, | |
rate | |||
) |
Set sample rate in Hz.
int | rate: Sample rate in Hz. Can be NAU7802_SPS_10, NAU7802_SPS_20, NAU7802_SPS_40, NAU7802_SPS_80, or NAU7802_SPS_320 |
def qwiic_nau7802.QwiicNAU7802.set_zero_offset | ( | self, | |
new_zero_offset | |||
) |
Sets zero offset mesaurement.
Useful if the zero offset has already been calculated
float | new_zero_offset: Zero offset |
def qwiic_nau7802.QwiicNAU7802.wait_for_calibrate_afe | ( | self, | |
timeout_ms = 0 |
|||
) |
Wait for asynchronous AFE calibration to complete with optional timeout.
If timeout is not specified (or set to 0), then wait indefinitely.
int,optional | timeout_ms: Timeout in ms, defaults to 0 |
True
if successful, otherwise False
qwiic_nau7802.QwiicNAU7802.address |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |