🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5StickC and Grove-Temperature_Sensor_V1.2

    M5 Stick/StickC
    2
    4
    5.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fsidders
      last edited by

      I bought the Grove-Temperature_Sensor_V1.2 and connected to M5StickC. I copied almost all the code from the Seedstudio page (https://wiki.seeedstudio.com/Grove-Temperature_Sensor_V1.2/#software) to convert the analog read to actual temperature, only adding the #include <M5StickC.h> and the M5.begin, but the temperature is way off and very oscillating. I am using pin 32 to read the data, Is it correct? Is it a sensor issue?

      For example, a sample output is:

      -0.34
      -2.32
      -4.34
      -2.16
      -3.89
      -4.04
      -3.42
      -5.16
      -4.42
      -4.79
      -5.24
      -5.09
      -5.38
      -6.61
      -6.40
      -5.82
      -6.96
      -6.82
      -6.96
      -6.89
      -6.96
      -7.17
      -6.96
      -8.08
      -6.96
      -6.96
      -7.94

      And the code is:

      #include <M5StickC.h>
      #include <math.h>

      const int B = 4275;
      const float R0 = 100000;
      const int PIN = 32;

      void setup() {
      M5.begin();

      Serial.begin(115200);

      }

      void loop() {

      int a = analogRead(PIN);

      float R = 1023.0/a-1.0;
      R = R0*R;

      float temperature = 1.0 / (log(R / 10000.0) / B + 1 / 298.15) - 273.15;

      Serial.println(temperature);

      delay(500);
      }

      Thanks,
      Fernando Gonzalez Sidders

      F 1 Reply Last reply Reply Quote 0
      • F
        fsidders @fsidders
        last edited by

        @fsidders I fixed the code, changed 10000 to 100000 in temperature formula, but the temperature is still off and oscillating:

        #include <M5StickC.h>
        #include <math.h>

        const int B = 4275; // B value of the thermistor
        const float R0 = 100000;
        const int PIN = 32;

        void setup() {
        M5.begin();
        Serial.begin(9600);

        }

        void loop() {

        int a = analogRead(PIN);

        float R = 1023.0/a-1.0;
        R = R0*R;

        float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet

        Serial.println(temperature);
        delay(500);
        }

        The temperature displayed now is:

        42.42
        44.15
        42.42
        42.85
        42.96
        45.96
        46.07
        44.38
        44.15
        42.74
        43.50
        42.42
        44.15
        44.49
        42.42
        45.16
        49.58
        42.85

        m5stackM 1 Reply Last reply Reply Quote 0
        • m5stackM
          m5stack @fsidders
          last edited by m5stack

          i have check the prodcut document.then i find this information, i guess this sensor need calibration:
          Nominal B-Constant: 4250 ~ 4299K

          if still can't work normal. maybe you could try to contact seeed store

          https://wiki.seeedstudio.com/Grove-Temperature_Sensor_V1.2/#specifications

          1 Reply Last reply Reply Quote 0
          • F
            fsidders
            last edited by

            I solved the issue, I am getting the correct temperature now.

            I changed the code to:

            #include <M5StickC.h>
            #include <math.h>

            const int B = 4275;
            const float R0 = 100000;
            const int PIN = 33;

            void setup() {
            M5.begin();

            Serial.begin(115200);

            }

            void loop() {

            int a = analogRead(PIN);

            float R = 4095.0/a-1.0;
            R = R0*R;

            float temperature = 1.0 / (log(R / R0) / B + 1 / 298.15) - 273.15;

            Serial.println(temperature);

            delay(500);
            }

            The correct pin was 33, and modified the 1023.0 to 4095.0 in the formula because esp32 is returning values between 0 and 4096. But anyway, the temperature readings were too high. Then, I modified the grove cable (as is explained here https://tinkerfarm.net/projects/the-m5stickc/the-5-volt-danger-with-the-m5stickc/) feeding the temperature sensor with 3.3v instead of 5v. And, now, (with no additional code changes) the temperature is correct.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post