03-04-13, 05:50 AM | #11 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
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.. |
03-04-13, 10:05 AM | #12 | |
Supreme EcoRenovator
Join Date: Mar 2009
Location: Portland, OR
Posts: 4,004
Thanks: 303
Thanked 723 Times in 534 Posts
|
Quote:
I think this is an illegal line... with the minus in front of the equal sign: Code:
steinhart -= 273.15; Code:
steinhart = 273.15; Code:
steinhart = -273.15; Code:
steinhart = 273.15 * -1; Code:
steinhart = steinhart + 273.15; Code:
steinhart = steinhart - 273.15; & & & The part of the program that is at the top, in other words above... Code:
void setup() { 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() { Code:
void loop() & & & & & & 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... |
|
The Following User Says Thank You to AC_Hacker For This Useful Post: | Mikesolar (03-05-13) |
03-04-13, 02:21 PM | #13 | |
Super Moderator
Join Date: May 2009
Location: Warsaw, Poland
Posts: 961
Thanks: 188
Thanked 110 Times in 86 Posts
|
Quote:
+= plus equal sign 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. |
|
The Following User Says Thank You to Piwoslaw For This Useful Post: | Mikesolar (03-05-13) |
03-04-13, 08:44 PM | #14 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
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.
|
03-04-13, 09:30 PM | #15 | |
Apprentice EcoRenovator
Join Date: Feb 2010
Location: Milford, DE
Posts: 106
Thanks: 5
Thanked 9 Times in 9 Posts
|
Quote:
The value you are passing in your new code is the same passed in the original: Code:
Serial.print("Thermistor resistance "); Serial.println(reading); 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); 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. |
|
The Following User Says Thank You to mrd For This Useful Post: | Mikesolar (03-05-13) |
03-04-13, 10:43 PM | #16 |
Supreme EcoRenovator
|
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. |
The Following User Says Thank You to jeff5may For This Useful Post: | Mikesolar (03-05-13) |
|
|