diff --git a/library.properties b/library.properties index d6a7e6b27..f6b504b19 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=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 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 DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, 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, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, 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, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306 +depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit AS5600 Library, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, 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, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, 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, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306 diff --git a/platformio.ini b/platformio.ini index 4d843bbc7..f2aabfa20 100644 --- a/platformio.ini +++ b/platformio.ini @@ -32,6 +32,7 @@ lib_deps = adafruit/ENS160 - Adafruit Fork adafruit/Adafruit SleepyDog Library adafruit/Adafruit AHTX0 + adafruit/Adafruit AS5600 Library adafruit/Adafruit BME280 Library adafruit/Adafruit BMP280 Library adafruit/Adafruit BMP3XX Library @@ -204,6 +205,7 @@ board_build.partitions = min_spiffs.csv extends = common:esp32 board = featheresp32-s2 build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2 -DBOARD_HAS_PSRAM +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -212,6 +214,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_feather_esp32s2_tft build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT -DBOARD_HAS_PSRAM +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -220,6 +223,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_feather_esp32s2_reversetft build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2_REVTFT -DBOARD_HAS_PSRAM +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -228,7 +232,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_feather_esp32s3 build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3 -DBOARD_HAS_PSRAM -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -247,7 +251,7 @@ build_type = debug debug_tool = esp-builtin board = adafruit_feather_esp32s3_tft build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3_TFT -DBOARD_HAS_PSRAM -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -256,7 +260,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_feather_esp32s3_reversetft build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3_REVTFT -DBOARD_HAS_PSRAM -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -265,7 +269,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_magtag29_esp32s2 build_flags = -DARDUINO_MAGTAG29_ESP32S2 -DBOARD_HAS_PSRAM -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -274,9 +278,12 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_metro_esp32s2 build_flags = -DARDUINO_METRO_ESP32S2 -DBOARD_HAS_PSRAM -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py +; debug_tool = jlink +; upload_protocol = jlink +; debug_init_break = tbreak WipperSnapper_I2C_Driver_MLX90632D ; Adafruit Metro ESP32-S3 [env:adafruit_metro_esp32s3] @@ -286,13 +293,14 @@ build_flags = -DARDUINO_METRO_ESP32S3 -DBOARD_HAS_PSRAM ;set partition to tinyuf2-partitions-16MB.csv as of idf 5.1 board_build.partitions = tinyuf2-partitions-16MB.csv extra_scripts = pre:rename_usb_config.py +debug_tool = jlink ; Adafruit Funhouse ESP32-S2 [env:adafruit_funhouse_esp32s2] extends = common:esp32 board = adafruit_funhouse_esp32s2 build_flags = -DARDUINO_FUNHOUSE -DBOARD_HAS_PSRAM -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -321,7 +329,7 @@ build_flags = -DLV_LOG_PRINTF=1 -DLV_LOG_COLOR=1 -DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -363,7 +371,7 @@ board_build.partitions = min_spiffs.csv extends = common:esp32 board = adafruit_qtpy_esp32s2 build_flags = -DARDUINO_ADAFRUIT_QTPY_ESP32S2 -DBOARD_HAS_PSRAM -;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py @@ -380,12 +388,14 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_qtpy_esp32s3_n4r2 build_flags = -DARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2 -DBOARD_HAS_PSRAM +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py [env:adafruit_qtpy_esp32s3_with_psram_debug] extends = common:esp32 board = adafruit_qtpy_esp32s3_n4r2 +;set partition to tinyuf2-partitions-4MB-noota.csv as of CPY 10 board_build.partitions = tinyuf2-partitions-4MB-noota.csv build_type = debug build_flags = diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 54cb8668a..8c58d8f9b 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -236,6 +236,16 @@ bool WipperSnapper_Component_I2C::initI2CDevice( } _ahtx0->configureDriver(msgDeviceInitReq); drivers.push_back(_ahtx0); + } else if (strcmp("as5600", msgDeviceInitReq->i2c_device_name) == 0) { + _as5600 = new WipperSnapper_I2C_Driver_AS5600(this->_i2c, i2cAddress); + if (!_as5600->begin()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize AS5600 chip!"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _as5600->configureDriver(msgDeviceInitReq); + drivers.push_back(_as5600); } else if (strcmp("bh1750", msgDeviceInitReq->i2c_device_name) == 0) { _bh1750 = new WipperSnapper_I2C_Driver_BH1750(this->_i2c, i2cAddress); if (!_bh1750->begin()) { diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index 9dc4c5cb7..75ff30d6a 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -22,6 +22,7 @@ #include "drivers/WipperSnapper_I2C_Driver.h" #include "drivers/WipperSnapper_I2C_Driver_ADT7410.h" #include "drivers/WipperSnapper_I2C_Driver_AHTX0.h" +#include "drivers/WipperSnapper_I2C_Driver_AS5600.h" #include "drivers/WipperSnapper_I2C_Driver_BH1750.h" #include "drivers/WipperSnapper_I2C_Driver_BME280.h" #include "drivers/WipperSnapper_I2C_Driver_BME680.h" @@ -158,6 +159,7 @@ class WipperSnapper_Component_I2C { _drivers_out; ///< List of i2c output drivers // Sensor driver objects WipperSnapper_I2C_Driver_AHTX0 *_ahtx0 = nullptr; + WipperSnapper_I2C_Driver_AS5600 *_as5600 = nullptr; WipperSnapper_I2C_Driver_D6T1A *_d6t1a = nullptr; WipperSnapper_I2C_Driver_DPS310 *_dps310 = nullptr; WipperSnapper_I2C_Driver_DS2484 *_ds2484 = nullptr; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_AS5600.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_AS5600.h new file mode 100644 index 000000000..3e51e8192 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_AS5600.h @@ -0,0 +1,155 @@ +/*! + * @file WipperSnapper_I2C_Driver_AS5600.h + * + * Device driver for the AS5600 Magnetic Angle sensor. + * + * 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 2024 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * + */ +#ifndef WipperSnapper_I2C_Driver_AS5600_H +#define WipperSnapper_I2C_Driver_AS5600_H + +#include + +#include "WipperSnapper_I2C_Driver.h" +#include "Wippersnapper.h" + +/**************************************************************************/ +/*! + @brief Class that provides a driver interface for a AS5600 sensor. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_AS5600 : public WipperSnapper_I2C_Driver { +public: + /*******************************************************************************/ + /*! + @brief Constructor for the AS5600 sensor. + @param i2c + The I2C interface. + @param sensorAddress + 7-bit device address. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_AS5600(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _as5600 = nullptr; + _angle = 0; + } + + /*******************************************************************************/ + /*! + @brief Destructor for an AS5600 sensor. + */ + /*******************************************************************************/ + ~WipperSnapper_I2C_Driver_AS5600() { + if (_as5600) { + delete _as5600; + _as5600 = nullptr; + } + } + + /*******************************************************************************/ + /*! + @brief Initializes the AS5600 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + _as5600 = new Adafruit_AS5600(); + if (!_as5600->begin((uint8_t)_sensorAddress, _i2c)) { + WS_DEBUG_PRINTLN("Failed to find AS5600 chip"); + return false; + } + + if (!configureSensor()) { + WS_DEBUG_PRINTLN("Failed to configure AS5600 sensor"); + return false; + } + return true; + } + + /*******************************************************************************/ + /*! + @brief Configures the AS5600 sensor. + @returns True if the sensor was configured successfully, False otherwise. + */ + /*******************************************************************************/ + bool configureSensor() { + return _as5600->enableWatchdog(false) && + // Normal (high) power mode + _as5600->setPowerMode(AS5600_POWER_MODE_NOM) && + // No Hysteresis + _as5600->setHysteresis(AS5600_HYSTERESIS_OFF) && + // analog output (0-VCC for 0-360 degrees) + _as5600->setOutputStage(AS5600_OUTPUT_STAGE_ANALOG_FULL) && + // setup filters + _as5600->setSlowFilter(AS5600_SLOW_FILTER_16X) && + _as5600->setFastFilterThresh(AS5600_FAST_FILTER_THRESH_SLOW_ONLY) && + // Reset position settings to defaults + _as5600->setZPosition(0) && _as5600->setMPosition(4095) && + _as5600->setMaxAngle(4095); + } + + /*******************************************************************************/ + /*! + @brief Reads the Angle sensor. + @returns True if the sensor was read successfully, False otherwise. + */ + /*******************************************************************************/ + bool readSensor() { + if (!_as5600->isMagnetDetected()) { + WS_DEBUG_PRINTLN("Magnet not detected!"); + return false; + } + + // Continuously read and display angle values + uint16_t rawAngle = _as5600->getRawAngle(); + uint16_t angle = _as5600->getAngle(); + + WS_DEBUG_PRINT("AS5600 Raw: "); + WS_DEBUG_PRINT(rawAngle); + WS_DEBUG_PRINT(" | Scaled: "); + WS_DEBUG_PRINT(angle); + + // Check status conditions + if (_as5600->isAGCminGainOverflow()) { + WS_DEBUG_PRINTLN(" | MH: magnet too strong"); + return false; + } + if (_as5600->isAGCmaxGainOverflow()) { + WS_DEBUG_PRINTLN(" | ML: magnet too weak"); + return false; + } + _angle = ((float)angle / 4095.0) * 360.0; + return true; + } + + /*******************************************************************************/ + /*! + @brief Reads the Angle sensor with short wait for data. + @param rawEvent + Angle sensor reading + @returns True if the sensor event was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventRaw(sensors_event_t *rawEvent) { + if (!readSensor()) { + return false; + } + rawEvent->data[0] = _angle; + return true; + } + +protected: + float _angle; ///< Current angle reading from the AS5600 sensor + Adafruit_AS5600 *_as5600; ///< Pointer to AS5600 sensor object +}; + +#endif // WipperSnapper_I2C_Driver_AS5600 \ No newline at end of file