First Commit

This commit is contained in:
MindCreeper03
2025-02-27 19:31:50 +01:00
parent bcbb6aff9a
commit e490df1715
2470 changed files with 1479965 additions and 0 deletions

View File

@@ -0,0 +1,516 @@
/*!
* @file Adafruit_SCD30.cpp
*
* @mainpage Adafruit SCD30 CO2, Temperature, and Humidity sensor
*
* @section intro_sec Introduction
*
* I2C Driver for the Library for the SCD30 CO2, Temperature, and Humidity
* sensor
*
* This is a library for the Adafruit SCD30 breakout:
* https://www.adafruit.com/product/48xx
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
* @section dependencies Dependencies
* This library depends on the Adafruit BusIO library
*
* This library depends on the Adafruit Unified Sensor library
*
* @section author Author
*
* Bryan Siepert for Adafruit Industries
*
* @section license License
*
* BSD (see license.txt)
*
* @section HISTORY
*
* v1.0 - First release
*/
#include "Arduino.h"
#include <Wire.h>
#include "Adafruit_SCD30.h"
static uint8_t crc8(const uint8_t *data, int len);
/**
* @brief Construct a new Adafruit_SCD30::Adafruit_SCD30 object
*
*/
Adafruit_SCD30::Adafruit_SCD30(void) {}
/**
* @brief Destroy the Adafruit_SCD30::Adafruit_SCD30 object
*
*/
Adafruit_SCD30::~Adafruit_SCD30(void) {
if (temp_sensor)
delete temp_sensor;
if (humidity_sensor)
delete humidity_sensor;
}
/*!
* @brief Sets up the hardware and initializes I2C
* @param i2c_address
* The I2C address to be used.
* @param wire
* The Wire object to be used for I2C connections.
* @param sensor_id
* The unique ID to differentiate the sensors from others
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_SCD30::begin(uint8_t i2c_address, TwoWire *wire,
int32_t sensor_id) {
if (i2c_dev) {
delete i2c_dev; // remove old interface
}
i2c_dev = new Adafruit_I2CDevice(i2c_address, wire);
if (!i2c_dev->begin()) {
return false;
}
return _init(sensor_id);
}
// bool Adafruit_SCD30::begin_UART(void){}
/*! @brief Initializer for post i2c init
* @param sensor_id Optional unique ID for the sensor set
* @returns True if chip identified and initialized
*/
bool Adafruit_SCD30::_init(int32_t sensor_id) {
_sensorid_humidity = sensor_id;
_sensorid_temp = sensor_id + 1;
reset();
// first I2C xfer after reset can fail, double tapping seems to get by it
if (!startContinuousMeasurement()) {
if (!startContinuousMeasurement())
return false;
}
if (!setMeasurementInterval(2)) {
return false;
}
humidity_sensor = new Adafruit_SCD30_Humidity(this);
temp_sensor = new Adafruit_SCD30_Temp(this);
return true;
}
/**
* @brief Performs a software reset initializing registers to their power on
* state.
*
*/
void Adafruit_SCD30::reset(void) {
sendCommand(SCD30_CMD_SOFT_RESET);
delay(30);
}
/**
* @brief Ask the sensor if new data is ready to read
*
* @return true: data is available false: no new data available
*/
bool Adafruit_SCD30::dataReady(void) {
return (readRegister(SCD30_CMD_GET_DATA_READY) == 1);
}
/**
* @brief Set the amount of time between measurements
*
* @param interval The time between measurements in seconds. Must be from 2-1800
* seconds. The default value set on sensor initialization is 2 seconds.
*
* @return true: success false: failure
*/
bool Adafruit_SCD30::setMeasurementInterval(uint16_t interval) {
if ((interval < 2) || (interval > 1800)) {
return false;
}
return sendCommand(SCD30_CMD_SET_MEASUREMENT_INTERVAL, interval);
}
/**
* @brief Read the current amount of time between measurements
*
* @return uint16_t The current measurement interval in seconds.
*/
uint16_t Adafruit_SCD30::getMeasurementInterval(void) {
return readRegister(SCD30_CMD_SET_MEASUREMENT_INTERVAL);
}
/**
* @brief Gets the enable status of the SCD30's self calibration routine
*
* @return true: enabled false: disabled
*/
bool Adafruit_SCD30::selfCalibrationEnabled(void) {
return (readRegister(SCD30_CMD_AUTOMATIC_SELF_CALIBRATION) == 1);
}
/**
* @brief Enable or disable the SCD30's self calibration routine
*
* @param enabled true: enable false: disable
* @return true: success false: failure
*/
bool Adafruit_SCD30::selfCalibrationEnabled(bool enabled) {
return sendCommand(SCD30_CMD_AUTOMATIC_SELF_CALIBRATION, enabled);
}
/**
* @brief Tell the SCD30 to start taking measurements continuously
*
* @param pressure an optional pressure offset to correct for in millibar (mBar)
* @return true: succes false: failure
*/
bool Adafruit_SCD30::startContinuousMeasurement(uint16_t pressure) {
return sendCommand(SCD30_CMD_CONTINUOUS_MEASUREMENT, pressure);
}
/**
* @brief Read the current ambient pressure offset
*
* @return uint16_t current ambient pressure offset in millibar (mBar)
*/
uint16_t Adafruit_SCD30::getAmbientPressureOffset(void) {
return readRegister(SCD30_CMD_CONTINUOUS_MEASUREMENT);
}
/**
* @brief Set the altitude offset that the SCD30 should correct for
*
* **Note:** This value is saved to the SCD30's internal storage and is reloaded
* on sensor power up.
* @param altitude The altitude offset in meters above sea level.
* @return true: success false: failure
*/
bool Adafruit_SCD30::setAltitudeOffset(uint16_t altitude) {
return sendCommand(SCD30_CMD_SET_ALTITUDE_COMPENSATION, altitude);
}
/**
* @brief Get the current altitude offset
*
* @return uint16_t The current altitude offset value in meters above sea level.
*/
uint16_t Adafruit_SCD30::getAltitudeOffset(void) {
return readRegister(SCD30_CMD_SET_ALTITUDE_COMPENSATION);
}
/**
* @brief Set a temperature offset
*
* @param temp_offset The **positive** temperature offset to set in hundreths of
* a degree C ie:
*
* 1015 => 10.15 degrees C
* 31337 => 313.37 degrees C
*
*
* **Note:** This value is saved to the SCD30's internal storage and is reloaded
* on sensor power up.
* @return true: success false: failure
*/
bool Adafruit_SCD30::setTemperatureOffset(uint16_t temp_offset) {
return sendCommand(SCD30_CMD_SET_TEMPERATURE_OFFSET, temp_offset);
}
/**
* @brief Get the current temperature offset in hundreths of a degree C
*
* @return uint16_t the current temperature offset
*/
uint16_t Adafruit_SCD30::getTemperatureOffset(void) {
return readRegister(SCD30_CMD_SET_TEMPERATURE_OFFSET);
}
/**
* @brief Force the SCD30 to recalibrate with a given reference value
*
* @param reference The calibration reference value in ppm from
* 400-2000 ppm.
*
* **Note:** This value is saved to the SCD30's internal storage and is reloaded
* on sensor power up.
*
* **Setting a reference value and forcing recalibration will override any
* previous automatic self-calibration.**
* @return true: success false: failure
*/
bool Adafruit_SCD30::forceRecalibrationWithReference(uint16_t reference) {
if ((reference < 400) || (reference > 2000)) {
return false;
}
return sendCommand(SCD30_CMD_SET_FORCED_RECALIBRATION_REF, reference);
}
/**
* @brief Get the current forced recalibration reference value
*
* @return uint16_t The current reference value in ppm
*/
uint16_t Adafruit_SCD30::getForcedCalibrationReference(void) {
return readRegister(SCD30_CMD_SET_FORCED_RECALIBRATION_REF);
}
/**
* @brief Updates the measurement data for all sensors simultaneously
*
* @return true: success false: failure
*/
bool Adafruit_SCD30::read(void) {
uint8_t buffer[18];
buffer[0] = (SCD30_CMD_READ_MEASUREMENT >> 8) & 0xFF;
buffer[1] = SCD30_CMD_READ_MEASUREMENT & 0xFF;
if (!i2c_dev->write(buffer, 2)) {
return false;
}
delay(4); // delay between write and read specified by the datasheet
if (!i2c_dev->read(buffer, 18)) {
return false;
}
// loop through the bytes we read, 3 at a time for i=MSB, i+1=LSB, i+2=CRC
for (uint8_t i = 0; i < 18; i += 3) {
if (crc8(buffer + i, 2) != buffer[i + 2]) {
// we got a bad CRC, fail out
return false;
}
}
// CRCs are good, unpack floats
uint32_t co2 = 0, temp = 0, hum = 0;
co2 |= buffer[0];
co2 <<= 8;
co2 |= buffer[1];
co2 <<= 8;
co2 |= buffer[3];
co2 <<= 8;
co2 |= buffer[4];
temp |= buffer[6];
temp <<= 8;
temp |= buffer[7];
temp <<= 8;
temp |= buffer[9];
temp <<= 8;
temp |= buffer[10];
hum |= buffer[12];
hum <<= 8;
hum |= buffer[13];
hum <<= 8;
hum |= buffer[15];
hum <<= 8;
hum |= buffer[16];
memcpy(&CO2, &co2, sizeof(CO2));
memcpy(&temperature, &temp, sizeof(temperature));
memcpy(&relative_humidity, &hum, sizeof(relative_humidity));
return true;
}
bool Adafruit_SCD30::sendCommand(uint16_t command) {
uint8_t buffer[2];
buffer[0] = (command >> 8) & 0xFF;
buffer[1] = command & 0xFF;
return i2c_dev->write(buffer, sizeof(buffer));
}
bool Adafruit_SCD30::sendCommand(uint16_t command, uint16_t argument) {
uint8_t buffer[5];
buffer[0] = (command >> 8) & 0xFF;
buffer[1] = command & 0xFF;
buffer[2] = argument >> 8;
buffer[3] = argument & 0xFF;
buffer[4] = crc8(buffer + 2, 2);
return i2c_dev->write(buffer, sizeof(buffer));
}
uint16_t Adafruit_SCD30::readRegister(uint16_t reg_address) {
uint8_t buffer[2];
buffer[0] = (reg_address >> 8) & 0xFF;
buffer[1] = reg_address & 0xFF;
// the SCD30 really wants a stop before the read!
i2c_dev->write(buffer, 2);
delay(4); // delay between write and read specified by the datasheet
i2c_dev->read(buffer, 2);
return (uint16_t)(buffer[0] << 8 | (buffer[1] & 0xFF));
}
/*!
@brief Gets an Adafruit Unified Sensor object for the presure sensor
component
@return Adafruit_Sensor pointer to humidity sensor
*/
Adafruit_Sensor *Adafruit_SCD30::getHumiditySensor(void) {
return humidity_sensor;
}
/*!
@brief Gets an Adafruit Unified Sensor object for the temp sensor component
@return Adafruit_Sensor pointer to temperature sensor
*/
Adafruit_Sensor *Adafruit_SCD30::getTemperatureSensor(void) {
return temp_sensor;
}
/**************************************************************************/
/*!
@brief Gets the humidity sensor and temperature values as sensor events
@param humidity Sensor event object that will be populated with humidity
data
@param temp Sensor event object that will be populated with temp data
@returns True
*/
/**************************************************************************/
bool Adafruit_SCD30::getEvent(sensors_event_t *humidity,
sensors_event_t *temp) {
uint32_t t = millis();
if (!read()) {
return false;
}
// use helpers to fill in the events
fillHumidityEvent(humidity, t);
fillTempEvent(temp, t);
return true;
}
void Adafruit_SCD30::fillHumidityEvent(sensors_event_t *humidity,
uint32_t timestamp) {
memset(humidity, 0, sizeof(sensors_event_t));
humidity->version = sizeof(sensors_event_t);
humidity->sensor_id = _sensorid_humidity;
humidity->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
humidity->timestamp = timestamp;
humidity->relative_humidity = relative_humidity;
}
void Adafruit_SCD30::fillTempEvent(sensors_event_t *temp, uint32_t timestamp) {
memset(temp, 0, sizeof(sensors_event_t));
temp->version = sizeof(sensors_event_t);
temp->sensor_id = _sensorid_temp;
temp->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
temp->timestamp = timestamp;
temp->temperature = temperature;
}
/**************************************************************************/
/*!
@brief Gets the sensor_t data for the SCD30's humidity
*/
/**************************************************************************/
void Adafruit_SCD30_Humidity::getSensor(sensor_t *sensor) {
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));
/* Insert the sensor name in the fixed length char array */
strncpy(sensor->name, "SCD30_P", sizeof(sensor->name) - 1);
sensor->name[sizeof(sensor->name) - 1] = 0;
sensor->version = 1;
sensor->sensor_id = _sensorID;
sensor->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
sensor->min_delay = 0;
sensor->min_value = 260;
sensor->max_value = 1260;
// 4096 LSB = 1 hPa >> 1 LSB = 1/4096 hPa >> 1 LSB = 2.441e-4 hPa
sensor->resolution = 2.441e-4;
}
/**************************************************************************/
/*!
@brief Gets the humidity as a standard sensor event
@param event Sensor event object that will be populated
@returns True
*/
/**************************************************************************/
bool Adafruit_SCD30_Humidity::getEvent(sensors_event_t *event) {
_theSCD30->read();
_theSCD30->fillHumidityEvent(event, millis());
return true;
}
/**************************************************************************/
/*!
@brief Gets the sensor_t data for the SCD30's tenperature
*/
/**************************************************************************/
void Adafruit_SCD30_Temp::getSensor(sensor_t *sensor) {
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));
/* Insert the sensor name in the fixed length char array */
strncpy(sensor->name, "SCD30_T", sizeof(sensor->name) - 1);
sensor->name[sizeof(sensor->name) - 1] = 0;
sensor->version = 1;
sensor->sensor_id = _sensorID;
sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
sensor->min_delay = 0;
sensor->min_value = -30;
sensor->max_value = 105;
// 480 LSB = 1°C >> 1 LSB = 1/480°C >> 1 LSB = 0.00208 °C
sensor->resolution = 0.00208;
}
/**************************************************************************/
/*!
@brief Gets the temperature as a standard sensor event
@param event Sensor event object that will be populated
@returns True
*/
/**************************************************************************/
bool Adafruit_SCD30_Temp::getEvent(sensors_event_t *event) {
_theSCD30->read();
_theSCD30->fillTempEvent(event, millis());
return true;
}
/**
* Performs a CRC8 calculation on the supplied values.
*
* @param data Pointer to the data to use when calculating the CRC8.
* @param len The number of bytes in 'data'.
*
* @return The computed CRC8 value.
*/
static uint8_t crc8(const uint8_t *data, int len) {
/*
*
* CRC-8 formula from page 14 of SHT spec pdf
*
* Test data 0xBE, 0xEF should yield 0x92
*
* Initialization data 0xFF
* Polynomial 0x31 (x8 + x5 +x4 +1)
* Final XOR 0x00
*/
const uint8_t POLYNOMIAL(0x31);
uint8_t crc(0xFF);
for (int j = len; j; --j) {
crc ^= *data++;
for (int i = 8; i; --i) {
crc = (crc & 0x80) ? (crc << 1) ^ POLYNOMIAL : (crc << 1);
}
}
return crc;
}

View File

@@ -0,0 +1,162 @@
/*!
* @file Adafruit_SCD30.h
*
* I2C Driver for the Adafruit SCD30 CO2, Temperature, and Humidity sensor
* This is a library is written to work with the Adafruit SCD30 breakout:
* https://www.adafruit.com/products/48xx
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
*
* license (see license.txt)
*/
#ifndef _ADAFRUIT_SCD30_H
#define _ADAFRUIT_SCD30_H
#include "Arduino.h"
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#define SCD30_I2CADDR_DEFAULT 0x61 ///< SCD30 default i2c address
#define SCD30_CHIP_ID 0x60 ///< SCD30 default device id from WHOAMI
#define SCD30_WHOAMI 0xD100 ///< Chip ID register
#define SCD30_CMD_READ_MEASUREMENT 0x0300 ///< Main data register
#define SCD30_CMD_CONTINUOUS_MEASUREMENT \
0x0010 ///< Command to start continuous measurement
#define SCD30_CMD_STOP_MEASUREMENTS 0x0104 ///< Command to stop measurements
#define SCD30_CMD_SET_MEASUREMENT_INTERVAL \
0x4600 ///< Command to set measurement interval
#define SCD30_CMD_GET_DATA_READY 0x0202 ///< Data ready reg
#define SCD30_CMD_AUTOMATIC_SELF_CALIBRATION \
0x5306 ///< enables/disables auto calibration
#define SCD30_CMD_SET_FORCED_RECALIBRATION_REF \
0x5204 ///< Forces calibration with given value
#define SCD30_CMD_SET_TEMPERATURE_OFFSET 0x5403 ///< Specifies the temp offset
#define SCD30_CMD_SET_ALTITUDE_COMPENSATION \
0x5102 ///< Specifies altitude offset
#define SCD30_CMD_SOFT_RESET 0xD304 ///< Soft reset!
#define SCD30_CMD_READ_REVISION 0xD100 ///< Firmware revision number
///////////////////////////////////////////////////////////////
/**
* @brief
*
* Allowed values for `setDataRate`.
*/
typedef enum {
SCD30_RATE_ONE_SHOT,
SCD30_RATE_1_HZ,
SCD30_RATE_7_HZ,
SCD30_RATE_12_5_HZ,
SCD30_RATE_25_HZ,
} scd30_rate_t;
class Adafruit_SCD30;
/** Adafruit Unified Sensor interface for temperature component of SCD30 */
class Adafruit_SCD30_Temp : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the temp sensor
@param parent A pointer to the SCD30 class */
Adafruit_SCD30_Temp(Adafruit_SCD30 *parent) { _theSCD30 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);
private:
int _sensorID = 0xC02;
Adafruit_SCD30 *_theSCD30 = NULL;
};
/** Adafruit Unified Sensor interface for the humidity sensor component of SCD30
*/
class Adafruit_SCD30_Humidity : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the humidity sensor
@param parent A pointer to the SCD30 class */
Adafruit_SCD30_Humidity(Adafruit_SCD30 *parent) { _theSCD30 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);
private:
int _sensorID = 0xC02 + 1;
Adafruit_SCD30 *_theSCD30 = NULL;
};
/*!
* @brief Class that stores state and functions for interacting with
* the SCD30 CO2, Temperature, and Humidity sensor
*/
class Adafruit_SCD30 {
public:
Adafruit_SCD30();
~Adafruit_SCD30();
bool begin(uint8_t i2c_addr = SCD30_I2CADDR_DEFAULT, TwoWire *wire = &Wire,
int32_t sensor_id = 0);
void reset(void);
bool dataReady(void);
bool getEvent(sensors_event_t *humidity, sensors_event_t *temp);
bool read(void);
uint16_t getMeasurementInterval(void);
bool setMeasurementInterval(uint16_t interval);
bool selfCalibrationEnabled(void);
bool selfCalibrationEnabled(bool);
bool startContinuousMeasurement(uint16_t pressure = 0);
uint16_t getAmbientPressureOffset(void);
bool setAltitudeOffset(uint16_t altitude);
uint16_t getAltitudeOffset(void);
bool setTemperatureOffset(uint16_t temp_offset);
uint16_t getTemperatureOffset(void);
bool forceRecalibrationWithReference(uint16_t reference);
uint16_t getForcedCalibrationReference(void);
Adafruit_Sensor *getTemperatureSensor(void);
Adafruit_Sensor *getHumiditySensor(void);
float CO2, ///< The most recent CO2 reading
temperature, ///< The most recent temperature reading
relative_humidity; ///< The most recent relative_humidity reading
;
protected:
virtual bool _init(int32_t sensor_id);
uint16_t _sensorid_humidity, ///< ID number for humidity
_sensorid_temp; ///< ID number for temperature
Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface
Adafruit_SCD30_Temp *temp_sensor = NULL; ///< Temp sensor data object
Adafruit_SCD30_Humidity *humidity_sensor =
NULL; ///< Humidity sensor data object
private:
friend class Adafruit_SCD30_Temp; ///< Gives access to private members to
///< Temp data object
friend class Adafruit_SCD30_Humidity; ///< Gives access to private
///< members to Humidity data
///< object
void fillHumidityEvent(sensors_event_t *humidity, uint32_t timestamp);
void fillTempEvent(sensors_event_t *temp, uint32_t timestamp);
bool sendCommand(uint16_t command, uint16_t argument);
bool sendCommand(uint16_t command);
uint16_t getAmbiendPressure(void);
uint8_t computeCRC8(uint8_t data[], uint8_t len);
uint16_t readRegister(uint16_t reg_address);
};
#endif

View File

@@ -0,0 +1,53 @@
# Adafruit SCD30 [![Build Status](https://github.com/adafruit/Adafruit_SCD30/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_SCD30/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_SCD30/html/index.html)
This is the Adafruit SCD30 CO2, Temperature, and Humidity Sensor Library for Arduino
Tested and works great with the [Adafruit SCD30 Breakout Board](https://www.adafruit.com/products/4867):
[<img src="assets/board.png?raw=true" width="500px">](https://www.adafruit.com/products/4867)
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
# Installation
To install, use the Arduino Library Manager and search for "Adafruit SCD30" and install the library.
## Dependencies
* [Adafruit BusIO](https://github.com/adafruit/Adafruit_BusIO)
* [Adafruit Unified Sensor Driver](https://github.com/adafruit/Adafruit_Sensor)
* [Adafruit SSD1306](https://github.com/adafruit/Adafruit_SSD1306)
# Contributing
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_SCD30/blob/master/code-of-conduct.md)
before contributing to help this project stay welcoming.
## Documentation and doxygen
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
Some examples of how to use doxygen can be found in these guide pages:
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
## Formatting and clang-format
This library uses [`clang-format`](https://releases.llvm.org/download.html) to standardize the formatting of `.cpp` and `.h` files.
Contributions should be formatted using `clang-format`:
The `-i` flag will make the changes to the file.
```bash
clang-format -i *.cpp *.h
```
If you prefer to make the changes yourself, running `clang-format` without the `-i` flag will print out a formatted version of the file. You can save this to a file and diff it against the original to see the changes.
Note that the formatting output by `clang-format` is what the automated formatting checker will expect. Any diffs from this formatting will result in a failed build until they are addressed. Using the `-i` flag is highly recommended.
### clang-format resources
* [Binary builds and source available on the LLVM downloads page](https://releases.llvm.org/download.html)
* [Documentation and IDE integration](https://clang.llvm.org/docs/ClangFormat.html)
## About this Driver
Written by Bryan Siepert for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 MiB

View File

@@ -0,0 +1,127 @@
# Adafruit Community Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.
## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment
include:
* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities
Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an
open message from any channel, or a direct message to @kattni#1507,
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
@Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

View File

@@ -0,0 +1,53 @@
// Basic demo for readings from Adafruit SCD30
#include <Adafruit_SCD30.h>
Adafruit_SCD30 scd30;
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit SCD30 test!");
// Try to initialize!
if (!scd30.begin()) {
Serial.println("Failed to find SCD30 chip");
while (1) { delay(10); }
}
Serial.println("SCD30 Found!");
// if (!scd30.setMeasurementInterval(10)){
// Serial.println("Failed to set measurement interval");
// while(1){ delay(10);}
// }
Serial.print("Measurement Interval: ");
Serial.print(scd30.getMeasurementInterval());
Serial.println(" seconds");
}
void loop() {
if (scd30.dataReady()){
Serial.println("Data available!");
if (!scd30.read()){ Serial.println("Error reading sensor data"); return; }
Serial.print("Temperature: ");
Serial.print(scd30.temperature);
Serial.println(" degrees C");
Serial.print("Relative Humidity: ");
Serial.print(scd30.relative_humidity);
Serial.println(" %");
Serial.print("CO2: ");
Serial.print(scd30.CO2, 3);
Serial.println(" ppm");
Serial.println("");
} else {
//Serial.println("No data");
}
delay(100);
}

View File

@@ -0,0 +1,76 @@
// A simple CO2 meter using the Adafruit SCD30 breakout and the Adafruit 128x32 OLEDs
#include <Adafruit_SCD30.h>
#include <Adafruit_SSD1306.h>
Adafruit_SCD30 scd30;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("SCD30 OLED CO2 meter!");
// Try to initialize!
if (!scd30.begin()) {
Serial.println("Failed to find SCD30 chip");
while (1) { delay(10); }
}
Serial.println("SCD30 Found!");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
if (!scd30.setMeasurementInterval(2)){
Serial.println("Failed to set measurement interval");
while(1) {delay(10);}
}
Serial.print("Measurement Interval: ");
Serial.print(scd30.getMeasurementInterval());
Serial.println(" seconds");
display.display();
delay(500); // Pause for half second
display.setTextSize(2);
display.setTextColor(WHITE);
display.setRotation(0);
}
void loop() {
if (scd30.dataReady()) {
display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(2);
Serial.println("Data available!");
if (!scd30.read()){
Serial.println("Error reading sensor data");
display.println("READ ERR");
display.display();
return;
}
Serial.print("CO2: ");
Serial.print(scd30.CO2, 3);
Serial.println(" ppm");
Serial.println("");
display.println("CO2:");
display.print(scd30.CO2, 2);
display.setTextSize(1);
display.setCursor(100, 20);
display.println(" ppm");
display.display();
}
delay(100);
}

View File

@@ -0,0 +1,133 @@
// Demo of the available settings for the SCD30
#include <Adafruit_SCD30.h>
Adafruit_SCD30 scd30;
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit SCD30 Sensor adjustment test!");
// Try to initialize!
if (!scd30.begin()) {
Serial.println("Failed to find SCD30 chip");
while (1) { delay(10); }
}
Serial.println("SCD30 Found!");
/***
* The code below will report the current settings for each of the
* settings that can be changed. To see how they work, uncomment the setting
* code above a status message and adjust the value
*
* **Note:** Since Automatic self calibration and forcing recalibration with
* a reference value overwrite each other, you should only set one or the other
***/
/*** Adjust the rate at which measurements are taken, from 2-1800 seconds */
// if (!scd30.setMeasurementInterval(5)) {
// Serial.println("Failed to set measurement interval");
// while(1){ delay(10);}
// }
Serial.print("Measurement interval: ");
Serial.print(scd30.getMeasurementInterval());
Serial.println(" seconds");
/*** Restart continuous measurement with a pressure offset from 700 to 1400 millibar.
* Giving no argument or setting the offset to 0 will disable offset correction
*/
// if (!scd30.startContinuousMeasurement(15)){
// Serial.println("Failed to set ambient pressure offset");
// while(1){ delay(10);}
// }
Serial.print("Ambient pressure offset: ");
Serial.print(scd30.getAmbientPressureOffset());
Serial.println(" mBar");
/*** Set an altitude offset in meters above sea level.
* Offset value stored in non-volatile memory of SCD30.
* Setting an altitude offset will override any pressure offset.
*/
// if (!scd30.setAltitudeOffset(110)){
// Serial.println("Failed to set altitude offset");
// while(1){ delay(10);}
// }
Serial.print("Altitude offset: ");
Serial.print(scd30.getAltitudeOffset());
Serial.println(" meters");
/*** Set a temperature offset in hundredths of a degree celcius.
* Offset value stored in non-volatile memory of SCD30.
*/
// if (!scd30.setTemperatureOffset(1984)){ // 19.84 degrees celcius
// Serial.println("Failed to set temperature offset");
// while(1){ delay(10);}
// }
Serial.print("Temperature offset: ");
Serial.print((float)scd30.getTemperatureOffset()/100.0);
Serial.println(" degrees C");
/*** Force the sensor to recalibrate with the given reference value
* from 400-2000 ppm. Writing a recalibration reference will overwrite
* any previous self calibration values.
* Reference value stored in non-volatile memory of SCD30.
*/
// if (!scd30.forceRecalibrationWithReference(400)){
// Serial.println("Failed to force recalibration with reference");
// while(1) { delay(10); }
// }
Serial.print("Forced Recalibration reference: ");
Serial.print(scd30.getForcedCalibrationReference());
Serial.println(" ppm");
/*** Enable or disable automatic self calibration (ASC).
* Parameter stored in non-volatile memory of SCD30.
* Enabling self calibration will override any previously set
* forced calibration value.
* ASC needs continuous operation with at least 1 hour
* 400ppm CO2 concentration daily.
*/
// if (!scd30.selfCalibrationEnabled(true)){
// Serial.println("Failed to enable or disable self calibration");
// while(1) { delay(10); }
// }
if (scd30.selfCalibrationEnabled()) {
Serial.print("Self calibration enabled");
} else {
Serial.print("Self calibration disabled");
}
Serial.println("\n\n");
}
void loop() {
if (scd30.dataReady()) {
if (!scd30.read()){
Serial.println("Error reading sensor data");
return;
}
Serial.print("Temperature: ");
Serial.print(scd30.temperature);
Serial.println(" degrees C");
Serial.print("Relative Humidity: ");
Serial.print(scd30.relative_humidity);
Serial.println(" %");
Serial.print("CO2: ");
Serial.print(scd30.CO2, 3);
Serial.println(" ppm");
Serial.println("");
}
delay(100);
}

View File

@@ -0,0 +1,45 @@
// Unified sensor demo for readings from Adafruit SCD30
#include <Adafruit_SCD30.h>
#include <Adafruit_Sensor.h>
Adafruit_SCD30 scd30;
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit SCD30 Temperature and humidity unified sensor test!");
// Try to initialize!
if (!scd30.begin()) {
Serial.println("Failed to find SCD30 chip");
while (1) { delay(10); }
}
Serial.println("SCD30 Found!");
}
void loop() {
if(scd30.dataReady()){
Serial.println("Data available!");
sensors_event_t temp;
sensors_event_t humidity;
if (!scd30.getEvent(&humidity, &temp)){
Serial.println("Error reading sensor data");
return;
}
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degrees C");
Serial.print("Relative Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
Serial.println("");
}
delay(100);
}

View File

@@ -0,0 +1,10 @@
name=Adafruit SCD30
version=1.0.11
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for the SCD30 sensors in the Adafruit shop
paragraph=Arduino library for the SCD30 sensors in the Adafruit shop
category=Sensors
url=https://github.com/adafruit/Adafruit_SCD30
architectures=*
depends=Adafruit Unified Sensor, Adafruit BusIO, Adafruit SSD1306

View File

@@ -0,0 +1,26 @@
Software License Agreement (BSD License)
Copyright (c) 2020 Bryan Siepert for Adafruit Industries
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.