Skip to content

Commit

Permalink
add changelog.md (#9)
Browse files Browse the repository at this point in the history
* add changelog.md
  • Loading branch information
RobTillaart authored Nov 24, 2022
1 parent 10ea4fe commit 30a017c
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 74 deletions.
18 changes: 17 additions & 1 deletion .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
Expand All @@ -7,5 +22,6 @@ compile:
# - leonardo
- m4
- esp32
# - esp8266
- esp8266
# - mega2560
- rpipico
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Change Log SGP30

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.1.6] - 2022-10-28
- Add RP2040 support to build-CI.
- Add CHANGELOG.md


## [0.1.5] - 2021-12-28
- update library,json
- update readme
- update license
- minor edits

## [0.1.4] - 2021-07-01
- add CRC checking

## [0.1.3] - 2021-06-26
- add get/setTVOCbaseline()

## [0.1.2] - 2021-06-26
- experimental add units H2 + Ethanol

## [0.1.1] - 2021-06-26
- add get/setBaseline ++

## [0.1.0] - 2021-06-24
- initial version

72 changes: 32 additions & 40 deletions SGP30.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
//
// FILE: SGP30.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.5
// VERSION: 0.1.6
// DATE: 2021-06-24
// PURPOSE: SGP30 library for Arduino
// URL: https://github.com/RobTillaart/SGP30
// https://www.adafruit.com/product/3709
//
// HISTORY:
// 0.1.0 2021-06-24 initial version
// 0.1.1 2021-06-26 add get/setBaseline ++
// 0.1.2 2021-06-26 experimental add units H2 + Ethanol
// 0.1.3 2021-06-26 add get/setTVOCbaseline()
// 0.1.4 2021-07-01 add CRC checking
// 0.1.5 2021-12-28 update library,json, readme, license, minor edits


#include "SGP30.h"


/////////////////////////////////////////////////////
//
// CONSTRUCTOR
// CONSTRUCTOR
//
SGP30::SGP30(TwoWire *wire)
{
Expand Down Expand Up @@ -70,7 +62,7 @@ bool SGP30::isConnected()
}


// INITIAL VERSION - needs optimization
// INITIAL VERSION - needs optimization
bool SGP30::getID()
{
_command(0x3682);
Expand All @@ -97,7 +89,7 @@ bool SGP30::getID()
}


// expect to return 0x0022
// expect to return 0x0022
uint16_t SGP30::getFeatureSet()
{
_command(0x202F);
Expand All @@ -121,7 +113,7 @@ uint16_t SGP30::getFeatureSet()
}


// WARNING: resets all devices on I2C bus.
// WARNING: resets all devices on I2C bus.
void SGP30::GenericReset()
{
_command(0x0006);
Expand All @@ -133,7 +125,7 @@ bool SGP30::measureTest()
{
uint16_t rv = 0;
_command(0x2032);
delay(220); // Page 11
delay(220); // Page 11
if (_wire->requestFrom(_address, (uint8_t)3) == 3)
{
rv = _wire->read() << 8;
Expand All @@ -154,13 +146,13 @@ bool SGP30::measureTest()

/////////////////////////////////////////////////////
//
// MEASUREMENT
// MEASUREMENT
//

// SYNCHRONUOUS MODUS
bool SGP30::measure(bool all) // this is the workhorse
// SYNCHRONUOUS MODUS
bool SGP30::measure(bool all) // this is the workhorse
{
// 1 second between measurements. P.09
// 1 second between measurements. Page 9
if (millis() - _lastTime < 1000) return false;
_lastTime = millis();

Expand All @@ -177,7 +169,7 @@ bool SGP30::measure(bool all) // this is the workhorse
}


// A-SYNCHRONUOUS INTERFACE
// A-SYNCHRONUOUS INTERFACE
void SGP30::request()
{
_lastRequest = millis();
Expand All @@ -188,7 +180,7 @@ void SGP30::request()
bool SGP30::read()
{
if (_lastRequest == 0) return false;
if (millis() - _lastRequest < 13) return false; // P11
if (millis() - _lastRequest < 13) return false; // Page 11
_lastRequest = 0;

if (_wire->requestFrom(_address, (uint8_t)6) != 6)
Expand Down Expand Up @@ -227,7 +219,7 @@ void SGP30::requestRaw()
bool SGP30::readRaw()
{
if (_lastRequest == 0) return false;
if (millis() - _lastRequest < 26) return false; // P11
if (millis() - _lastRequest < 26) return false; // Page 11
_lastRequest = 0;

if (_wire->requestFrom(_address, (uint8_t)6) != 6)
Expand Down Expand Up @@ -256,34 +248,34 @@ bool SGP30::readRaw()
}


// experimental - datasheet P2
// 1.953125e-3 = 1/512
// experimental - datasheet Page 2
// 1.953125e-3 = 1/512
float SGP30::getH2()
{
float cref = 0.5; // ppm
float cref = 0.5; // ppm
return cref * exp((_srefH2 - _h2) * 1.953125e-3);
}


float SGP30::getEthanol()
{
float cref = 0.4; // ppm
float cref = 0.4; // ppm
return cref * exp((_srefEth - _ethanol) * 1.953125e-3);
}


/////////////////////////////////////////////////////
//
// CALIBRATION
// CALIBRATION
//

// T in °C
// RH == RelativeHumidity
float SGP30::setRelHumidity(float T, float RH) // P10
// T in °C
// RH == RelativeHumidity
float SGP30::setRelHumidity(float T, float RH) // Page 10
{
// page 10 datasheet
// AH = AbsoluteHumidity
// uint16_t AH = 216.7 * RH/100 * 6.117 * exp((17.62 * T)/(243.12 + T)) / (273.15 + T);
// page 10 datasheet
// AH = AbsoluteHumidity
// uint16_t AH = 216.7 * RH/100 * 6.117 * exp((17.62 * T)/(243.12 + T)) / (273.15 + T);
float absoluteHumidity = (2.167 * 6.112) * RH ;
absoluteHumidity *= exp((17.62 * T)/(243.12 + T));
absoluteHumidity /= (273.15 + T);
Expand All @@ -299,7 +291,7 @@ void SGP30::setAbsHumidity(float absoluteHumidity)
uint8_t tmp = (absoluteHumidity - AH) * 256;
AH = (AH << 8) | tmp;

_command(0x2061, AH); // P 11
_command(0x2061, AH); // Page 11
}


Expand Down Expand Up @@ -367,7 +359,7 @@ bool SGP30::getTVOCBaseline(uint16_t *TVOC)

/////////////////////////////////////////////////////
//
// MISC
// MISCELANEOUS
//
int SGP30::lastError()
{
Expand All @@ -379,7 +371,7 @@ int SGP30::lastError()

/////////////////////////////////////////////////////
//
// PRIVATE
// PRIVATE
//
int SGP30::_command(uint16_t cmd)
{
Expand Down Expand Up @@ -420,22 +412,22 @@ int SGP30::_command(uint16_t cmd, uint16_t v1, uint16_t v2)
}


// for sending command - CRC lib.
// always 2 bytes
// for sending command - CRC lib.
// always 2 bytes
uint8_t SGP30::_CRC8(uint16_t data)
{
uint8_t val[2];
val[0] = data >> 8;
val[1] = data & 0xFF;

uint8_t crc = 0xFF; // start value
uint8_t crc = 0xFF; // start value
for(uint8_t i = 0; i < 2; i++)
{
crc ^= val[i];
for (uint8_t b = 8; b > 0; b--)
{
if (crc & 0x80)
crc = (crc << 1) ^ 0x31; // polynomial
crc = (crc << 1) ^ 0x31; // polynomial
else
crc <<= 1;
}
Expand All @@ -450,5 +442,5 @@ void SGP30::_init()
};


// -- END OF FILE --
// -- END OF FILE --

Loading

0 comments on commit 30a017c

Please sign in to comment.