EcoRenovator  

Go Back   EcoRenovator > Improvements > Geothermal & Heat Pumps
Advanced Search
 


Blog 60+ Home Energy Saving Tips Recent Posts Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Display Modes
Old 03-04-13, 05:50 AM   #11
Mikesolar
Master EcoRenovator
 
Mikesolar's Avatar
 
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
Default

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);
}


Last edited by Piwoslaw; 03-04-13 at 01:55 PM..
Mikesolar is offline   Reply With Quote
Old 03-04-13, 10:05 AM   #12
AC_Hacker
Supreme EcoRenovator
 
AC_Hacker's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 4,004
Thanks: 303
Thanked 723 Times in 534 Posts
Default

Quote:
Originally Posted by Piwoslaw View Post
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
__________________
I'm not an HVAC technician. In fact, I'm barely even a hacker...
AC_Hacker is offline   Reply With Quote
The Following User Says Thank You to AC_Hacker For This Useful Post:
Mikesolar (03-05-13)
Old 03-04-13, 02:21 PM   #13
Piwoslaw
Super Moderator
 
Piwoslaw's Avatar
 
Join Date: May 2009
Location: Warsaw, Poland
Posts: 960
Thanks: 188
Thanked 110 Times in 86 Posts
Default

Quote:
Originally Posted by AC_Hacker View Post
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 View Post
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).
__________________
Ecorenovation - the bottomless piggy bank that tries to tame the energy hog.
Piwoslaw is offline   Reply With Quote
The Following User Says Thank You to Piwoslaw For This Useful Post:
Mikesolar (03-05-13)
Old 03-04-13, 08:44 PM   #14
Mikesolar
Master EcoRenovator
 
Mikesolar's Avatar
 
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
Default

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.
Mikesolar is offline   Reply With Quote
Old 03-04-13, 09:30 PM   #15
mrd
Apprentice EcoRenovator
 
Join Date: Feb 2010
Location: Milford, DE
Posts: 106
Thanks: 5
Thanked 9 Times in 9 Posts
Default

Quote:
Originally Posted by Mikesolar View Post
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.
mrd is offline   Reply With Quote
The Following User Says Thank You to mrd For This Useful Post:
Mikesolar (03-05-13)
Old 03-04-13, 10:43 PM   #16
jeff5may
Supreme EcoRenovator
 
Join Date: Jan 2010
Location: elizabethtown, ky, USA
Posts: 2,428
Thanks: 431
Thanked 619 Times in 517 Posts
Send a message via Yahoo to jeff5may
Default

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.

jeff5may is offline   Reply With Quote
The Following User Says Thank You to jeff5may For This Useful Post:
Mikesolar (03-05-13)
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger
Inactive Reminders By Icora Web Design