EcoRenovator

EcoRenovator (https://ecorenovator.org/forum/index.php)
-   Geothermal & Heat Pumps (https://ecorenovator.org/forum/forumdisplay.php?f=10)
-   -   Arduino issues (https://ecorenovator.org/forum/showthread.php?t=2909)

Mikesolar 03-04-13 05:50 AM

Here is the current code which is purely a copied code from the Adafruit site "using a thermister". Then, I added the last line from Jeffs approach in bold. It seems to ignore the added code and continues to post in ohms. I am looking for a reason for this but the program doesn't come up with any errors.

Code:


// the value of the 'other' resistor
#define SERIESRESISTOR 10000   
 
// What pin to connect the sensor to
#define THERMISTORPIN A0
 
void setup(void) {
  Serial.begin(9600);
}
 
void loop(void) {
  float reading;
 
  reading = analogRead(THERMISTORPIN);
 
  Serial.print("Analog reading ");
  Serial.println(reading);
 
  // convert the value to resistance
  reading = (1023 / reading)  - 1;
  reading = SERIESRESISTOR / reading;
  Serial.print("Thermistor resistance ");
  Serial.println(reading);
 
  float logcubed = log(reading);
logcubed = logcubed * logcubed * logcubed;
float kelvin = 1.0 / (-7.5e-4 + 6.23e-4 * log(reading) - 1.73e-6 * (logcubed));
float celsius = kelvin - 273.15;

 
  delay(1000);
}


AC_Hacker 03-04-13 10:05 AM

Quote:

Originally Posted by Piwoslaw (Post 28634)
The line:
Code:

steinhart -= 273.15;
is the same as:
Code:

steinhart = steinhart - 273.15;
so this in itself is not a problem.



I think this is an illegal line... with the minus in front of the equal sign:

Code:

steinhart -= 273.15;
I you want steinhart to take the value of 273.15, you could say:

Code:

steinhart = 273.15;
I you want steinhart to take the value of -273.15, you could say:

Code:

steinhart = -273.15;
... or even:

Code:

steinhart = 273.15 * -1;
If you want to increase whatever value steinhart already has by 273.25, you could say:

Code:

steinhart = steinhart + 273.15;
If you want to decrease whatever value steinhart already has by 273.25, you could say:

Code:

steinhart = steinhart - 273.15;

& & &


The part of the program that is at the top, in other words above...

Code:

void setup()  {
... is where all variable name must be declared, or else the program will not know what the strange undefined words mean.

steinhart is a variable name and it needs to be defined as such in this section.

The middle part of the program, that is below...

Code:

void setup()  {
but above...

Code:

void loop()
Is where initial values are set... in other words, you can't assume that the first time you use steinhart that it will have a value of zero, you have to make it so.


& & & & & &


You can't expect anyone to give useful advice on a program or on what it's debugger message means unless you have quoted ALL of the program and ALL of the debugger message.

Else, you're wasting everyones time, including your own.

-AC

Piwoslaw 03-04-13 02:21 PM

Quote:

Originally Posted by AC_Hacker (Post 28640)
I think this is an illegal line... with the minus in front of the equal sign:

Code:

steinhart -= 273.15;
[...]

Compound assignment operators in C and C++

+= plus equal sign

Quote:

Originally Posted by AC_Hacker (Post 28640)
The part of the program that is at the top, in other words above...

Code:

void setup()  {
... is where all variable name must be declared, or else the program will not know what the strange undefined words mean.
[...]

I may be wrong (I haven't installed the Arduino compiler on my new computer yet, so I can't try it today), but a variable defined in setup() may not be visible in loop() since those are two distinct functions. If you want a variable to be visible in both setup() and loop(), it must be declared outside of the scope of either function, ie before the declaration of setup() (after the #define would be good).

Mikesolar 03-04-13 08:44 PM

I'm trying to recreate the sketch which i had deleted by accident. I will then post it. If I find a way around it I will post that too.

mrd 03-04-13 09:30 PM

Quote:

Originally Posted by Mikesolar (Post 28638)
It seems to ignore the added code and continues to post in ohms.

What it 'posts' is the value passed to the function Serial.println. That function name indicates you are utilizing the serial port to print a line.

The value you are passing in your new code is the same passed in the original:
Code:

  Serial.print("Thermistor resistance ");
  Serial.println(reading);

If you want to print something else you need to specify such, e.g.
Code:

float logcubed = log(reading);
logcubed = logcubed * logcubed * logcubed;
float kelvin = 1.0 / (-7.5e-4 + 6.23e-4 * log(reading) - 1.73e-6 * (logcubed));
float celsius = kelvin - 273.15;

Serial.println(celsius);

And note the correct value is placed into the variable celsius before you pass it to the Serial.println function to be displayed.

Also, you should paste the full error message you are receiving with the other code you are trying to use. Compiler errors typically indicate a line number at the beginning to help pinpoint the source of the mistake. Variable scope relates to which portions of your code may access a given variable. This scope is determined by where the variable is defined. For example, function-local scope is variables defined within a function (within the brackets { } encapsulating the function definition) whereas module/file-level scope is variables defined outside of any function, which can be accessed within any function.

I could go on and on but it sounds like you're just trying to get your feet wet and I don't want to drown you. Also, take everything I say with a grain of salt. I've never coded for the Arduino, but I am familiar with C/C++, and like to make assumptions.

jeff5may 03-04-13 10:43 PM

Thanks to all who are helping set things in the right direction. I have an arduino and have been playing with it, but my programming skills are rusty. I have very little experience programming in languages newer than say, pascal or plain old c. Sorry about my misunderstanding of abbreviated operations statements.

Mikesolar,

I know you've seen lots of those shows where a writer starts a story and changes his mind. He crumples up his paper and starts over. After the commercials, we return to the author still writing, with a basket full of crumpled up papers at his feet. He then writes his masterpiece.

This is a prime example of computer programming. Never mind the program that didn't work for the moment, you're on the right track. What code you have now is reading your thermistor and calculating ohms, kelvin and celsius. Just because those variables aren't being printed doesn't mean they don't exist. I'm guessing you will be able to serial print out any of these values at will if desired. So you have succeeded in the data acquisition phase of your program.

The next thing you want to do is figure out which method to use in averaging this raw data. A rolling average will fit into this existing code nicely, but a circular array will take some rearranging.


All times are GMT -5. The time now is 06:38 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger