Skip to content

Commit

Permalink
Merge branch 'devel' of github.com:kike-canaries/canairio_sensorlib i…
Browse files Browse the repository at this point in the history
…nto devel
  • Loading branch information
hpsaturn committed Mar 23, 2024
2 parents 0ab605e + b605255 commit 7b65fc0
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 28 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ jobs:
- name: Basic Arduino IDE example test
run: |
cd examples/advanced_sensirion
pio run -s
- name: PlatformIO registry test (M5CoreInk project)
pio run
- name: PlatformIO registry backward (M5CoreInk project)
run: |
git clone https://github.com/hpsaturn/co2_m5coreink.git
cd co2_m5coreink
pio run -s
pio run
- name: PlatformIO registry lastest (M5Atom project)
run: |
cd examples/m5atom
pio run
- name: All archictures tests
run: |
pio run
Expand Down
32 changes: 32 additions & 0 deletions examples/m5airq/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
src_dir = .
lib_dir = ../..
extra_configs = ../../unified-lib-deps.ini

[env]
framework = arduino
upload_speed = 1500000
monitor_speed = 115200
build_flags =
-D CORE_DEBUG_LEVEL=0
-D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_ESP32_DEV=1
-D M5AIRQ=1 ; in your implementation you NEED it (it will improved in the future)
lib_deps =
${commonlibs.lib_deps}

[env:m5airq]
extends = env
platform = espressif32
board = esp32-s3-devkitc-1
board_build.filesystem = littlefs ; compatibility with original demo firmware
96 changes: 96 additions & 0 deletions examples/m5airq/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @file main.cpp
* @author Antonio Vanegas @hpsaturn
* @date June 2018 - 2024
* @brief CanAirIO M5AirQ test
* @license GPL3
*
* Full documentation:
* https://github.com/kike-canaries/canairio_sensorlib#canairio-air-quality-sensors-library
*
* Full implementation for WiFi and Bluetooth Air Quality fixed and mobile station:
* https://github.com/kike-canaries/canairio_firmware#canairio-firmware
*
* CanAirIO project documentation:
* https://canair.io/docs
*/

#include <Arduino.h>

#include <Sensors.hpp>

#define POWER_HOLD 46 // M5AirQ main board
#define SEN55_POWER_EN 10

#define GROVE_SDA 13
#define GROVE_SCL 15

#define I2C1_SDA_PIN 11
#define I2C1_SCL_PIN 12

void printSensorsDetected() {
uint16_t sensors_count = sensors.getSensorsRegisteredCount();
uint16_t units_count = sensors.getUnitsRegisteredCount();
Serial.println("-->[MAIN] Sensors detected \t: " + String(sensors_count));
Serial.println("-->[MAIN] Sensors units count\t: " + String(units_count));
Serial.print("-->[MAIN] Sensors devices names\t: ");
int i = 0;
while (sensors.getSensorsRegistered()[i++] != 0) {
Serial.print(sensors.getSensorName((SENSORS)sensors.getSensorsRegistered()[i - 1]));
Serial.print(",");
}
Serial.println();
}

void printSensorsValues() {
Serial.println("-->[MAIN] Preview sensor values :");
UNIT unit = sensors.getNextUnit();
while (unit != UNIT::NUNIT) {
String uName = sensors.getUnitName(unit);
float uValue = sensors.getUnitValue(unit);
String uSymb = sensors.getUnitSymbol(unit);
Serial.printf("-->[MAIN] %6s:\t%02.1f\t%s\n", uName.c_str(), uValue, uSymb.c_str());
unit = sensors.getNextUnit();
}
}

void onSensorDataOk() {
Serial.println("======= E X A M P L E T E S T =========");
printSensorsDetected();
printSensorsValues();
}

void onSensorDataError(const char* msg) {}
/******************************************************************************
* M A I N
******************************************************************************/

void powerEnableSensors() {
Serial.println("-->[POWR] == enable sensors ==");
pinMode(POWER_HOLD, OUTPUT);
digitalWrite(POWER_HOLD, HIGH);
pinMode(SEN55_POWER_EN, OUTPUT);
digitalWrite(SEN55_POWER_EN, LOW);
}

void setup() {
Serial.begin(115200);
delay(2000); // Only for debugging
powerEnableSensors(); // M5AirQ enable sensors

delay(100);
Serial.println("\n== Sensor test setup ==\n");
Serial.println("-->[SETUP] Detecting sensors..");

sensors.setSampleTime(10); // config sensors sample time interval
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
sensors.setDebugMode(false); // [optional] debug mode
sensors.detectI2COnly(true); // not force to only i2c sensors
sensors.setTemperatureUnit(TEMPUNIT::CELSIUS); // comment for Celsius or set Fahrenheit
sensors.init(); // Auto detection (UART and i2c sensors)
delay(1000);
}

void loop() {
sensors.loop(); // read sensor data and showed it
}
4 changes: 1 addition & 3 deletions examples/m5atom/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

[platformio]
src_dir = .
lib_dir = ../..
extra_configs = ../../unified-lib-deps.ini

[env:esp32dev]
platform = espressif32
Expand All @@ -23,6 +21,6 @@ build_flags =
-D CORE_DEBUG_LEVEL=0
-D M5ATOM
lib_deps =
hpsaturn/CanAirIO Air Quality Sensors Library @ 0.7.4
fastled/FastLED@^3.5.0
m5stack/M5Atom@^0.0.7
${commonlibs.lib_deps}
Loading

0 comments on commit 7b65fc0

Please sign in to comment.