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