diff --git a/library.properties b/library.properties index 89a1fb1f8..2bbcd1318 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper category=Communication url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino architectures=* -depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork +depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork diff --git a/platformio.ini b/platformio.ini index 85f7f4f73..7a1c1747c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -46,6 +46,7 @@ lib_deps = adafruit/Adafruit MPL115A2 adafruit/Adafruit MPRLS Library adafruit/Adafruit MS8607 + adafruit/Adafruit NAU7802 Library adafruit/Adafruit TMP117 adafruit/Adafruit TSL2591 Library adafruit/Adafruit_VL53L0X diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 9b0d3ffbb..74c93d6b5 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -386,6 +386,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice( _ltr329->configureDriver(msgDeviceInitReq); drivers.push_back(_ltr329); WS_DEBUG_PRINTLN("LTR329/303 Initialized Successfully!"); + } else if (strcmp("nau7802", msgDeviceInitReq->i2c_device_name) == 0) { + _nau7802 = new WipperSnapper_I2C_Driver_NAU7802(this->_i2c, i2cAddress); + if (!_nau7802->begin()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize NAU7802/303"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _nau7802->configureDriver(msgDeviceInitReq); + drivers.push_back(_nau7802); + WS_DEBUG_PRINTLN("NAU7802/303 Initialized Successfully!"); } else if (strcmp("sgp30", msgDeviceInitReq->i2c_device_name) == 0) { _sgp30 = new WipperSnapper_I2C_Driver_SGP30(this->_i2c, i2cAddress); if (!_sgp30->begin()) { diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index ef0c6c867..80c53794d 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -44,6 +44,7 @@ #include "drivers/WipperSnapper_I2C_Driver_MPL115A2.h" #include "drivers/WipperSnapper_I2C_Driver_MPRLS.h" #include "drivers/WipperSnapper_I2C_Driver_MS8607.h" +#include "drivers/WipperSnapper_I2C_Driver_NAU7802.h" #include "drivers/WipperSnapper_I2C_Driver_PCT2075.h" #include "drivers/WipperSnapper_I2C_Driver_PM25.h" #include "drivers/WipperSnapper_I2C_Driver_SCD30.h" @@ -132,6 +133,7 @@ class WipperSnapper_Component_I2C { WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr; WipperSnapper_I2C_Driver_MPRLS *_mprls = nullptr; WipperSnapper_I2C_Driver_MS8607 *_ms8607 = nullptr; + WipperSnapper_I2C_Driver_NAU7802 *_nau7802 = nullptr; WipperSnapper_I2C_Driver_TMP117 *_tmp117 = nullptr; WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr; WipperSnapper_I2C_Driver_VCNL4020 *_vcnl4020 = nullptr; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_NAU7802.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_NAU7802.h new file mode 100644 index 000000000..e71e7249c --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_NAU7802.h @@ -0,0 +1,102 @@ +/*! + * @file WipperSnapper_I2C_Driver_NAU7802.h + * + * Device driver for the NAU7802 24bit ADC / load cell breakout + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry for Adafruit Industries 2024 + * + * MIT license, all text here must be included in any redistribution. + * + */ + +#ifndef WipperSnapper_I2C_Driver_NAU7802_H +#define WipperSnapper_I2C_Driver_NAU7802_H + +#include "WipperSnapper_I2C_Driver.h" +#include + +/**************************************************************************/ +/*! + @brief Class that provides a driver interface for the NAU7802. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver { +public: + /*******************************************************************************/ + /*! + @brief Constructor for an NAU7802. + @param i2c + The I2C interface. + @param sensorAddress + 7-bit device address. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_NAU7802(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _i2c = i2c; + _sensorAddress = sensorAddress; + _nau7802 = new Adafruit_NAU7802(); + } + + /*******************************************************************************/ + /*! + @brief Destructor for an NAU7802. + */ + /*******************************************************************************/ + ~WipperSnapper_I2C_Driver_NAU7802() { _nau7802 = nullptr; } + + /*******************************************************************************/ + /*! + @brief Initializes the NAU7802 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + if (!_nau7802->begin(_i2c)) + return false; + + if (!_nau7802->setLDO(NAU7802_3V0)) { + WS_DEBUG_PRINTLN("Failed to set LDO to 3V0"); + } + + if (!_nau7802->setGain(NAU7802_GAIN_128)) { + WS_DEBUG_PRINTLN("Failed to set gain to 128"); + } + + if (!_nau7802->setRate(NAU7802_RATE_10SPS)) { + WS_DEBUG_PRINTLN("Failed to set sample rate to 10SPS"); + } + return true; + } + + /*******************************************************************************/ + /*! + @brief Gets the sensor's raw "force" value. + @param rawEvent + Pointer to an Adafruit_Sensor event. + @returns True if the reading was obtained successfully, False otherwise. + */ + /*******************************************************************************/ + bool getEventRaw(sensors_event_t *rawEvent) { + unsigned long start = millis(); + + // Wait for the sensor to be ready + while (!_nau7802->available()) { + if (millis() - start > 1000) { + WS_DEBUG_PRINTLN("NAU7802 not available"); + return false; + } + } + rawEvent->data[0] = (float)_nau7802->read(); + return true; + } + +protected: + Adafruit_NAU7802 *_nau7802 = nullptr; ///< NAU7802 object +}; + +#endif // WipperSnapper_I2C_Driver_NAU7802_H \ No newline at end of file