From 99b3aec221579709dcd56ef2580976ff2c9810ce Mon Sep 17 00:00:00 2001 From: Jogi Date: Fri, 8 Jan 2021 12:56:40 +0100 Subject: [PATCH 1/2] Does not yet work --- src/SparkFun_SCD30_Arduino_Library.cpp | 4 ++++ src/SparkFun_SCD30_Arduino_Library.h | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/SparkFun_SCD30_Arduino_Library.cpp b/src/SparkFun_SCD30_Arduino_Library.cpp index 1284ae9..de738d6 100644 --- a/src/SparkFun_SCD30_Arduino_Library.cpp +++ b/src/SparkFun_SCD30_Arduino_Library.cpp @@ -33,7 +33,11 @@ SCD30::SCD30(void) } //Initialize the Serial port +#ifdef USE_TEENSY3_I2C_LIB +bool SCD30::begin(i2c_t3 &wirePort, bool autoCalibrate) +#else bool SCD30::begin(TwoWire &wirePort, bool autoCalibrate) +#endif { _i2cPort = &wirePort; //Grab which port the user wants us to use diff --git a/src/SparkFun_SCD30_Arduino_Library.h b/src/SparkFun_SCD30_Arduino_Library.h index 38b3b9f..71187bd 100644 --- a/src/SparkFun_SCD30_Arduino_Library.h +++ b/src/SparkFun_SCD30_Arduino_Library.h @@ -28,8 +28,14 @@ #ifndef __SparkFun_SCD30_ARDUINO_LIBARARY_H__ #define __SparkFun_SCD30_ARDUINO_LIBARARY_H__ +#define USE_TEENSY3_I2C_LIB + #include "Arduino.h" +#ifdef USE_TEENSY3_I2C_LIB +#include +#else #include +#endif //The default I2C address for the SCD30 is 0x61. #define SCD30_ADDRESS 0x61 @@ -52,8 +58,11 @@ class SCD30 SCD30(void); bool begin(bool autoCalibrate) { return begin(Wire, autoCalibrate); } +#ifdef USE_TEENSY3_I2C_LIB + bool begin(i2c_t3 &wirePort = Wire, bool autoCalibrate=true); //By default use Wire port +#else bool begin(TwoWire &wirePort = Wire, bool autoCalibrate=true); //By default use Wire port - +#endif bool beginMeasuring(uint16_t pressureOffset); bool beginMeasuring(void); @@ -85,8 +94,11 @@ class SCD30 private: //Variables +#ifdef USE_TEENSY3_I2C_LIB + i2c_t3 *_i2cPort; //The generic connection to user's chosen I2C hardware +#else TwoWire *_i2cPort; //The generic connection to user's chosen I2C hardware - +#endif //Global main datums float co2 = 0; float temperature = 0; From 7cddcb1e0cea2a7033dcbe7b93cfd75d1fe4f7f6 Mon Sep 17 00:00:00 2001 From: Jogi Date: Sat, 9 Jan 2021 01:21:21 +0100 Subject: [PATCH 2/2] Finally works, use #define to switch between Teensy >= 3.0 / LC and arduino --- src/SparkFun_SCD30_Arduino_Library.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SparkFun_SCD30_Arduino_Library.h b/src/SparkFun_SCD30_Arduino_Library.h index 71187bd..68b530f 100644 --- a/src/SparkFun_SCD30_Arduino_Library.h +++ b/src/SparkFun_SCD30_Arduino_Library.h @@ -28,7 +28,10 @@ #ifndef __SparkFun_SCD30_ARDUINO_LIBARARY_H__ #define __SparkFun_SCD30_ARDUINO_LIBARARY_H__ -#define USE_TEENSY3_I2C_LIB +// Uncomment the next #define if using an Teensy >= 3 or Teensy LC and want to use the dedicated I2C-Library for it +// Then you also have to include on your application instead of + +// #define USE_TEENSY3_I2C_LIB #include "Arduino.h" #ifdef USE_TEENSY3_I2C_LIB