Pages: [1]   Go Down
Author Topic: #include <math.h> not working correctly  (Read 1154 times)
0 Members and 1 Guest are viewing this topic.
Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there.

I'm trying a code found on: http://arduino.cc/playground/ComponentLib/Thermistor2
Code:
#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:
þÿÿÿÿþÿþÿÿþÿþþÿÿÿþÿÿÿþþÿÿþ
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.
Logged

Nederlands, Svenska, English

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13738
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

please use


Code:
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);
}
Logged

Rob Tillaart

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

Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bedankt Rob!

Works perfect now :-)
Code:
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);
}
Logged

Nederlands, Svenska, English

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13738
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are welcome.

(you are dutch living in Sweden?)
Logged

Rob Tillaart

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

Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 18, 2012, 06:00:06 pm by sebswed » Logged

Nederlands, Svenska, English

Pages: [1]   Go Up
Jump to: