とりあえず、動いた。
M5StackのサンプルコードがENV. IIではなく、旧版のENVのものしかなく、
センサーの種類が違ったので、ちょいと手間取った。
/*
note: need add library Adafruit_BMP280 & Adafruit_SHT31 from library manage
*/
#include <M5Stack.h>
#include <Adafruit_SHT31.h>
#include <Wire.h> //The SHT31 uses I2C comunication.
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
Adafruit_SHT31 sht31 = Adafruit_SHT31();
//DHT12 dht12; //Preset scale CELSIUS and ID 0x5c.
Adafruit_BMP280 bme;
void setup() {
M5.begin();
M5.Power.begin();
Wire.begin();
M5.Lcd.setBrightness(10);
Serial.println(F("ENV2 Unit(SHT12 and BMP280) test..."));
if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
Serial.print("Heater Enabled State: ");
if (sht31.isHeaterEnabled())
Serial.println("ENABLED");
else
Serial.println("DISABLED");
if (! bme.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
M5.Lcd.println("Could not find a valid BMP280 sensor, check wiring!");
while (1) delay(1);
}
M5.Lcd.clear(BLACK);
M5.Lcd.println("ENV Unit test...");
}
void loop() {
float tmp = sht31.readTemperature();
float hum = sht31.readHumidity();
float pressure = bme.readPressure() /100 ;
Serial.printf("Temperatura: %2.2f*C Humedad: %0.2f%% Pressure: %0.2fhPa\r\n", tmp, hum, pressure);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.printf("Temp: %2.1fC \r\nHumi: %2.0f%% \r\nPressure:%2.0fhPa\r\n", tmp, hum, pressure);
delay(1000);
}
0 件のコメント:
コメントを投稿