ESP32基于Arduino环境读取SHT20温湿度,显示在OLED上
#include <Stdio.h>
#include <String.h>
#include <Wire.h>
#include "SSD1306.h"
#include "uFire_SHT20.h"
uFire_SHT20 sht20;
SSD1306 display(0x3c, 32, 33);
int counter = 0;
void setup() {
Serial.begin(115200);
Wire.setPins(32,33);
Wire.begin(); // join i2c bus (address optional for master)
display.init();
sht20.begin();
}
void loop() {
sht20.measure_all();
Serial.println((String)sht20.tempC + "°C");
Serial.println((String)sht20.RH + " %RH");
Serial.println((String)sht20.vpd() + " kPa VPD");
Serial.println();
display.clear();
display.drawString(0,0, "TEMP: " + (String)sht20.tempC + "°C");
display.drawString(0,20, "HUMI: " + (String)sht20.RH + " %RH");
display.display();
counter ++;
delay(1000);
}