From 37816412d6e62e234c2701d62c726ffd33da3a89 Mon Sep 17 00:00:00 2001 From: Brent Rubell Date: Thu, 10 Mar 2022 15:49:35 -0500 Subject: [PATCH 1/6] add driver, ambient temp --- .../WipperSnapper_I2C_Driver_MCP9601.h | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h new file mode 100644 index 000000000..c2169b068 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h @@ -0,0 +1,88 @@ +/*! + * @file WipperSnapper_I2C_Driver_MCP9601.h + * + * Device driver for the MCP9601 Temperature 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) Brent Rubell 2022 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * + */ +#ifndef WipperSnapper_I2C_Driver_MCP9601_H +#define WipperSnapper_I2C_Driver_MCP9601_H + +#include "WipperSnapper_I2C_Driver.h" +#include + +/**************************************************************************/ +/*! + @brief Class that provides a driver interface for a MCP9601 sensor. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_MCP9601 : public WipperSnapper_I2C_Driver { +public: + /*******************************************************************************/ + /*! + @brief Constructor for a MCP9601 sensor. + @param _i2c + The I2C interface. + @param sensorAddress + The 7-bit I2C address of the sensor. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_MCP9601(TwoWire *_i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(_i2c, sensorAddress) { + // Called when a MCP9601 component is created + setI2CAddress(sensorAddress); // sets the driver's I2C address + _MCP9601 = new Adafruit_MCP9601(); + _isInitialized = _MCP9601->begin(); + + if (_isInitialized) { + _MCP9601->setADCresolution(MCP9600_ADCRESOLUTION_18); + _MCP9601->setThermocoupleType(MCP9600_TYPE_K); + _MCP9601->setFilterCoefficient(3); + _MCP9601->enable(true); + } + } + + /*******************************************************************************/ + /*! + @brief Destructor for an MCP9601 sensor. + */ + /*******************************************************************************/ + ~WipperSnapper_I2C_Driver_MCP9601() { + // Called when a MCP9601 component is deleted. + delete _MCP9601; + } + + /*******************************************************************************/ + /*! + @brief Gets the MCP9601's current temperature. + @param tempEvent + Pointer to an Adafruit_Sensor event. + @returns True if the temperature was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventAmbientTemperature(sensors_event_t *tempEvent) { + uint8_t status = mcp.getStatus(); + if (status & MCP9601_STATUS_OPENCIRCUIT) { + return; // don't continue, since there's no thermocouple + } + if (status & MCP9601_STATUS_SHORTCIRCUIT) { + return; // don't continue, since the sensor is not working + } + + tempEvent->temperature = mcp->readAmbient(); + return true; + } + +protected: + Adafruit_MCP9601 *_MCP9601; ///< Pointer to MCP9601 temperature sensor object +}; + +#endif // WipperSnapper_I2C_Driver_MCP9601 \ No newline at end of file From a222457b7d37b0cbf12a8538e5bccbc193385ce5 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 11 Mar 2022 11:48:59 -0500 Subject: [PATCH 2/6] add object_temp sensor handling code for mcp9601's thermocouple --- src/components/i2c/WipperSnapper_I2C.cpp | 40 +++++++ src/components/i2c/WipperSnapper_I2C.h | 2 + .../i2c/drivers/WipperSnapper_I2C_Driver.h | 103 +++++++++++++++++- .../WipperSnapper_I2C_Driver_MCP9601.h | 30 ++++- 4 files changed, 169 insertions(+), 6 deletions(-) diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 46d7abd0e..4b1544b01 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -255,6 +255,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice( _mcp9808->configureDriver(msgDeviceInitReq); drivers.push_back(_mcp9808); WS_DEBUG_PRINTLN("MCP9808 Initialized Successfully!"); + } else if (strcmp("mcp9601", msgDeviceInitReq->i2c_device_name) == 0) { + _mcp9601 = new WipperSnapper_I2C_Driver_MCP9601(this->_i2c, i2cAddress); + if (!_mcp9601->isInitialized()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize MCP9601!"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _mcp9601->configureDriver(msgDeviceInitReq); + drivers.push_back(_mcp9601); + WS_DEBUG_PRINTLN("MCP9601 Initialized Successfully!"); } else { WS_DEBUG_PRINTLN("ERROR: I2C device type not found!") _busStatusResponse = @@ -287,6 +298,10 @@ void WipperSnapper_Component_I2C::updateI2CDeviceProperties( drivers[i]->updateSensorAmbientTemperature( msgDeviceUpdateReq->i2c_device_properties[j].sensor_period); break; + case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE: + drivers[i]->updateSensorObjectTemp( + msgDeviceUpdateReq->i2c_device_properties[j].sensor_period); + break; case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_RELATIVE_HUMIDITY: drivers[i]->updateSensorRelativeHumidity( msgDeviceUpdateReq->i2c_device_properties[j].sensor_period); @@ -459,6 +474,31 @@ void WipperSnapper_Component_I2C::update() { } } + // AMBIENT_TEMPERATURE sensor + curTime = millis(); + if ((*iter)->sensorObjectTempPeriod() != 0L && + curTime - (*iter)->sensorObjectTempPeriodPrv() > + (*iter)->sensorObjectTempPeriod()) { + if ((*iter)->getEventObjectTemp(&event)) { + WS_DEBUG_PRINT("Sensor 0x"); + WS_DEBUG_PRINTHEX((*iter)->getI2CAddress()); + WS_DEBUG_PRINTLN(""); + WS_DEBUG_PRINT("\tTemperature: "); + WS_DEBUG_PRINT(event.temperature); + WS_DEBUG_PRINTLN(" degrees C"); + + // pack event data into msg + fillEventMessage( + &msgi2cResponse, event.temperature, + wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE); + + (*iter)->setSensorObjectTempPeriodPrv(curTime); + } else { + WS_DEBUG_PRINTLN( + "ERROR: Failed to get object temperature sensor reading!"); + } + } + // RELATIVE_HUMIDITY sensor curTime = millis(); if ((*iter)->sensorRelativeHumidityPeriod() != 0L && diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index cfd627923..d6b0e4572 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -23,6 +23,7 @@ #include "drivers/WipperSnapper_I2C_Driver_AHTX0.h" #include "drivers/WipperSnapper_I2C_Driver_BME280.h" #include "drivers/WipperSnapper_I2C_Driver_DPS310.h" +#include "drivers/WipperSnapper_I2C_Driver_MCP9601.h" #include "drivers/WipperSnapper_I2C_Driver_MCP9808.h" #include "drivers/WipperSnapper_I2C_Driver_SCD30.h" @@ -74,6 +75,7 @@ class WipperSnapper_Component_I2C { WipperSnapper_I2C_Driver_SCD30 *_scd30 = nullptr; WipperSnapper_I2C_Driver_BME280 *_bme280 = nullptr; WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr; + WipperSnapper_I2C_Driver_MCP9601 *_mcp9601 = nullptr; }; extern Wippersnapper WS; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h index 59d8e645c..f5268cb47 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver.h @@ -88,6 +88,10 @@ class WipperSnapper_I2C_Driver { setSensorAltitudePeriod( msgDeviceInitReq->i2c_device_properties[propertyIdx].sensor_period); break; + case wippersnapper_i2c_v1_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE: + enableSensorObjectTemp(); + setSensorObjectTempPeriod( + msgDeviceInitReq->i2c_device_properties[propertyIdx].sensor_period); default: break; } @@ -672,6 +676,97 @@ class WipperSnapper_I2C_Driver { setSensorAltitudePeriod(period); } + /**************************** SENSOR_TYPE: Object_Temperature + * ****************************/ + /*******************************************************************************/ + /*! + @brief Enables the device's object temperature sensor, if it exists. + */ + /*******************************************************************************/ + virtual void enableSensorObjectTemp(){}; + + /*******************************************************************************/ + /*! + @brief Disables the device's object temperature sensor, if it exists. + */ + /*******************************************************************************/ + virtual void disableSensorObjectTemp() { _objectTempSensorPeriod = 0.0L; } + + /*********************************************************************************/ + /*! + @brief Base implementation - Returns the object temperature sensor's + period, if set. + @returns Time when the object temperature sensor should be polled, in + seconds. + */ + /*********************************************************************************/ + virtual long sensorObjectTempPeriod() { return _objectTempSensorPeriod; } + + /*******************************************************************************/ + /*! + @brief Set the object temperature sensor's return frequency. + @param period + The time interval at which to return new data from the + object temperature sensor. + */ + /*******************************************************************************/ + virtual void setSensorObjectTempPeriod(float period) { + if (period == 0) + disableSensorObjectTemp(); + // Period is in seconds, cast it to long and convert it to milliseconds + _objectTempSensorPeriod = (long)period * 1000; + } + + /*********************************************************************************/ + /*! + @brief Base implementation - Returns the previous time interval at + which the object temperature sensor was queried last. + @returns Time when the object temperature sensor was last queried, + in seconds. + */ + /*********************************************************************************/ + virtual long sensorObjectTempPeriodPrv() { + return _objectTempSensorPeriodPrv; + } + + /*******************************************************************************/ + /*! + @brief Sets a timestamp for when the object temperature sensor + was queried. + @param period + The time when the object temperature sensor was queried last. + */ + /*******************************************************************************/ + virtual void setSensorObjectTempPeriodPrv(long period) { + _objectTempSensorPeriodPrv = period; + } + + /*******************************************************************************/ + /*! + @brief Base implementation - Reads a object temperature sensor and + converts the reading into the expected SI unit. + @param objectTempEvent + object temperature sensor reading, in meters. + @returns True if the sensor event was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + virtual bool getEventObjectTemp(sensors_event_t *objectTempEvent) { + return false; + } + + /*******************************************************************************/ + /*! + @brief Updates the properties of a object temperature sensor. + @param period + The time interval at which to return new data from the + object temperature sensor. + */ + /*******************************************************************************/ + virtual void updateSensorObjectTemp(float period) { + setSensorObjectTempPeriod(period); + } + protected: bool _isInitialized = false; ///< True if the I2C device was initialized ///< successfully, False otherwise. @@ -698,8 +793,12 @@ class WipperSnapper_I2C_Driver { ///< was last read. long _altitudeSensorPeriod = 0L; ///< The time period between reading the altitude sensor's value. - long _altitudeSensorPeriodPrv = 0L; ///< The time when the altitude sensor - ///< was last read. + long _altitudeSensorPeriodPrv = 0L; ///< The time when the altitude sensor + ///< was last read. + long _objectTempSensorPeriod = 0L; ///< The time period between reading the + ///< object temperature sensor's value. + long _objectTempSensorPeriodPrv = 0L; ///< The time when the object + ///< temperature sensor was last read. }; #endif // WipperSnapper_I2C_Driver_H \ No newline at end of file diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h index c2169b068..058ce42d4 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h @@ -69,15 +69,37 @@ class WipperSnapper_I2C_Driver_MCP9601 : public WipperSnapper_I2C_Driver { */ /*******************************************************************************/ bool getEventAmbientTemperature(sensors_event_t *tempEvent) { - uint8_t status = mcp.getStatus(); - if (status & MCP9601_STATUS_OPENCIRCUIT) { + uint8_t status = _MCP9601->getStatus(); + if (status & MCP9601_STATUS_OPENCIRCUIT) { return; // don't continue, since there's no thermocouple } - if (status & MCP9601_STATUS_SHORTCIRCUIT) { + if (status & MCP9601_STATUS_SHORTCIRCUIT) { return; // don't continue, since the sensor is not working } - tempEvent->temperature = mcp->readAmbient(); + tempEvent->temperature = _MCP9601->readAmbient(); + return true; + } + + /*******************************************************************************/ + /*! + @brief Gets the MCP9601's current object temperature (thermocouple). + @param objectTempEvent + Pointer to an Adafruit_Sensor event. + @returns True if the object temperature was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventObjectTemp(sensors_event_t *objectTempEvent) { + uint8_t status = _MCP9601->getStatus(); + if (status & MCP9601_STATUS_OPENCIRCUIT) { + return false; // don't continue, since there's no thermocouple + } + if (status & MCP9601_STATUS_SHORTCIRCUIT) { + return false; // don't continue, since the sensor is not working + } + + objectTempEvent->temperature = _MCP9601->readThermocouple(); return true; } From 4e887f34806f7b7afc9114e31d6ed32eef1f317c Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 11 Mar 2022 13:49:36 -0500 Subject: [PATCH 3/6] drop clock speed to 50khz for mcp960x to init? --- library.properties | 4 ++-- src/Wippersnapper.h | 2 +- src/components/i2c/WipperSnapper_I2C.cpp | 7 ++++--- .../i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/library.properties b/library.properties index cf9c870d9..1c9797ffb 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit WipperSnapper Beta -version=1.0.0-beta.25 +version=1.0.0-beta.27 author=Adafruit maintainer=Adafruit sentence=Arduino client for Adafruit.io WipperSnapper @@ -7,4 +7,4 @@ paragraph=Arduino client for Adafruit.io WipperSnapper category=Communication url=https://github.com/adafruit/Adafruit_IO_Arduino architectures=* -depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library +depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library diff --git a/src/Wippersnapper.h b/src/Wippersnapper.h index 1a5d056e3..751711b2f 100644 --- a/src/Wippersnapper.h +++ b/src/Wippersnapper.h @@ -62,7 +62,7 @@ #endif #define WS_VERSION \ - "1.0.0-beta.26" ///< WipperSnapper app. version (semver-formatted) + "1.0.0-beta.27" ///< WipperSnapper app. version (semver-formatted) // Reserved Adafruit IO MQTT topics #define TOPIC_IO_THROTTLE "/throttle" ///< Adafruit IO Throttle MQTT Topic diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 4b1544b01..150ac3149 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -65,13 +65,14 @@ WipperSnapper_Component_I2C::WipperSnapper_Component_I2C( // Initialize I2C bus #if defined(ARDUINO_ARCH_ESP32) _i2c = new TwoWire(msgInitRequest->i2c_port_number); - if (!_i2c->begin(msgInitRequest->i2c_pin_sda, - msgInitRequest->i2c_pin_scl)) { + if (!_i2c->begin((int)msgInitRequest->i2c_pin_sda, + (int)msgInitRequest->i2c_pin_scl)) { _isInit = false; // if the peripheral was configured incorrectly } else { _isInit = true; // if the peripheral was configured incorrectly } - _i2c->setClock(msgInitRequest->i2c_frequency); + //_i2c->setClock(msgInitRequest->i2c_frequency); + _i2c->setClock(50000); #elif defined(ARDUINO_ARCH_ESP8266) _i2c = new TwoWire(); _i2c->begin(msgInitRequest->i2c_pin_sda, msgInitRequest->i2c_pin_scl); diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h index 058ce42d4..b358caf02 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h @@ -39,7 +39,7 @@ class WipperSnapper_I2C_Driver_MCP9601 : public WipperSnapper_I2C_Driver { // Called when a MCP9601 component is created setI2CAddress(sensorAddress); // sets the driver's I2C address _MCP9601 = new Adafruit_MCP9601(); - _isInitialized = _MCP9601->begin(); + _isInitialized = _MCP9601->begin((uint8_t)sensorAddress); if (_isInitialized) { _MCP9601->setADCresolution(MCP9600_ADCRESOLUTION_18); @@ -71,10 +71,10 @@ class WipperSnapper_I2C_Driver_MCP9601 : public WipperSnapper_I2C_Driver { bool getEventAmbientTemperature(sensors_event_t *tempEvent) { uint8_t status = _MCP9601->getStatus(); if (status & MCP9601_STATUS_OPENCIRCUIT) { - return; // don't continue, since there's no thermocouple + return false; // don't continue, since there's no thermocouple } if (status & MCP9601_STATUS_SHORTCIRCUIT) { - return; // don't continue, since the sensor is not working + return false; // don't continue, since the sensor is not working } tempEvent->temperature = _MCP9601->readAmbient(); From 292f84efbbafbf1c0444fb53dd3f3ee57e9634a5 Mon Sep 17 00:00:00 2001 From: brentru Date: Fri, 11 Mar 2022 15:17:49 -0500 Subject: [PATCH 4/6] setclock --- src/components/i2c/WipperSnapper_I2C.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 150ac3149..85c21a0db 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -71,12 +71,11 @@ WipperSnapper_Component_I2C::WipperSnapper_Component_I2C( } else { _isInit = true; // if the peripheral was configured incorrectly } - //_i2c->setClock(msgInitRequest->i2c_frequency); _i2c->setClock(50000); #elif defined(ARDUINO_ARCH_ESP8266) _i2c = new TwoWire(); _i2c->begin(msgInitRequest->i2c_pin_sda, msgInitRequest->i2c_pin_scl); - _i2c->setClock(msgInitRequest->i2c_frequency); + _i2c->setClock(50000); _isInit = true; #else // SAMD From aad72d9ad14618885f30010cd1a5b0ef77a91c35 Mon Sep 17 00:00:00 2001 From: brentru Date: Mon, 14 Mar 2022 10:48:40 -0400 Subject: [PATCH 5/6] adhere to new refeactor --- src/components/i2c/WipperSnapper_I2C.cpp | 2 +- .../WipperSnapper_I2C_Driver_MCP9601.h | 43 +++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 72e3c28eb..f86bd6ba0 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -256,7 +256,7 @@ bool WipperSnapper_Component_I2C::initI2CDevice( WS_DEBUG_PRINTLN("MCP9808 Initialized Successfully!"); } else if (strcmp("mcp9601", msgDeviceInitReq->i2c_device_name) == 0) { _mcp9601 = new WipperSnapper_I2C_Driver_MCP9601(this->_i2c, i2cAddress); - if (!_mcp9601->isInitialized()) { + if (!_mcp9601->begin()) { WS_DEBUG_PRINTLN("ERROR: Failed to initialize MCP9601!"); _busStatusResponse = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h index b358caf02..594f19f5b 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h @@ -28,25 +28,16 @@ class WipperSnapper_I2C_Driver_MCP9601 : public WipperSnapper_I2C_Driver { /*******************************************************************************/ /*! @brief Constructor for a MCP9601 sensor. - @param _i2c + @param i2c The I2C interface. @param sensorAddress The 7-bit I2C address of the sensor. */ /*******************************************************************************/ - WipperSnapper_I2C_Driver_MCP9601(TwoWire *_i2c, uint16_t sensorAddress) - : WipperSnapper_I2C_Driver(_i2c, sensorAddress) { - // Called when a MCP9601 component is created - setI2CAddress(sensorAddress); // sets the driver's I2C address - _MCP9601 = new Adafruit_MCP9601(); - _isInitialized = _MCP9601->begin((uint8_t)sensorAddress); - - if (_isInitialized) { - _MCP9601->setADCresolution(MCP9600_ADCRESOLUTION_18); - _MCP9601->setThermocoupleType(MCP9600_TYPE_K); - _MCP9601->setFilterCoefficient(3); - _MCP9601->enable(true); - } + WipperSnapper_I2C_Driver_MCP9601(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _i2c = i2c; + _sensorAddress = sensorAddress; } /*******************************************************************************/ @@ -59,6 +50,30 @@ class WipperSnapper_I2C_Driver_MCP9601 : public WipperSnapper_I2C_Driver { delete _MCP9601; } + /*******************************************************************************/ + /*! + @brief Initializes the MCP9601 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + _MCP9601 = new Adafruit_MCP9601(); + if (!_MCP9601->begin((uint8_t)_sensorAddress)) + return false; + + // Configure MCP9601's settings + // Set resolution + _MCP9601->setADCresolution(MCP9600_ADCRESOLUTION_18); + // Set thermocouple type (NOTE: We do not have advanced settings in WS, set + // to 'K'-type for now) + _MCP9601->setThermocoupleType(MCP9600_TYPE_K); + // Set filter coefficient + _MCP9601->setFilterCoefficient(3); + // Enable sensor + _MCP9601->enable(true); + return true; + } + /*******************************************************************************/ /*! @brief Gets the MCP9601's current temperature. From be97647a67cd8d61f24595741e6a375179e1e086 Mon Sep 17 00:00:00 2001 From: brentru Date: Mon, 14 Mar 2022 11:13:25 -0400 Subject: [PATCH 6/6] change neopixel pin to match https://github.com/espressif/arduino-esp32/commit/ba8024c0d28d97cd02052bd178bf528fd2a3e576 --- src/Wippersnapper_Boards.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wippersnapper_Boards.h b/src/Wippersnapper_Boards.h index 8281d0601..bff8d78d8 100644 --- a/src/Wippersnapper_Boards.h +++ b/src/Wippersnapper_Boards.h @@ -89,7 +89,7 @@ #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) #define BOARD_ID "adafruit-huzzah-32-v2" #define USE_STATUS_NEOPIXEL -#define STATUS_NEOPIXEL_PIN NEOPIXEL_PIN +#define STATUS_NEOPIXEL_PIN PIN_NEOPIXEL #define STATUS_NEOPIXEL_NUM 1 #define USE_LITTLEFS #elif defined(ARDUINO_SAMD_NANO_33_IOT)