Go Down

Topic: math was not declared (Read 298 times) previous topic - next topic

vickkk

I'm just starting to learn Arduino's and its coding but with all learning experience's I've hit a road block that i need some help. I'm been trying to do small projects to learn the process and code, currently i'm trying to use a meat thermometer and read it with the Arduino using some sample code. All was going good until i got to this line

Code: [Select]
result=Math.log(((10240000/x) - 10000));

I'm getting a "math was not declared in this scope error. My research says that i need math.h library but i can't find it. I tried defining it but it still didn't work I'm sure this is some rookie error.

UKHeliBob

Have you by any chance tried
Code: [Select]
#include <math.h>
Do you need to #include it specifically ?

Are you sure that you are trying to use the log function correctly ?

log function

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Juraj


vickkk

UKHeliBob
I did try
Code: [Select]
#include <math.h>
but this did not help. The math.h part was not the same color as the "include" either.

Juraj
I changed the line to
Code: [Select]
result=log(((10240000/x) - 10000));
and it compiled. What is the difference between the two?

AWOL

Quote
What is the difference between the two?
"Math."
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

UKHeliBob

Quote
The math.h part was not the same color as the "include" either.
Ignore the colours.

As you have discovered and as I alluded to you don't need to explicitly #include the library anyway but you do need to use the function correctly.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

vickkk

Thanks, I'm still not clear on the log after reading your link. I'll do some more research on it.

UKHeliBob

What could be clearer ?
Code: [Select]

void setup()
{
  Serial.begin(115200);
  double param, result;
  param = 5.5;
  result = log(param);
  Serial.println(result, 6);
}

void loop()
{
}
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

vickkk

My apologies, this is all new and I'm trying to learn. I do appreciate all the help and positive direction I get along the way.

westfw

Are you trying to covert code from some other language?  "Math.log()" looks to be mostly a Javascript or Python syntax.
The C/C++ syntax would be more like "Math::log()", except that C/C++ is so old a language that math functions are shoved in at the "top level" of the namespaces, so it's just "log()"
(In this case "Math" is known as a 'namespace' that groups a bunch of similar functions, and prevents their names from conflicting with similar names that do something entirely different (say: "TinkerToyGraphics.log(length, diameter)")  "Modern Languages" are big on using this concept as they embrace a broad range of "things."   But C is not a "modern language", and (mathematical) log() is a standard C function.)


odometer

What do logarithms have to do with reading a meat thermometer?

edgemoron

#11
Aug 13, 2017, 03:50 am Last Edit: Aug 13, 2017, 04:02 am by edgemoron
Maybe a thermistor and the Steinhart - Hart equation?
https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation
And this library:
https://github.com/panStamp/thermistor

vickkk

Thanks Westfw, that's helpful and makes some sence. Like is said, i'm trying to learn but it didn't look familiar. The post that i was using as a guide is here-
 
https://www.safaribooksonline.com/blog/2013/07/25/an-arduino-powered-bbq-thermometer/

westfw

Quote
https://www.safaribooksonline.com/blog/2013/07/25/an-arduino-powered-bbq-thermometer/
It looks to me like that particular example is a javascript host-side example talking to a Firmata sketch running on the arduino hardware.  Huh.  I just mentioned Firmata in another thread - it's a special purpose sketch/protocol that runs on both the arduino and the host (PC) that lets a host program (written in any number of languages) access the arduino hardware in ways that are similar to running code on the arduino itself (digitalWrite(), and etc.)


vickkk

That explains why it wasn't looking familiar. That's ok, it did give me enough structure and guidance to get it done and learn a little more.

Thanks for the great feedback.

Go Up