Go Down

Topic: #include <math.h> not working correctly (Read 1 time) previous topic - next topic

sebswed

Hi there.

I'm trying a code found on: http://arduino.cc/playground/ComponentLib/Thermistor2
Code: [Select]

#include <math.h>

double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;            // Convert Kelvin to Celcius
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
return Temp;
}

void setup() {
Serial.begin(115200);
}

void loop() {
Serial.println(int(Thermister(analogRead(0))));  // display Fahrenheit
delay(100);
}


I have no errors during compiling.
My serial monitor gives me some nice Icelandic? symbols:
Code: [Select]
þÿÿÿÿþÿþÿÿþÿþþÿÿÿþÿÿÿþþÿÿþ
In my compiler #include <math.h> is not colored orange.

My system spec.
OS: Linux Ubuntu 11.10
Compiler: Arduino 0022ubuntu0.1

Does the message in my serial monitor mean that math.h is not installed on my comp?
If this is the case, does someone know how I get this file installed in the correct directory?

Kind regards.
Nederlands, Svenska, English

robtillaart


The message in the IDE means that you
- have set the wrong baudrate
- or get binary data

please use


Code: [Select]
void loop()
{
Serial.println(Thermister(analogRead(0)), 2);  // float with 2 decimals, you can use 0,1,2,3, ...decimals
}

or if you want to have ints

void loop()
{
Serial.println( int(Thermister(analogRead(0))), DEC);  // if you don't add the DEC flag the int mught be interpreted as char
delay(100);
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

sebswed

Bedankt Rob!

Works perfect now :-)
Code: [Select]

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

void loop() {
Serial.println(Thermister(analogRead(0)), 2);  // float with 2 decimals, you can use 0,1,2,3, ...decimals
delay(100);
}
Nederlands, Svenska, English

robtillaart

You are welcome.

(you are dutch living in Sweden?)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

sebswed

#4
Mar 18, 2012, 11:58 pm Last Edit: Mar 19, 2012, 12:00 am by sebswed Reason: 1
Ja, helemaal correct, en getrouwd met een belgische uit walonie :-)
Maar omdat mijn ik geen Frans spreek en walonen geen Nederlands is het thuis in het Engels.
Nederlands, Svenska, English

Go Up