Skip to content

Instantly share code, notes, and snippets.

@e-jigsaw
Last active December 24, 2021 13:12
Show Gist options
  • Save e-jigsaw/c1149df69f6e2dcda52ef4f674de270c to your computer and use it in GitHub Desktop.
Save e-jigsaw/c1149df69f6e2dcda52ef4f674de270c to your computer and use it in GitHub Desktop.
#include "M5StickCPlus.h"
#include "SCD30.h"
void setup() {
M5.begin();
M5.Lcd.setTextColor(WHITE);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0,0);
M5.Lcd.setTextSize(2);
M5.Lcd.println("START");
Wire.begin();
Serial.begin(9600);
scd30.initialize();
}
void loop() {
float result[3] = {0};
if (scd30.isAvailable()) {
scd30.getCarbonDioxideConcentration(result);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0,0);
M5.Lcd.println("CO2:");
M5.Lcd.print(result[0]);
M5.Lcd.println(" ppm");
M5.Lcd.println("---");
M5.Lcd.println("Temp:");
M5.Lcd.print(result[1]);
M5.Lcd.println(" C");
M5.Lcd.println("---");
M5.Lcd.println("Humidity:");
M5.Lcd.print(result[2]);
M5.Lcd.println(" %");
M5.Lcd.println("---");
Serial.println(String(result[0])+','+String(result[1])+','+String(result[2]));
}
delay(30000);
}
const SerialPort = require('serialport')
const Ambient = require('ambient-lib')
const port = new SerialPort('/dev/ttyUSB0', {
baudRate: 9600
})
let tmp = ''
const am = new Ambient(ch, key)
port.on('data', (data) => {
tmp += data.toString()
if (/\r\n/.test(tmp)) {
const [co2, temp, hum] = tmp.split(',')
am.send({d1: co2, d2: temp, d3: hum.replace(/\r\n/, '')}, (res) => console.log(res.status))
console.log(co2, temp, hum)
tmp = ''
}
console.log('rcv:', data.toString(), tmp)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment