Add PM25 Kit example

This commit is contained in:
TinyuChiu
2022-12-15 10:46:29 +08:00
parent 34293be661
commit 6ab55cfa20
4 changed files with 726 additions and 0 deletions
+114
View File
@@ -0,0 +1,114 @@
#include "DFRobot_SHT20.h"
void DFRobot_SHT20::initSHT20(TwoWire &wirePort)
{
i2cPort = &wirePort;
i2cPort->begin();
}
uint16_t DFRobot_SHT20::readValue(byte cmd)
{
i2cPort->beginTransmission(SLAVE_ADDRESS);
i2cPort->write(cmd);
i2cPort->endTransmission();
byte toRead;
byte counter;
for(counter = 0, toRead = 0 ; counter < MAX_COUNTER && toRead != 3; counter++){
delay(DELAY_INTERVAL);
toRead = i2cPort->requestFrom(SLAVE_ADDRESS, 3);
}
if(counter == MAX_COUNTER){
return (ERROR_I2C_TIMEOUT);
}
byte msb, lsb, checksum;
msb = i2cPort->read();
lsb = i2cPort->read();
checksum = i2cPort->read();
uint16_t rawValue = ((uint16_t) msb << 8) | (uint16_t) lsb;
if(checkCRC(rawValue, checksum) != 0){
return (ERROR_BAD_CRC);
}
return rawValue & 0xFFFC;
}
float DFRobot_SHT20::readHumidity(void)
{
uint16_t rawHumidity = readValue(TRIGGER_HUMD_MEASURE_NOHOLD);
if(rawHumidity == ERROR_I2C_TIMEOUT || rawHumidity == ERROR_BAD_CRC){
return(rawHumidity);
}
float tempRH = rawHumidity * (125.0 / 65536.0);
float rh = tempRH - 6.0;
return (rh);
}
float DFRobot_SHT20::readTemperature(void)
{
uint16_t rawTemperature = readValue(TRIGGER_TEMP_MEASURE_NOHOLD);
if(rawTemperature == ERROR_I2C_TIMEOUT || rawTemperature == ERROR_BAD_CRC){
return(rawTemperature);
}
float tempTemperature = rawTemperature * (175.72 / 65536.0);
float realTemperature = tempTemperature - 46.85;
return (realTemperature);
}
void DFRobot_SHT20::setResolution(byte resolution)
{
byte userRegister = readUserRegister();
userRegister &= B01111110;
resolution &= B10000001;
userRegister |= resolution;
writeUserRegister(userRegister);
}
byte DFRobot_SHT20::readUserRegister(void)
{
byte userRegister;
i2cPort->beginTransmission(SLAVE_ADDRESS);
i2cPort->write(READ_USER_REG);
i2cPort->endTransmission();
i2cPort->requestFrom(SLAVE_ADDRESS, 1);
userRegister = i2cPort->read();
return (userRegister);
}
void DFRobot_SHT20::writeUserRegister(byte val)
{
i2cPort->beginTransmission(SLAVE_ADDRESS);
i2cPort->write(WRITE_USER_REG);
i2cPort->write(val);
i2cPort->endTransmission();
}
byte DFRobot_SHT20::checkCRC(uint16_t message_from_sensor, uint8_t check_value_from_sensor)
{
uint32_t remainder = (uint32_t)message_from_sensor << 8;
remainder |= check_value_from_sensor;
uint32_t divsor = (uint32_t)SHIFTED_DIVISOR;
for(int i = 0 ; i < 16 ; i++){
if(remainder & (uint32_t)1 << (23 - i)){
remainder ^= divsor;
}
divsor >>= 1;
}
return (byte)remainder;
}
void DFRobot_SHT20::showReslut(const char *prefix, int val)
{
Serial.print(prefix);
if(val){
Serial.println("yes");
}else{
Serial.println("no");
}
}
void DFRobot_SHT20::checkSHT20(void)
{
byte reg = readUserRegister();
showReslut("End of battery: ", reg & USER_REGISTER_END_OF_BATTERY);
showReslut("Heater enabled: ", reg & USER_REGISTER_HEATER_ENABLED);
showReslut("Disable OTP reload: ", reg & USER_REGISTER_DISABLE_OTP_RELOAD);
}
+52
View File
@@ -0,0 +1,52 @@
#ifndef DFRobot_SHT20_h
#define DFRobot_SHT20_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Wire.h>
#define ERROR_I2C_TIMEOUT 998
#define ERROR_BAD_CRC 999
#define SLAVE_ADDRESS 0x40
#define TRIGGER_TEMP_MEASURE_HOLD 0xE3
#define TRIGGER_HUMD_MEASURE_HOLD 0xE5
#define TRIGGER_TEMP_MEASURE_NOHOLD 0xF3
#define TRIGGER_HUMD_MEASURE_NOHOLD 0xF5
#define WRITE_USER_REG 0xE6
#define READ_USER_REG 0xE7
#define SOFT_RESET 0xFE
#define USER_REGISTER_RESOLUTION_MASK 0x81
#define USER_REGISTER_RESOLUTION_RH12_TEMP14 0x00
#define USER_REGISTER_RESOLUTION_RH8_TEMP12 0x01
#define USER_REGISTER_RESOLUTION_RH10_TEMP13 0x80
#define USER_REGISTER_RESOLUTION_RH11_TEMP11 0x81
#define USER_REGISTER_END_OF_BATTERY 0x40
#define USER_REGISTER_HEATER_ENABLED 0x04
#define USER_REGISTER_DISABLE_OTP_RELOAD 0x02
#define MAX_WAIT 100
#define DELAY_INTERVAL 10
#define SHIFTED_DIVISOR 0x988000
#define MAX_COUNTER (MAX_WAIT/DELAY_INTERVAL)
class DFRobot_SHT20
{
public:
void checkSHT20(void);
void setResolution(byte resBits);
void writeUserRegister(byte val);
void initSHT20(TwoWire &wirePort = Wire);
void showReslut(const char *prefix, int val);
float readHumidity(void);
float readTemperature(void);
byte readUserRegister(void);
private:
TwoWire *i2cPort;
byte checkCRC(uint16_t message_from_sensor, uint8_t check_value_from_sensor);
uint16_t readValue(byte cmd);
};
#endif
+377
View File
@@ -0,0 +1,377 @@
// Attach this header file to your sketch to use the GFX Free Fonts. You can write
// sketches without it, but it makes referencing them easier.
// This calls up ALL the fonts but they only get loaded if you actually
// use them in your sketch.
//
// No changes are needed to this header file unless new fonts are added to the
// library "Fonts/GFXFF" folder.
//
// To save a lot of typing long names, each font can easily be referenced in the
// sketch in three ways, either with:
//
// 1. Font file name with the & in front such as &FreeSansBoldOblique24pt7b
// an example being:
//
// tft.setFreeFont(&FreeSansBoldOblique24pt7b);
//
// 2. FF# where # is a number determined by looking at the list below
// an example being:
//
// tft.setFreeFont(FF32);
//
// 3. An abbreviation of the file name. Look at the list below to see
// the abbreviations used, for example:
//
// tft.setFreeFont(FSSBO24)
//
// Where the letters mean:
// F = Free font
// M = Mono
// SS = Sans Serif (double S to distinguish is form serif fonts)
// S = Serif
// B = Bold
// O = Oblique (letter O not zero)
// I = Italic
// # = point size, either 9, 12, 18 or 24
//
// Setting the font to NULL will select the GLCD font:
//
// tft.setFreeFont(NULL); // Set font to GLCD
#define LOAD_GFXFF
#ifdef LOAD_GFXFF // Only include the fonts if LOAD_GFXFF is defined in User_Setup.h
// Use these when printing or drawing text in GLCD and high rendering speed fonts
#define GFXFF 1
#define GLCD 0
#define FONT2 2
#define FONT4 4
#define FONT6 6
#define FONT7 7
#define FONT8 8
// Use the following when calling setFont()
//
// Reserved for GLCD font // FF0
//
#define TT1 &TomThumb
#define FM9 &FreeMono9pt7b
#define FM12 &FreeMono12pt7b
#define FM18 &FreeMono18pt7b
#define FM24 &FreeMono24pt7b
#define FMB9 &FreeMonoBold9pt7b
#define FMB12 &FreeMonoBold12pt7b
#define FMB18 &FreeMonoBold18pt7b
#define FMB24 &FreeMonoBold24pt7b
#define FMO9 &FreeMonoOblique9pt7b
#define FMO12 &FreeMonoOblique12pt7b
#define FMO18 &FreeMonoOblique18pt7b
#define FMO24 &FreeMonoOblique24pt7b
#define FMBO9 &FreeMonoBoldOblique9pt7b
#define FMBO12 &FreeMonoBoldOblique12pt7b
#define FMBO18 &FreeMonoBoldOblique18pt7b
#define FMBO24 &FreeMonoBoldOblique24pt7b
#define FSS9 &FreeSans9pt7b
#define FSS12 &FreeSans12pt7b
#define FSS18 &FreeSans18pt7b
#define FSS24 &FreeSans24pt7b
#define FSSB9 &FreeSansBold9pt7b
#define FSSB12 &FreeSansBold12pt7b
#define FSSB18 &FreeSansBold18pt7b
#define FSSB24 &FreeSansBold24pt7b
#define FSSO9 &FreeSansOblique9pt7b
#define FSSO12 &FreeSansOblique12pt7b
#define FSSO18 &FreeSansOblique18pt7b
#define FSSO24 &FreeSansOblique24pt7b
#define FSSBO9 &FreeSansBoldOblique9pt7b
#define FSSBO12 &FreeSansBoldOblique12pt7b
#define FSSBO18 &FreeSansBoldOblique18pt7b
#define FSSBO24 &FreeSansBoldOblique24pt7b
#define FS9 &FreeSerif9pt7b
#define FS12 &FreeSerif12pt7b
#define FS18 &FreeSerif18pt7b
#define FS24 &FreeSerif24pt7b
#define FSI9 &FreeSerifItalic9pt7b
#define FSI12 &FreeSerifItalic12pt7b
#define FSI19 &FreeSerifItalic18pt7b
#define FSI24 &FreeSerifItalic24pt7b
#define FSB9 &FreeSerifBold9pt7b
#define FSB12 &FreeSerifBold12pt7b
#define FSB18 &FreeSerifBold18pt7b
#define FSB24 &FreeSerifBold24pt7b
#define FSBI9 &FreeSerifBoldItalic9pt7b
#define FSBI12 &FreeSerifBoldItalic12pt7b
#define FSBI18 &FreeSerifBoldItalic18pt7b
#define FSBI24 &FreeSerifBoldItalic24pt7b
#define FF0 NULL //ff0 reserved for GLCD
#define FF1 &FreeMono9pt7b
#define FF2 &FreeMono12pt7b
#define FF3 &FreeMono18pt7b
#define FF4 &FreeMono24pt7b
#define FF5 &FreeMonoBold9pt7b
#define FF6 &FreeMonoBold12pt7b
#define FF7 &FreeMonoBold18pt7b
#define FF8 &FreeMonoBold24pt7b
#define FF9 &FreeMonoOblique9pt7b
#define FF10 &FreeMonoOblique12pt7b
#define FF11 &FreeMonoOblique18pt7b
#define FF12 &FreeMonoOblique24pt7b
#define FF13 &FreeMonoBoldOblique9pt7b
#define FF14 &FreeMonoBoldOblique12pt7b
#define FF15 &FreeMonoBoldOblique18pt7b
#define FF16 &FreeMonoBoldOblique24pt7b
#define FF17 &FreeSans9pt7b
#define FF18 &FreeSans12pt7b
#define FF19 &FreeSans18pt7b
#define FF20 &FreeSans24pt7b
#define FF21 &FreeSansBold9pt7b
#define FF22 &FreeSansBold12pt7b
#define FF23 &FreeSansBold18pt7b
#define FF24 &FreeSansBold24pt7b
#define FF25 &FreeSansOblique9pt7b
#define FF26 &FreeSansOblique12pt7b
#define FF27 &FreeSansOblique18pt7b
#define FF28 &FreeSansOblique24pt7b
#define FF29 &FreeSansBoldOblique9pt7b
#define FF30 &FreeSansBoldOblique12pt7b
#define FF31 &FreeSansBoldOblique18pt7b
#define FF32 &FreeSansBoldOblique24pt7b
#define FF33 &FreeSerif9pt7b
#define FF34 &FreeSerif12pt7b
#define FF35 &FreeSerif18pt7b
#define FF36 &FreeSerif24pt7b
#define FF37 &FreeSerifItalic9pt7b
#define FF38 &FreeSerifItalic12pt7b
#define FF39 &FreeSerifItalic18pt7b
#define FF40 &FreeSerifItalic24pt7b
#define FF41 &FreeSerifBold9pt7b
#define FF42 &FreeSerifBold12pt7b
#define FF43 &FreeSerifBold18pt7b
#define FF44 &FreeSerifBold24pt7b
#define FF45 &FreeSerifBoldItalic9pt7b
#define FF46 &FreeSerifBoldItalic12pt7b
#define FF47 &FreeSerifBoldItalic18pt7b
#define FF48 &FreeSerifBoldItalic24pt7b
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Now we define "s"tring versions for easy printing of the font name so:
// tft.println(sFF5);
// will print
// Mono bold 9
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define sFF0 "GLCD"
#define sTT1 "Tom Thumb"
#define sFF1 "Mono 9"
#define sFF2 "Mono 12"
#define sFF3 "Mono 18"
#define sFF4 "Mono 24"
#define sFF5 "Mono bold 9"
#define sFF6 "Mono bold 12"
#define sFF7 "Mono bold 18"
#define sFF8 "Mono bold 24"
#define sFF9 "Mono oblique 9"
#define sFF10 "Mono oblique 12"
#define sFF11 "Mono oblique 18"
#define sFF12 "Mono oblique 24"
#define sFF13 "Mono bold oblique 9"
#define sFF14 "Mono bold oblique 12"
#define sFF15 "Mono bold oblique 18"
#define sFF16 "Mono bold oblique 24" // Full text line is too big for 480 pixel wide screen
#define sFF17 "Sans 9"
#define sFF18 "Sans 12"
#define sFF19 "Sans 18"
#define sFF20 "Sans 24"
#define sFF21 "Sans bold 9"
#define sFF22 "Sans bold 12"
#define sFF23 "Sans bold 18"
#define sFF24 "Sans bold 24"
#define sFF25 "Sans oblique 9"
#define sFF26 "Sans oblique 12"
#define sFF27 "Sans oblique 18"
#define sFF28 "Sans oblique 24"
#define sFF29 "Sans bold oblique 9"
#define sFF30 "Sans bold oblique 12"
#define sFF31 "Sans bold oblique 18"
#define sFF32 "Sans bold oblique 24"
#define sFF33 "Serif 9"
#define sFF34 "Serif 12"
#define sFF35 "Serif 18"
#define sFF36 "Serif 24"
#define sFF37 "Serif italic 9"
#define sFF38 "Serif italic 12"
#define sFF39 "Serif italic 18"
#define sFF40 "Serif italic 24"
#define sFF41 "Serif bold 9"
#define sFF42 "Serif bold 12"
#define sFF43 "Serif bold 18"
#define sFF44 "Serif bold 24"
#define sFF45 "Serif bold italic 9"
#define sFF46 "Serif bold italic 12"
#define sFF47 "Serif bold italic 18"
#define sFF48 "Serif bold italic 24"
#else // LOAD_GFXFF not defined so setup defaults to prevent error messages
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Free fonts are not loaded in User_Setup.h so we must define all as font 1
// to prevent compile error messages
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define GFXFF 1
#define GLCD 1
#define FONT2 2
#define FONT4 4
#define FONT6 6
#define FONT7 7
#define FONT8 8
#define FF0 1
#define FF1 1
#define FF2 1
#define FF3 1
#define FF4 1
#define FF5 1
#define FF6 1
#define FF7 1
#define FF8 1
#define FF9 1
#define FF10 1
#define FF11 1
#define FF12 1
#define FF13 1
#define FF14 1
#define FF15 1
#define FF16 1
#define FF17 1
#define FF18 1
#define FF19 1
#define FF20 1
#define FF21 1
#define FF22 1
#define FF23 1
#define FF24 1
#define FF25 1
#define FF26 1
#define FF27 1
#define FF28 1
#define FF29 1
#define FF30 1
#define FF31 1
#define FF32 1
#define FF33 1
#define FF34 1
#define FF35 1
#define FF36 1
#define FF37 1
#define FF38 1
#define FF39 1
#define FF40 1
#define FF41 1
#define FF42 1
#define FF43 1
#define FF44 1
#define FF45 1
#define FF46 1
#define FF47 1
#define FF48 1
#define FM9 1
#define FM12 1
#define FM18 1
#define FM24 1
#define FMB9 1
#define FMB12 1
#define FMB18 1
#define FMB24 1
#define FMO9 1
#define FMO12 1
#define FMO18 1
#define FMO24 1
#define FMBO9 1
#define FMBO12 1
#define FMBO18 1
#define FMBO24 1
#define FSS9 1
#define FSS12 1
#define FSS18 1
#define FSS24 1
#define FSSB9 1
#define FSSB12 1
#define FSSB18 1
#define FSSB24 1
#define FSSO9 1
#define FSSO12 1
#define FSSO18 1
#define FSSO24 1
#define FSSBO9 1
#define FSSBO12 1
#define FSSBO18 1
#define FSSBO24 1
#define FS9 1
#define FS12 1
#define FS18 1
#define FS24 1
#define FSI9 1
#define FSI12 1
#define FSI19 1
#define FSI24 1
#define FSB9 1
#define FSB12 1
#define FSB18 1
#define FSB24 1
#define FSBI9 1
#define FSBI12 1
#define FSBI18 1
#define FSBI24 1
#endif // LOAD_GFXFF
+183
View File
@@ -0,0 +1,183 @@
#include <M5Stack.h>
#include "Free_Fonts.h"
#include <Wire.h>
#include "UNIT_ENV.h"
SHT3X sht30;
#define TFT_GREY 0x7BEF
#define DATA_LEN 32
#define X_LOCAL 40
#define Y_LOCAL 30
#define X_OFFSET 160
#define Y_OFFSET 23
uint16_t CheckSum;
uint16_t CheckCode;
// Print the header for a display screen
void header(const char *string, uint16_t color) {
M5.Lcd.fillScreen(color);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE);
M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE);
M5.Lcd.setTextDatum(TC_DATUM);
M5.Lcd.drawString(string, 160, 3, 4);
}
void setup() {
M5.begin();
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1, 16, 17);
pinMode(13, OUTPUT);
digitalWrite(13, 1);
M5.Lcd.fillScreen(TFT_BLACK);
header("P M 2.5", TFT_BLACK);
}
uint8_t Air_val[32] = {0};
int16_t p_val[16] = {0};
uint8_t i = 0;
#define FRONT 2
void LCD_Display_Val(void) {
for (int i = 0, j = 0; i < 32; i++) {
if (i % 2 == 0) {
p_val[j] = Air_val[i];
p_val[j] = p_val[j] << 8;
} else {
p_val[j] |= Air_val[i];
j++;
}
}
// M5.Lcd.setTextSize(FRONT);
M5.Lcd.setTextColor(TFT_RED, TFT_BLACK);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL, FRONT);
M5.Lcd.print("S P M");
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET, FRONT);
M5.Lcd.print("PM1.0 : ");
M5.Lcd.print(p_val[2]);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 2, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 2, FRONT);
M5.Lcd.print("PM2.5 : ");
M5.Lcd.print(p_val[3]);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 3, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 3, FRONT);
M5.Lcd.print("PM10 : ");
M5.Lcd.print(p_val[4]);
M5.Lcd.setTextColor(TFT_RED, TFT_BLACK);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL, FRONT);
M5.Lcd.print("A T M E");
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET, FRONT);
M5.Lcd.print("PM1.0 : ");
M5.Lcd.print(p_val[5]);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 2, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 2, FRONT);
M5.Lcd.print("PM2.5 : ");
M5.Lcd.print(p_val[6]);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 3, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 3, FRONT);
M5.Lcd.print("PM10 : ");
M5.Lcd.print(p_val[7]);
M5.Lcd.setTextColor(TFT_RED, TFT_BLACK);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET / 4, Y_LOCAL + Y_OFFSET * 4, FRONT);
M5.Lcd.print("Number of particles");
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 5, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 5, FRONT);
M5.Lcd.print("0.3um : ");
M5.Lcd.print(p_val[8]);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 6, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 6, FRONT);
M5.Lcd.print("0.5um : ");
M5.Lcd.print(p_val[9]);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 7, FRONT);
M5.Lcd.print("1.0um : ");
M5.Lcd.print(p_val[10]);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 5, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 5, FRONT);
M5.Lcd.print("2.5um : ");
M5.Lcd.print(p_val[11]);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 6, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 6, FRONT);
M5.Lcd.print("5.0um : ");
M5.Lcd.print(p_val[12]);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 7, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 7, FRONT);
M5.Lcd.print("10um : ");
M5.Lcd.print(p_val[13]);
}
void TempHumRead(void) {
float humd, temp;
if (sht30.get() == 0) { // Obtain the data of shT30. 获取sht30的数据
humd = sht30.cTemp; // Read Humidity
temp = sht30.humidity; // Read Temperature
} else {
humd = 0; // Read Humidity
temp = 0; // Read Temperature
}
M5.Lcd.setTextColor(TFT_GREEN, TFT_BLACK);
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 8, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * 8, FRONT);
M5.Lcd.print("T M P : ");
M5.Lcd.print(temp);
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 8, FRONT);
M5.Lcd.print(" ");
M5.Lcd.setCursor(X_LOCAL + X_OFFSET, Y_LOCAL + Y_OFFSET * 8, FRONT);
M5.Lcd.print("H U M : ");
M5.Lcd.print(humd);
}
void loop() {
if (Serial2.available()) {
Air_val[i] = Serial2.read();
Serial.write(Air_val[i]);
i++;
} else {
i = 0;
}
if (i == DATA_LEN) {
LCD_Display_Val();
TempHumRead();
}
}