Skip to content

Commit 4f2f048

Browse files
authored
Merge pull request #216 from kike-canaries/devel
TTGO T7S3 and M5Atom I2C issues fixed
2 parents 09c8d8d + 1a2103d commit 4f2f048

File tree

13 files changed

+425
-45
lines changed

13 files changed

+425
-45
lines changed

examples/DfRobot_Multigas/dfr_multigas.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
void onSensorDataOk() {
2222
Serial.println("-->[MAIN] NH3: " + String(sensors.getNH3()));
2323
Serial.println("-->[MAIN] CO: " + String(sensors.getCO()));
24-
Serial.println("-->[MAIN] NO2: " + String(sensors.getNO2()));)
24+
Serial.println("-->[MAIN] NO2: " + String(sensors.getNO2()));
25+
Serial.println("-->[MAIN] O3: " + String(sensors.getO3()));
2526
}
2627

2728
void onSensorDataError(const char* msg) {
@@ -48,7 +49,7 @@ void setup() {
4849
sensors.init(SENSORS::SDFRCO); // detect CO sensor
4950
sensors.init(SENSORS::SDFRNH3); // detect NH3 sensor
5051
sensors.init(SENSORS::SDFRNO2); // detect NO2 sensor
51-
52+
sensors.init(SENSORS::SDFRO3); // detect O3 sensor
5253
delay(500);
5354
}
5455

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*!
2+
* @file readGasConcentration.ino
3+
* @brief Obtain gas concentration corresponding to the current environment, output as concentration value
4+
* @n Experimental mode: connect sensor communication pin to the main controller and burn
5+
* @n Communication mode select, DIP switch SEL: 0: I2C, 1: UART
6+
* @n Group serial number Address in the group
7+
* @n A0 A1 DIP level 00 01 10 11
8+
* @n 1 0x60 0x61 0x62 0x63
9+
* @n 2 0x64 0x65 0x66 0x67
10+
* @n 3 0x68 0x69 0x6A 0x6B
11+
* @n 4 0x6C 0x6D 0x6E 0x6F
12+
* @n 5 0x70 0x71 0x72 0x73
13+
* @n 6 (Default address group) 0x74 0x75 0x76 0x77 (Default address)
14+
* @n 7 0x78 0x79 0x7A 0x7B
15+
* @n 8 0x7C 0x7D 0x7E 0x7F
16+
* @n i2c address select, default to 0x77, A1 and A0 are grouped into 4 I2C addresses.
17+
* @n | A0 | A1 |
18+
* @n | 0 | 0 | 0x74
19+
* @n | 0 | 1 | 0x75
20+
* @n | 1 | 0 | 0x76
21+
* @n | 1 | 1 | 0x77 default i2c address
22+
* @n Experimental phenomenon: view the gas concentration corresponding to the current environment through serial port printing
23+
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
24+
* @license The MIT License (MIT)
25+
* @author PengKaixing(kaixing.peng@dfrobot.com)
26+
* @version V1.0
27+
* @date 2021-03-28
28+
* @url https://github.com/DFRobot/DFRobot_MultiGasSensor
29+
*/
30+
#include "DFRobot_MultiGasSensor.h"
31+
#include <Arduino.h>
32+
33+
//Turn on by default, using I2C communication at the time, switch to serial port communication after turning off
34+
//#define I2C_COMMUNICATION
35+
36+
//#ifdef I2C_COMMUNICATION
37+
//#define I2C_ADDRESS 0x77
38+
DFRobot_GAS_I2C nh3(&Wire,0x7A);
39+
DFRobot_GAS_I2C co(&Wire,0x78);
40+
DFRobot_GAS_I2C no2(&Wire,0x7B);
41+
DFRobot_GAS_I2C o3(&Wire,0x79);
42+
43+
void setup() {
44+
//Serial port init for viewing printing output
45+
Serial.begin(115200);
46+
47+
//Change i2c address group
48+
while(no2.changeI2cAddrGroup(7)==0)
49+
{
50+
Serial.println("IIC addr change fail!");
51+
delay(1000);
52+
}
53+
Serial.println("IIC addr change success!");
54+
55+
//Sensor init, used to init serial port or I2C, depending on the communication mode currently used
56+
while(!nh3.begin())
57+
{
58+
Serial.println("No Devices NH3 !");
59+
delay(1000);
60+
}
61+
//Mode of obtaining data: the main controller needs to request the sensor for data
62+
nh3.changeAcquireMode(nh3.PASSIVITY);
63+
delay(1000);
64+
65+
nh3.setTempCompensation(nh3.ON);
66+
67+
Serial.println("The device nh3 0x7A is connected successfully!");
68+
69+
while(!co.begin())
70+
{
71+
Serial.println("No Devices CO !");
72+
delay(1000);
73+
}
74+
75+
co.changeAcquireMode(co.PASSIVITY);
76+
delay(1000);
77+
78+
co.setTempCompensation(co.ON);
79+
80+
Serial.println("The device CO 0x78 is connected successfully!");
81+
82+
while(!no2.begin())
83+
{
84+
Serial.println("No Devices NO2 !");
85+
delay(1000);
86+
}
87+
88+
no2.changeAcquireMode(no2.PASSIVITY);
89+
delay(1000);
90+
91+
no2.setTempCompensation(no2.ON);
92+
93+
Serial.println("The device NO2 0x7B is connected successfully!");
94+
95+
while(!o3.begin())
96+
{
97+
Serial.println("No Devices O3 !");
98+
delay(1000);
99+
}
100+
101+
o3.changeAcquireMode(o3.PASSIVITY);
102+
delay(1000);
103+
104+
o3.setTempCompensation(o3.ON);
105+
106+
Serial.println("The device O3 0x79 is connected successfully!");
107+
}
108+
109+
void loop() {
110+
String gastypeNH3 = nh3.queryGasType();
111+
/**
112+
*Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
113+
*The current gas concentration
114+
*Print with 1s delay each time
115+
*/
116+
Serial.print("Ambient ");
117+
Serial.print(gastypeNH3);
118+
Serial.print(" concentration is: ");
119+
Serial.print(nh3.readGasConcentrationPPM());
120+
if (gastypeNH3 == "O2")
121+
Serial.println(" %vol");
122+
else
123+
Serial.println(" PPM");
124+
Serial.println();
125+
delay(1000);
126+
127+
String gastypeCO = co.queryGasType();
128+
/**
129+
*Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
130+
*The current gas concentration
131+
*Print with 1s delay each time
132+
*/
133+
Serial.print("Ambient ");
134+
Serial.print(gastypeCO);
135+
Serial.print(" concentration is: ");
136+
Serial.print(co.readGasConcentrationPPM());
137+
if (gastypeCO == "O2")
138+
Serial.println(" %vol");
139+
else
140+
Serial.println(" PPM");
141+
Serial.println();
142+
delay(1000);
143+
144+
String gastypeNO2 = no2.queryGasType();
145+
/**
146+
*Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
147+
*The current gas concentration
148+
*Print with 1s delay each time
149+
*/
150+
Serial.print("Ambient ");
151+
Serial.print(gastypeNO2);
152+
Serial.print(" concentration is: ");
153+
Serial.print(no2.readGasConcentrationPPM());
154+
if (gastypeNO2 == "O2")
155+
Serial.println(" %vol");
156+
else
157+
Serial.println(" PPM");
158+
Serial.println();
159+
delay(1000);
160+
161+
String gastypeO3 = o3.queryGasType();
162+
/**
163+
*Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
164+
*The current gas concentration
165+
*Print with 1s delay each time
166+
*/
167+
Serial.print("Ambient ");
168+
Serial.print(gastypeO3);
169+
Serial.print(" concentration is: ");
170+
Serial.print(o3.readGasConcentrationPPM());
171+
if (gastypeO3 == "O2")
172+
Serial.println(" %vol");
173+
else
174+
Serial.println(" PPM");
175+
Serial.println();
176+
delay(1000);
177+
}
178+

examples/m5airq/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void onSensorDataOk() {
5858
Serial.println("======= E X A M P L E T E S T =========");
5959
printSensorsDetected();
6060
printSensorsValues();
61+
delay(5000);
6162
}
6263

6364
void onSensorDataError(const char* msg) {}
@@ -93,4 +94,5 @@ void setup() {
9394

9495
void loop() {
9596
sensors.loop(); // read sensor data and showed it
97+
delay(100);
9698
}

examples/ttgo_t7_s3/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

examples/ttgo_t7_s3/platformio.ini

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[platformio]
12+
src_dir = .
13+
lib_dir = ../..
14+
extra_configs = ../../unified-lib-deps.ini
15+
16+
[env]
17+
framework = arduino
18+
upload_speed = 1500000
19+
monitor_speed = 115200
20+
build_flags =
21+
-D CORE_DEBUG_LEVEL=0
22+
-D ARDUINO_USB_CDC_ON_BOOT=1
23+
-D ARDUINO_ESP32_DEV=1
24+
-D TTGO_T7S3=1 ; in your implementation you NEED it (it will improved in the future)
25+
lib_deps =
26+
${commonlibs.lib_deps}
27+
28+
[env:TTGO_T7S3]
29+
extends = env
30+
platform = espressif32
31+
board = esp32-s3-devkitc-1
32+
board_build.filesystem = littlefs ; compatibility with original demo firmware

examples/ttgo_t7_s3/src/main.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @file main.cpp
3+
* @author Antonio Vanegas @hpsaturn
4+
* @date June 2018 - 2025
5+
* @brief CanAirIO M5AirQ test
6+
* @license GPL3
7+
*
8+
* Full documentation:
9+
* https://github.com/kike-canaries/canairio_sensorlib#canairio-air-quality-sensors-library
10+
*
11+
* Full implementation for WiFi and Bluetooth Air Quality fixed and mobile station:
12+
* https://github.com/kike-canaries/canairio_firmware#canairio-firmware
13+
*
14+
* CanAirIO project documentation:
15+
* https://canair.io/docs
16+
*/
17+
18+
#include <Arduino.h>
19+
#include "Wire.h"
20+
#include <Sensors.hpp>
21+
22+
#define POWER_HOLD 3 // power sensors board enable pin
23+
24+
#define GROVE_SDA 13 // original grove port (defaults)
25+
#define GROVE_SCL 14
26+
27+
#define I2C1_SDA_PIN 8 // Wire1 alternative pins
28+
#define I2C1_SCL_PIN 9
29+
30+
void printSensorsDetected() {
31+
uint16_t sensors_count = sensors.getSensorsRegisteredCount();
32+
uint16_t units_count = sensors.getUnitsRegisteredCount();
33+
Serial.println("-->[MAIN] Sensors detected \t: " + String(sensors_count));
34+
Serial.println("-->[MAIN] Sensors units count\t: " + String(units_count));
35+
Serial.print("-->[MAIN] Sensors devices names\t: ");
36+
int i = 0;
37+
while (sensors.getSensorsRegistered()[i++] != 0) {
38+
Serial.print(sensors.getSensorName((SENSORS)sensors.getSensorsRegistered()[i - 1]));
39+
Serial.print(",");
40+
}
41+
Serial.println();
42+
}
43+
44+
void printSensorsValues() {
45+
Serial.println("-->[MAIN] Preview sensor values :");
46+
UNIT unit = sensors.getNextUnit();
47+
while (unit != UNIT::NUNIT) {
48+
String uName = sensors.getUnitName(unit);
49+
float uValue = sensors.getUnitValue(unit);
50+
String uSymb = sensors.getUnitSymbol(unit);
51+
Serial.printf("-->[MAIN] %6s:\t%02.1f\t%s\n", uName.c_str(), uValue, uSymb.c_str());
52+
unit = sensors.getNextUnit();
53+
}
54+
}
55+
56+
void onSensorDataOk() {
57+
Serial.println("======= E X A M P L E T E S T =========");
58+
printSensorsDetected();
59+
printSensorsValues();
60+
delay(5000);
61+
}
62+
63+
void onSensorDataError(const char* msg) {}
64+
/******************************************************************************
65+
* M A I N
66+
******************************************************************************/
67+
68+
void powerEnableSensors() {
69+
Serial.println("-->[POWR] == enable sensors ==");
70+
pinMode(POWER_HOLD, OUTPUT);
71+
digitalWrite(POWER_HOLD, HIGH);
72+
pinMode(GROVE_SDA, OUTPUT);
73+
pinMode(GROVE_SCL, OUTPUT);
74+
// Wire.begin(GROVE_SDA, GROVE_SCL); // defined in the library when build flag TTGO_T7S3 is set
75+
// Wire1.begin(I2C1_SDA_PIN, I2C1_SCL_PIN);
76+
}
77+
78+
void setup() {
79+
Serial.begin(115200);
80+
delay(4000); // Only for debugging
81+
powerEnableSensors(); // enable sensors (optional)
82+
83+
delay(100);
84+
Serial.println("\n== Sensor test setup ==\n");
85+
Serial.println("-->[SETUP] Detecting sensors..");
86+
87+
sensors.setSampleTime(10); // config sensors sample time interval
88+
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
89+
sensors.setDebugMode(false); // [optional] debug mode
90+
sensors.detectI2COnly(true); // not force to only i2c sensors
91+
sensors.setTemperatureUnit(TEMPUNIT::CELSIUS); // comment for Celsius or set Fahrenheit
92+
sensors.init(); // Auto detection (UART and i2c sensors)
93+
delay(1000);
94+
}
95+
96+
void loop() {
97+
sensors.loop(); // read sensor data and showed it
98+
delay(100);
99+
}

library.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CanAirIO Air Quality Sensors Library",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"homepage":"https://canair.io",
55
"keywords":
66
[
@@ -28,6 +28,7 @@
2828
"scd40",
2929
"scd41",
3030
"SenseAir S8",
31+
"DFRobot_MultiGasSensor",
3132
"cm1106",
3233
"sds011",
3334
"particulate matter",
@@ -76,12 +77,12 @@
7677
"license": "GPL-3.0-only",
7778
"dependencies":
7879
[
79-
{"name":"Adafruit Unified Sensor", "owner":"adafruit", "version":"1.1.13"},
80-
{"name":"Adafruit BME280 Library", "owner":"adafruit","version":"2.2.2"},
80+
{"name":"Adafruit Unified Sensor", "owner":"adafruit", "version":"1.1.14"},
81+
{"name":"Adafruit BME280 Library", "owner":"adafruit","version":"2.2.4"},
8182
{"name":"Adafruit BMP280 Library", "owner":"adafruit","version":"2.6.8"},
82-
{"name":"Adafruit BME680 Library","owner":"adafruit","version":"2.0.2"},
83+
{"name":"Adafruit BME680 Library","owner":"adafruit","version":"2.0.4"},
8384
{"name":"Adafruit SHT31 Library", "owner":"adafruit","version":"2.2.2"},
84-
{"name":"Adafruit SCD30", "owner":"adafruit","version":"1.0.9"},
85+
{"name":"Adafruit SCD30", "owner":"adafruit","version":"1.0.11"},
8586
{"name":"Adafruit BusIO", "owner":"adafruit","version":"1.14.5"},
8687
{"name":"AM232X", "owner":"robtillaart", "version":"0.5.0"},
8788
{"name":"sps30", "owner":"paulvha","version":"1.4.17"},

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=CanAirIO Air Quality Sensors Library
2-
version=0.7.5
2+
version=0.7.6
33
author=@hpsaturn, CanAirIO project <info@canair.io>
44
maintainer=Antonio Vanegas <hpsaturn@gmail.com>
55
url=https://github.com/kike-canaries/canairio_sensorlib

0 commit comments

Comments
 (0)