From cb14b03daa9b34977a82587c87b12b18098533ef Mon Sep 17 00:00:00 2001 From: Francois <thiebolt@irit.fr> Date: Mon, 14 Mar 2022 01:26:43 +0100 Subject: [PATCH] added temperature support for SCD4x --- neosensor/libraries/boards/neosensor.h | 2 +- .../libraries/neocampus_drivers/MCP47X6.cpp | 12 +++++++--- .../libraries/neocampus_drivers/SCD4x.cpp | 24 +++++++++++++------ .../neocampus_modules/temperature.cpp | 16 +++++++++++++ .../libraries/neocampus_modules/temperature.h | 1 + 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/neosensor/libraries/boards/neosensor.h b/neosensor/libraries/boards/neosensor.h index 53719d7b..1605517e 100644 --- a/neosensor/libraries/boards/neosensor.h +++ b/neosensor/libraries/boards/neosensor.h @@ -42,7 +42,7 @@ */ #define BOARD_NAME "neOSensor" #define BOARD_REVISION 1.2 -#define BOARD_FWREV 211129 // Firmware revision <year><month><day> in 2 digits each +#define BOARD_FWREV 220314 // Firmware revision <year><month><day> in 2 digits each /* ############################################################################# diff --git a/neosensor/libraries/neocampus_drivers/MCP47X6.cpp b/neosensor/libraries/neocampus_drivers/MCP47X6.cpp index f3855949..67d50242 100644 --- a/neosensor/libraries/neocampus_drivers/MCP47X6.cpp +++ b/neosensor/libraries/neocampus_drivers/MCP47X6.cpp @@ -11,6 +11,8 @@ @section HISTORY + F.Thiebolt mar.22 added early detection support to distinguish with + newer SCD4x (0x62) chips 2017-July - F.Thiebolt Initial release */ @@ -52,10 +54,14 @@ boolean MCP47X6::is_device( uint8_t a ) { if( found == false ) return false; /* - * UNABLE to read MCP47X6 devices because of the specific I2C protocol that does not match - * those used at arduino :( + * WARNING: custom I2C reading !!! + * We'll ONLY read ONE byte (we don't care about the others) */ - // unable to read anything so we assume it is ok :s + #warning "Please confirm MCP47X06 eading code" + uint8_t status,_res; + _res = readList_ll( a, &status, 1); + if( _res!=1 ) return false; + if( (status & 0xE0) != (uint8_t)0xC0 ) return false; // ... okay return true; diff --git a/neosensor/libraries/neocampus_drivers/SCD4x.cpp b/neosensor/libraries/neocampus_drivers/SCD4x.cpp index 0fab7df9..a8bc977b 100644 --- a/neosensor/libraries/neocampus_drivers/SCD4x.cpp +++ b/neosensor/libraries/neocampus_drivers/SCD4x.cpp @@ -33,13 +33,22 @@ #include "SCD4x.h" +/* + * Definitions + * Time to obtain a new data point = _MAX_MEASURES * (5s or 30s) if periodic or low-power periodic) + */ +#define _MEASURES_INTERLEAVE_MS DEFL_READ_MSINTERVAL // delay between two measures in the 'measuring' state +#define _MAX_MEASURES 3 // max. number of measures during a single campaign +//#define _MAX_MEASURES DEFL_THRESHOLD_CPT // max. number of measures during a single campaign + + /**************************************************************************/ /*! @brief Declare list of possible I2C addrs */ /**************************************************************************/ -const uint8_t SCD4x::i2c_addrs[] = { 0x69 }; +const uint8_t SCD4x::i2c_addrs[] = { 0x62 }; /* [static] declare kind of units */ @@ -91,7 +100,8 @@ boolean SCD4x::is_device( uint8_t a ) { @brief Instantiates a new class */ /**************************************************************************/ -SCD4x::SCD4x( scd4xMeasureType_t kindness ) : generic_driver() { +SCD4x::SCD4x( scd4xMeasureType_t kindness ) : generic_driver( _MEASURES_INTERLEAVE_MS, + _MAX_MEASURES ) { _i2caddr = -1; _measureType = kindness; } @@ -323,7 +333,7 @@ bool SCD4x::_readSensor( void ) { // DEBUG hex_dump( (char*)buf, sizeof(buf) ); - break; + //break; // CO2 + CRC if( crc_check(buf, 2, buf[2]) ) { @@ -504,8 +514,8 @@ bool SCD4x::_check_identity( uint8_t a ) { } // DEBUG - hex_dump( (char*)buf, sizeof(buf) ); - break; + //hex_dump( (char*)buf, sizeof(buf) ); + //break; // check answer's CRC if( not crc_check(buf, 2, buf[2]) ) { @@ -526,8 +536,8 @@ bool SCD4x::_check_identity( uint8_t a ) { // DISPLAY retrieved serial number :) { - char tmp[48]; - snprintf(tmp, sizeof(tmp),"\n[SCD4x] serial number = 0x%02X%02X %02X%02X %02X%02X", + char tmp[64]; + snprintf(tmp, sizeof(tmp),"\n[SCD4x] detected serial number = 0x%02X%02X %02X%02X %02X%02X", buf[7],buf[6],buf[4],buf[3],buf[1],buf[0]); log_debug(tmp); log_flush(); } diff --git a/neosensor/libraries/neocampus_modules/temperature.cpp b/neosensor/libraries/neocampus_modules/temperature.cpp index 5d8e5df5..9d90dc54 100644 --- a/neosensor/libraries/neocampus_modules/temperature.cpp +++ b/neosensor/libraries/neocampus_modules/temperature.cpp @@ -9,6 +9,7 @@ * TODO: * - convert all 'frequency' parameters & define into 'cooldown' ones * --- + * F.Thiebolt mar.22 add support for SCD4x sensor * F.Thiebolt aug.20 switched to intelligent data sending vs timer based data sending * Thiebolt.F nov.20 previous 'force data as float' didn't work! we need to * use serialized(String(1.0,6)); // 1.000000 @@ -128,6 +129,21 @@ boolean temperature::add_sensor( uint8_t adr ) { _sensor_added=true; } } + // check for SHT3x + else if( SCD4x::is_device( adr ) == true ) { + SCD4x *cur_sensor = new SCD4x( scd4xMeasureType_t::temperature ); // because it features several sensors + if( cur_sensor->begin( adr ) != true ) { + log_debug(F("\n[temperature] ###ERROR at SCD4x startup ... removing instance ..."));log_flush(); + free(cur_sensor); + cur_sensor = NULL; + } + else { + cur_sensor->powerON(); // remember that device is shared across several modules + cur_sensor->powerOFF(); // remember that device is shared across several modules + _sensor[_sensors_count++] = cur_sensor; + _sensor_added=true; + } + } //else if( TCN75A::is_device( adr ) == true ) { // add check for additional device here diff --git a/neosensor/libraries/neocampus_modules/temperature.h b/neosensor/libraries/neocampus_modules/temperature.h index fedb708d..d2550d61 100644 --- a/neosensor/libraries/neocampus_modules/temperature.h +++ b/neosensor/libraries/neocampus_modules/temperature.h @@ -27,6 +27,7 @@ #include "Adafruit_MCP9808.h" #include "SHT2x.h" #include "SHT3x.h" +#include "SCD4x.h" // Sensirion SCD4X CO2 sensor including temp + hygro //#include "TCN75A.h" later maybe -- GitLab