Created
October 18, 2022 12:31
-
-
Save tianrking/f70fdf791081bb9e646bebd37b6b4d7f to your computer and use it in GitHub Desktop.
A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TFT_eSPI.h> | |
#include "Free_Fonts.h" | |
TFT_eSPI tft; | |
TFT_eSprite spr = TFT_eSprite(&tft); | |
#define SCREEN_WIDTH 320 // Wio Terminal Maximum Width | |
#define SCREEN_HIGH 240 // Wio Terminal Maximum Height | |
#define PIXEL 4 // Width of one letter | |
const static unsigned int FONT_ROW_HEIGHT = 22; // The height of a letter | |
#include "seeed_line_chart.h" //include the library | |
#include <Arduino.h> | |
#include "sensirion_common.h" | |
#include "sgp30.h" | |
#define MAX_SIZE 30 // maximum size of data | |
#include "Wire.h" | |
#include "DHT.h" | |
#define DHTTYPE DHT20 // DHT 20 | |
// /*Notice: The DHT10 and DHT20 is different from other DHT* sensor ,it uses i2c interface rather than one wire*/ | |
// /*So it doesn't require a pin.*/ | |
DHT dht(DHTTYPE); // DHT10 DHT20 don't need to define Pin | |
void DISPLAY_INIT() // Display initialization, black background rotation | |
{ | |
tft.begin(); | |
tft.setRotation(3); | |
tft.fillScreen(TFT_BLACK); | |
} | |
void BindDev_Display(int _CO2,int _template=1) // Select Frequency band interface | |
{ | |
spr.createSprite(SCREEN_WIDTH, SCREEN_HIGH); | |
// put your main code here | |
spr.setFreeFont(FSSB9); | |
spr.setTextColor(TFT_WHITE); | |
spr.drawString(String(_CO2), 10, 10 , GFXFF); //Show the network you are in | |
// spr.drawString(String(_template), 30, 10 , GFXFF); //Show the network you are in | |
spr.pushSprite(20,20); | |
spr.deleteSprite(); | |
} | |
void setup_1() { | |
s16 err; | |
u16 scaled_ethanol_signal, scaled_h2_signal; | |
Serial.begin(115200); | |
Serial.println("serial start!!"); | |
/*For wio link!*/ | |
#if defined(ESP8266) | |
pinMode(15, OUTPUT); | |
digitalWrite(15, 1); | |
Serial.println("Set wio link power!"); | |
delay(500); | |
#endif | |
/* Init module,Reset all baseline,The initialization takes up to around 15 seconds, during which | |
all APIs measuring IAQ(Indoor air quality ) output will not change.Default value is 400(ppm) for co2,0(ppb) for tvoc*/ | |
while (sgp_probe() != STATUS_OK) { | |
Serial.println("SGP failed"); | |
while (1); | |
} | |
/*Read H2 and Ethanol signal in the way of blocking*/ | |
// err = sgp_measure_signals_blocking_read(&scaled_ethanol_signal, | |
// &scaled_h2_signal); | |
// if (err == STATUS_OK) { | |
// Serial.println("get ram signal!"); | |
// } else { | |
// Serial.println("error reading signals"); | |
// } | |
// err = sgp_iaq_init(); | |
// // debug.begin(115200); | |
// debug.println("DHTxx test!"); | |
// Wire.begin(); | |
/*if using WIO link,must pull up the power pin.*/ | |
// pinMode(PIN_GROVE_POWER, OUTPUT); | |
// digitalWrite(PIN_GROVE_POWER, 1); | |
// dht.begin(); | |
// | |
} | |
void setup() | |
{ | |
DISPLAY_INIT(); | |
setup_1(); | |
} | |
float temp_hum_val[2] = {0}; | |
void loop() | |
{ | |
s16 err = 0; | |
u16 tvoc_ppb, co2_eq_ppm; | |
err = sgp_measure_iaq_blocking_read(&tvoc_ppb, &co2_eq_ppm); | |
if (err == STATUS_OK) { | |
Serial.print("tVOC Concentration:"); | |
Serial.print(tvoc_ppb); | |
Serial.println("ppb"); | |
Serial.print("CO2eq Concentration:"); | |
Serial.print(co2_eq_ppm); | |
Serial.println("ppm"); | |
} else { | |
Serial.println("error reading IAQ values\n"); | |
} | |
// if (!dht.readTempAndHumidity(temp_hum_val)) { | |
if (1==1) { | |
Serial.print("Humidity: "); | |
Serial.print(temp_hum_val[0]); | |
Serial.print(" %\t"); | |
Serial.print("Temperature: "); | |
Serial.print(temp_hum_val[1]); | |
Serial.println(" *C"); | |
} else { | |
Serial.println("Failed to get temprature and humidity value."); | |
} | |
BindDev_Display(tvoc_ppb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment