ENV III unit on M5Stack CoreInk



  • Hi,
    Very n00b question, but how do I use the ENV III sensor on CoreInk? T
    From sample code https://docs.m5stack.com/en/unit/envIII, I tried this but UNIT_ENV.h does not exist on CoreInk

    #include "M5CoreInk.h"
    #include "UNIT_ENV.h"
    
    SHT3X sht30;
    QMP6988 qmp6988;
    

    Same #include "M5_ENV.h" does not exist either.
    Thanks.



  • Ok - I found. You have to use #include "M5_ENV.h" and include the library M5UNIT-ENV in Arduino.



  • 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.



  • @vuhn88 Good to know! I also tried last week to run an ENVII on Stamp-C3 but the "get" didn't get! So I put the code inline as you did and it worked fine, then I wrote a new library (with the proven inline code) as a function with Return (value) and that worked as well. (just completed last night!)
    The "get" is somehow the problem. Cheers!



  • As you have noticed, "Get" isn't a stand alone function instead it is used to retrieve values and so is required to be used with a function.



  • @ajb2k3 The std ENV Library works with Stamp-PICO, but not Stamp-C3.
    The GET works with PICO, not C3.
    Bringing the library code into the Arduino void loop() works for both products.
    I re-wrote the standard library to remove the GET and instead used this:
    #include <SHT3Xnew.h>
    unsigned int data[2];
    float sensor() {
    Wire.beginTransmission(0x44);
    Wire.write(0x2C);
    Wire.write(0x06);
    if (Wire.endTransmission() != 0) {
    Serial.println("not = 0 ");
    }
    delay(50);
    Wire.requestFrom(0x44, 2);
    data[0] = Wire.read();
    data[1] = Wire.read();
    delay(50);
    return ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
    }

    This Library works with both, but is just a test, only reads cTemp, ;)



  • @teastain Nice work.