|
03-02-13, 05:34 PM | #1 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
Arduino issues
OK, even though Arduino is supposed to make us older farts equal to the young dudes in programming, I will readily admit that I am useless at it which is even more embarrassing as I was an electronics technologist 30 years ago. ARRRGGGG.
So all I am trying to do is take the Mega, and sensor shield, add a 10k thermister (2 wire, not the digital stuff that I never see in the heating industry) and see the temp change on the screen. I followed a thread on yourduino to do this and got errors that I cannot explain and it seems, I cannot even find definitions to some of the phrases given at the bottom of the page when trying to verify the program. Here is an example: "was not declared in this scope" What does that mean? I cannot find a glossary of terms used anywhere. HHHheeeellllpppp (please) |
03-03-13, 01:35 AM | #2 |
Eco OWNER!!
Join Date: Jul 2012
Location: ATL
Posts: 99
Thanks: 25
Thanked 7 Times in 6 Posts
|
I am no pro, but is this regarding a variable that was not declared initially? Do you want to post up your sketch?
__________________
In it for the money (savings) |
03-03-13, 06:10 AM | #3 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
The sketch is not important so here only because it it taken directly from the the adafruit book about how to use a thermister. I cut and paste the exact sketch from the site and voila......errors.
The phrasing doesn't have enough explanation. Here is what i tried to do: 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); delay(1000); } Then I erase this program and copy one that changes the thermister value to deg C (below) and it doesn't recognize the thermister. Code:
// which analog pin to connect #define THERMISTORPIN A0 // resistance at 25 degrees C #define THERMISTORNOMINAL 10000 // temp. for nominal resistance (almost always 25 C) #define TEMPERATURENOMINAL 25 // how many samples to take and average, more takes longer // but is more 'smooth' #define NUMSAMPLES 5 // The beta coefficient of the thermistor (usually 3000-4000) #define BCOEFFICIENT 3950 // the value of the 'other' resistor #define SERIESRESISTOR 10000 int samples[NUMSAMPLES]; void setup(void) { Serial.begin(9600); analogReference(EXTERNAL); } void loop(void) { uint8_t i; float average; // take N samples in a row, with a slight delay for (i=0; i< NUMSAMPLES; i++) { samples[i] = analogRead(THERMISTORPIN); delay(10); } // average all the samples out average = 0; for (i=0; i< NUMSAMPLES; i++) { average += samples[i]; } average /= NUMSAMPLES; Serial.print("Average analog reading "); Serial.println(average); // convert the value to resistance average = 1023 / average - 1; average = SERIESRESISTOR / average; Serial.print("Thermistor resistance "); Serial.println(average); float steinhart; steinhart = average / THERMISTORNOMINAL; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // convert to C Serial.print("Temperature "); Serial.print(steinhart); Serial.println(" *C"); delay(1000); } The problem is that the explanations are inadequate. Last edited by Mikesolar; 03-03-13 at 09:12 PM.. |
03-03-13, 09:00 AM | #4 |
Supreme EcoRenovator
Join Date: Mar 2009
Location: Portland, OR
Posts: 4,004
Thanks: 303
Thanked 723 Times in 534 Posts
|
If I understand your post, you are having problems with your sketch. So, it seems that since you are having problems with your sketch, it actually is important... especially if you want someone else to help you. The de-bugger in Arduino is not the best in the world, but it is better than nothing. Sometimes there is an error in some part of the code, and the Arduino de-bugger says it's in another place, so if you do not include your entire sketch, you are wasting everyones time.
It is easiest to see your sketch, if you put it inside CODE tags. So you would use a square brace "[" and then you would put the letters "CODE" next, and then you would put another square brace "]"... then you put your sketch, your whole sketch next... ...then you would use a square brace "[" and then you would put a slash "/" and then the letters "CODE" next, and then you would put another square brace "]". It makes your sketch stand out so that it's easier to see what went wrong. -AC
__________________
I'm not an HVAC technician. In fact, I'm barely even a hacker... |
03-03-13, 09:24 AM | #5 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
The two versions of the code are presented in their entirety above. I thought it was evident enough, perhaps not, so I will try again. I edited it again to show the square brackets. As there is 2 separate codes in the post I said "end post". This is not going in the arduino so i assume it is just for the readers benefit.
The main thing is that there is no plain english glossary that really defines the terms as presented in the debugger. I have my talents but this isn't one of them LOL. Last edited by Mikesolar; 03-03-13 at 09:33 AM.. |
03-03-13, 12:40 PM | #6 |
Supreme EcoRenovator
|
i'm no longer a programming expert, but this line looks fishy to me:
steinhart -= 273.15; // convert to C it seems you should have something like: variable = variable + constant rather than variable = constant Last edited by jeff5may; 03-03-13 at 12:43 PM.. |
03-04-13, 04:03 AM | #7 | ||
Super Moderator
Join Date: May 2009
Location: Warsaw, Poland
Posts: 961
Thanks: 188
Thanked 110 Times in 86 Posts
|
Quote:
Code:
steinhart -= 273.15; Code:
steinhart = steinhart - 273.15; As for the Quote:
If possible please give the full error message, so that we know which variable was not declared, etc.
__________________
Ecorenovation - the bottomless piggy bank that tries to tame the energy hog. |
||
03-04-13, 05:50 AM | #8 |
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, 09:30 PM | #9 | |
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:05 AM | #10 | |
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) |
|
|