Not sure if you're referring to the hat or port ENV III
but the get
method of SHT3X
didn't have the correct begin
for the ENV III
hat, so I brought the method into main and manually set up Wire.begin(25, 26)
as seen below:
#include "M5CoreInk.h"
#include "M5_ENV.h"
//SHT3X sht30;
QMP6988 qmp6988;
float tmp = 0.0;
float hum = 0.0;
float pressure = 0.0;
Ink_Sprite InkPageSprite(&M5.M5Ink);
void setup() {
M5.begin();
Wire.begin(25, 26);
qmp6988.init();
if ( !M5.M5Ink.isInit()) {
Serial.printf("Ink Init faild");
while (1) delay(100);
}
M5.M5Ink.clear(); //Clear screen.
delay(1000);
if ( InkPageSprite.creatSprite(0, 0, 200, 200, true) != 0) {
Serial.printf("Ink Sprite creat faild");
}
}
byte getVal()
{
unsigned int data[6];
// Start I2C Transmission
Wire.beginTransmission(0x44);
// Send measurement command
Wire.write(0x2C);
Wire.write(0x06);
// Stop I2C transmission
if (Wire.endTransmission() != 0)
return 1;
delay(200);
// Request 6 bytes of data
Wire.requestFrom(0x44, 6);
// Read 6 bytes of data
// cTemp msb, cTemp lsb, cTemp crc, humidity msb, humidity lsb, humidity crc
for (int i = 0; i < 6; i++) {
data[i] = Wire.read();
};
delay(50);
if (Wire.available() != 0)
return 2;
// Convert the data
float cTemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
tmp = (cTemp * 1.8) + 32;
hum = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0);
return 0;
}
void loop() {
pressure = qmp6988.calcPressure();
if (getVal() == 0) {
char buf[20];
snprintf(buf, 20, "Temp: %2.1f F", tmp);
InkPageSprite.drawString(40, 20, buf);
snprintf(buf, 20, "Humi: %2.0f%%", hum);
InkPageSprite.drawString(40, 40, buf);
snprintf(buf, 20, "Pres: %2.0f Pa", pressure);
InkPageSprite.drawString(40, 60, buf);
}
InkPageSprite.pushSprite(); //Push the sprite to the screen.
delay(1000);
}
It's pretty basic in functionality, but it works for the most part. And again, this is for the ENV III
hat.