Skip to content

Commit

Permalink
add examples (#16)
Browse files Browse the repository at this point in the history
- add LORA example
- add Multiplexer example
- update readme.md
- minor edits.
  • Loading branch information
RobTillaart committed Jan 1, 2024
1 parent 0a88600 commit 342b04c
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.3.1] - 2024-01-01
- add LORA example
- add Multiplexer example
- update readme.md
- minor edits.

## [0.3.0] - 2023-12-08
- refactor API, begin()
- update readme.md
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2023 Rob Tillaart
Copyright (c) 2021-2024 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ or switch the VCC as a sort of ChipSelect signal.

- https://github.com/RobTillaart/TCA9548 (I2C 8 channel multiplexer)

See **TCA9548_demo_SGP30.ino** example.


#### Related

Expand Down Expand Up @@ -127,10 +129,10 @@ Note the measurement is slow as there is an active blocking until the sensor is
If the last measurement is less than a second ago, no measurement is made and the function returns false.


#### A-synchronous measurements
#### Asynchronous measurements

With the async interface, the user should control that reads are at least one second apart.
The user should also take care not to mix up different requests. See examples.
The user should also take care not to mix up different requests. See examples.

- **void request()** sends a request to the sensor to read CO2 and TVOC.
- **bool read()** returns true if the last request is more than 12 milliseconds ago the
Expand Down Expand Up @@ -208,9 +210,9 @@ The used references are based upon
(2) the assumption that this is 0.4 resp 0.5 ppm.
(Note only 1 significant digit) as mentioned in datasheet P2.

- **void setSrefH2(uint16_t s = 13119)** // 13119 is my measurement.
- **void setSrefH2(uint16_t s = 13119)** 13119 is my measurement.
- **uint16_t getSrefH2()** returns value set.
- **void setSrefEthanol(uint16_t s = 18472)** // 18472 is my measurement.
- **void setSrefEthanol(uint16_t s = 18472)** 18472 is my measurement.
- **uint16_t getSrefEthanol()** returns value set.


Expand All @@ -229,7 +231,6 @@ The used references are based upon
#### Could

- move code from .h to .cpp
- improve/merge the private **command()** function
- add/extend error handling
- better name for **measureTest()**

Expand All @@ -241,6 +242,7 @@ for the smallest platforms e.g. tiny.

- make defines for the magic numbers (commands)
- only used once.
- improve/merge the private **command()** function (made no difference)


## Support
Expand Down
5 changes: 3 additions & 2 deletions SGP30.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: SGP30.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.0
// VERSION: 0.3.1
// DATE: 2021-06-24
// PURPOSE: Arduino library for SGP30 environment sensor.
// URL: https://github.com/RobTillaart/SGP30
Expand All @@ -17,15 +17,16 @@
//
SGP30::SGP30(TwoWire *wire)
{
_address = 0x58;
_wire = wire;
_address = 0x58; // Fixed!

_tvoc = 0;
_co2 = 0;
_h2 = 0;
_ethanol = 0;

_lastTime = 0;
_lastRequest = 0;
_error = SGP30_OK;
}

Expand Down
9 changes: 5 additions & 4 deletions SGP30.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: SGP30.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.0
// VERSION: 0.3.1
// DATE: 2021-06-24
// PURPOSE: Arduino library for SGP30 environment sensor.
// URL: https://github.com/RobTillaart/SGP30
Expand All @@ -12,7 +12,7 @@
#include "Arduino.h"
#include "Wire.h"

#define SGP30_LIB_VERSION (F("0.3.0"))
#define SGP30_LIB_VERSION (F("0.3.1"))

#define SGP30_OK 0x00
#define SGP30_ERROR_CRC 0xFF
Expand Down Expand Up @@ -95,13 +95,14 @@ class SGP30
private:
uint8_t _address;
int _error;
uint32_t _lastTime = 0;
uint32_t _lastRequest = 0;
uint32_t _lastTime;
uint32_t _lastRequest;

// TODO improve?
int _command(uint16_t cmd);
int _command(uint16_t cmd, uint16_t v1);
int _command(uint16_t cmd, uint16_t v1, uint16_t v2);

uint8_t _CRC8(uint16_t val);
void _init();

Expand Down
30 changes: 30 additions & 0 deletions examples/TCA9548_demo_SGP30/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico
libraries:
- "AM232X"
- "TCA9548"
82 changes: 82 additions & 0 deletions examples/TCA9548_demo_SGP30/TCA9548_demo_SGP30.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// FILE: TCA9548_demo_SGP30.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo TCA9548 I2C multiplexer
// URL: https://github.com/RobTillaart/TCA9548
// URL: https://github.com/RobTillaart/SGP30


#include "SGP30.h"
#include "TCA9548.h"

PCA9546 MP(0x70);
uint8_t channels = 0;

SGP30 living; // channel 0
SGP30 kitchen; // channel 1
SGP30 outside; // channel 2

uint32_t lastTime = 0;

void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("TCA9548_LIB_VERSION: ");
Serial.println(TCA9548_LIB_VERSION);
Serial.print("SGP30_LIB_VERSION: ");
Serial.println(SGP30_LIB_VERSION);
Serial.println();

Wire.begin();
// initialize multiplexer
if (MP.begin() == false)
{
Serial.println("Multiplexer error");
}
channels = MP.channelCount();

// initialize the temperature sensors
MP.selectChannel(0);
if (living.begin() == false)
{
Serial.println("living error");
}
MP.selectChannel(1);
if (kitchen.begin() == false )
{
Serial.println("kitchen error");
}
MP.selectChannel(2);
if (outside.begin() == false )
{
Serial.println("outside error");
}
}


void loop()
{
if ((millis() - lastTime) > 5000)
{
lastTime = millis();

MP.selectChannel(0);
living.read();
Serial.print(living.getCO2(), 1);
Serial.print("\t");

MP.selectChannel(1);
kitchen.read();
Serial.print(kitchen.getCO2(), 1);
Serial.print("\t");

MP.selectChannel(2);
outside.read();
Serial.print(outside.getCO2(), 1);
Serial.print("\n");
}
}


// -- END OF FILE --
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/SGP30.git"
},
"version": "0.3.0",
"version": "0.3.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SGP30
version=0.3.0
version=0.3.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for SGP30 environment sensor.
Expand Down

0 comments on commit 342b04c

Please sign in to comment.