CodilX 0 Posted October 18, 2012 Share Posted October 18, 2012 Hi there, I'm trying to get an internal temperature reading using the follow code float temp = 0; void setup() { Serial.begin(9600); Serial.println("Temperature:"); } void loop() { temp = analogRead(TEMPSENSOR); Serial.println(temp); delay(200); } And my reading is: Temperature:322.00 324.00 323.00 323.00 323.00 324.00 What is this? How do I convert these numbers to celsius? And also, every time I try finding the brightness of my LED, it always returns nothing int BrightnessVal = digitalRead(GREEN_LED); Serial.println("Green LED brightness: " + BrightnessVal); Thanks Quote Link to post Share on other sites
mbeals 74 Posted October 18, 2012 Share Posted October 18, 2012 Do you know the temperature of your room? If those readings were in tenths of a degree (e.g. 322 = 32.2C), and there was a small calibration bias in the sensor, then they seem perfectly reasonable. No clue if that's what is going on, but you could test it out by putting it in the freezer for a minute or two. Quote Link to post Share on other sites
CodilX 0 Posted October 18, 2012 Author Share Posted October 18, 2012 The temperature is around 18.5 C, and I doubt that the temperature would rise ~14 degrees on launch and be stable, thus my question what are these numbers and how to convert them? Quote Link to post Share on other sites
olivluca 12 Posted October 18, 2012 Share Posted October 18, 2012 viewtopic.php?t=2474 CodilX 1 Quote Link to post Share on other sites
energia 485 Posted October 19, 2012 Share Posted October 19, 2012 Floats should be avoided if possible. Since the MSP430 does not have a floating point unit it need to "emulate" one which makes it very slow. The "emulation" code is about 4k. Rei Vilo has put together an excellent example for how to read the temp sensor. https://github.com/energia/Energia/blob ... er_430.ino Bare in mind that the temp sensor is not calibrated and might be of a bit. Robert CodilX 1 Quote Link to post Share on other sites
CodilX 0 Posted October 19, 2012 Author Share Posted October 19, 2012 Thanks so much, but I wonder how can the temperature be so high? It shows: 27.9 27.727.9 27.9 27.1 27.7 27.9 27.7 27.9 27.7 27.9 27.7 When the room temperature is surely not above 20C, and the LaunchPad is just booted up Quote Link to post Share on other sites
energia 485 Posted October 19, 2012 Share Posted October 19, 2012 Temperature offset error is not just a bit as I stated in the previous post. It can be significant as per MSP430x2xx user manual: The temperature sensor offset error is large. Deriving absolute temperature values in the application requires calibration. See the device-specific data sheet for the parameters." Quickest way to calibrate would be to measure your room temperature with an accurate temperature measurement device or estimate it. Then let the LaunchPad sit there running the temp sense demo for a bit. At the end of that period take average value displayed in the serial console, subtract the actual room temperature and use that as the offset in the Sketch. Robert CodilX 1 Quote Link to post Share on other sites
bobnova 59 Posted October 19, 2012 Share Posted October 19, 2012 That's closer than mine. If the formulas are correct the launchpad I'm using is off by something like 40c. Quote Link to post Share on other sites
CodilX 0 Posted October 19, 2012 Author Share Posted October 19, 2012 Thank you. I didn't realize this is almost unit specific. I'll try measuring the room temperature to get a fixed reading, and also I'll try the fridge to check if that offset is correct. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.