Hi there - currently experiencing something odd when running Grove Temperature Sensor reference code on an Arduino Yun where the values are all minus only, AND fluctuate occasionally for some reason to a weird value - see below for an example of the readings:
</s>11:41:55.830 -> temperature = -72.53
11:41:55.941 -> temperature = -72.53
11:41:56.052 -> temperature = -72.53
11:41:56.124 -> temperature = -72.53
11:41:56.233 -> temperature = -72.53
11:41:56.338 -> temperature = -72.53
11:41:56.448 -> temperature = -72.53
11:41:56.559 -> temperature = -273.15
11:41:56.671 -> temperature = -273.15
11:41:56.744 -> temperature = -72.53
11:41:56.852 -> temperature = -72.53
11:41:56.961 -> temperature = -72.53
11:41:57.071 -> temperature = -72.53
11:41:57.184 -> temperature = -72.53
11:41:57.288 -> temperature = -72.53
<e>
The code that i am running on the board is as follows:
[code]
// Demo code for Grove - Temperature Sensor V1.1/1.2
// Loovee @ 2015-8-26
#include <math.h>
#include <rgb_lcd.h>
const int B = 4250; // B value of the thermistor
const int R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
rgb_lcd lcd;
const int colorR = 255;
const int colorG = 255;
const int colorB = 255;
#if defined(ARDUINO_ARCH_AVR)
#define debug Serial
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#define debug SerialUSB
#else
#define debug Serial
#endif
void setup()
{
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
lcd.print("Current Temp:");
}
void loop()
{
// read sensor data
int a = analogRead(pinTempSensor);
float R = 1023.0/a-1.0;
R = R0*R;
// set the current temperature value
float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet
// debug output of current temperature
Serial.print("temperature = ");
Serial.println(temperature);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the temperature on the LCD display:
lcd.print(temperature);
delay(100);
}
[/code]
Any ideas what is going on here? All i have added is support for LCD display which shows the same value as being output on serial console, that’s it…
Thanks in advance!