Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add teensy3 i2clib #19

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/SparkFun_SCD30_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 17 additions & 2 deletions src/SparkFun_SCD30_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@
#ifndef __SparkFun_SCD30_ARDUINO_LIBARARY_H__
#define __SparkFun_SCD30_ARDUINO_LIBARARY_H__

// 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 <i2c_t3.h> on your application instead of <Wire.h>

// #define USE_TEENSY3_I2C_LIB

#include "Arduino.h"
#ifdef USE_TEENSY3_I2C_LIB
#include <i2c_t3.h>
#else
#include <Wire.h>
#endif

//The default I2C address for the SCD30 is 0x61.
#define SCD30_ADDRESS 0x61
Expand All @@ -52,8 +61,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);

Expand Down Expand Up @@ -85,8 +97,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;
Expand Down