HELP PLEASE with PBASIC
JoNIKaH
Posts: 12
Hey guys, I need some help with PBASIC.
I posted something a awhile ago about my project and now i stumbled onto something else
I have a SCi-BOX that uses a thermistor to read the temperature.
This is the software part that I use to read the temperature (it came with PBASIC)
The problem is that it shows me a 3 digit number. So i did some experimenting and i found out the coresponding temperatures for the 3 digits number. But i only found them for 30,40,50 ...90 degrees celsius
And after this i came to a formula :
T=4.925*e(0.0031*N)
Where : T= temperature in celsius
e=exp function
N=the number it shows (it own temp reading)
But I have no ideea how to implement this in the pbasic programming. I found out that it has no ideea what "e" or "exp" is (while Turbo pascal knows about it. ANd that it doesn`t work with decimals
And i`m desperate cause it took me hours to get to that and i found out its useless.
If you have any ideea on how i can get it to show a certain reading starting from what i know (its values for 20,30...90) I will thank you untill I die lol :P)
Thanks for reading
I posted something a awhile ago about my project and now i stumbled onto something else
I have a SCi-BOX that uses a thermistor to read the temperature.
This is the software part that I use to read the temperature (it came with PBASIC)
'{$STAMP BS2sx} '{$PBASIC 2.5} '************************************************ ' Show temperature relative value on DEBUG terminal ' ' Connect temperature sensor at SENSOR0 '************************************************ ' System I/O and constant , please do not make change SD PIN 13 ' Sci-BOX serial communication port BAUD CON 240 ' 9600bps constant CMD CON $FE ' SLCD command constant ' Custom I/O on this application SLCD PIN 7 ' Connect SLCD here! ' Variable defined VALUE VAR Word ' VALUE as SENSOR0 variable PAUSE 1000 ' Delay 1s. for pheripheral initialize SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] ' Clear SLCD screen DO LOW SD : PAUSE 1 : HIGH SD ' Break signal SEROUT SD,BAUD,[noparse][[/noparse]0] ' Request SENSOR0 SERIN SD,BAUD,[noparse][[/noparse]VALUE.LOWBYTE,VALUE.HIGHBYTE] ' Received data 2 byte to 1 word DEBUG "Read data = ",DEC4 VALUE,HOME SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,2] ' Cursor home SEROUT SLCD,BAUD,[noparse][[/noparse]"Read data = ",DEC4 VALUE] PAUSE 100 ' Delay 100ms. LOOP ' Do again
The problem is that it shows me a 3 digit number. So i did some experimenting and i found out the coresponding temperatures for the 3 digits number. But i only found them for 30,40,50 ...90 degrees celsius
And after this i came to a formula :
T=4.925*e(0.0031*N)
Where : T= temperature in celsius
e=exp function
N=the number it shows (it own temp reading)
But I have no ideea how to implement this in the pbasic programming. I found out that it has no ideea what "e" or "exp" is (while Turbo pascal knows about it. ANd that it doesn`t work with decimals
And i`m desperate cause it took me hours to get to that and i found out its useless.
If you have any ideea on how i can get it to show a certain reading starting from what i know (its values for 20,30...90) I will thank you untill I die lol :P)
Thanks for reading
Comments
The best way to handle this is to use a spreadsheet (like Excel) or some PC programming language (like Turbo Pascal) to compute a table of values for T given some N. Look through the "math" section here: www.emesystems.com for ideas. Towards the end is a worked example for converting a thermistor reading to Celsius.
The problem is that the only way i can convert a specific reading in the BStamp is with "e". But BStamp doesn`t like "e".
After comparing I need to display it and then display another message (COOLING or HEATING) and give the commands. Here is how i defined the temperatures. Will test it later to see if it works.
of course i have to insert a loop also and the rest of the program. But its the only way I could define the temperature. VALUE = the reading I get with the thermistor.
Another problem is that this converting formula differs from thermistor to thermistor and so on, therefor there are different ways to convert it.
Another way I found is to work on small intervals and eliminate the exponential, using a plain function (sorry my english and math definitions aren`t that good. I`m from Romania ;P ), but again I have to use decimals and Basic Stamp doesn`t like it also.
It only allows 16 if-then statements per loop. Why ? How am I going to do all that in a single loop ? I don`t know how to use subroutines [noparse]:([/noparse]
You may have problems with this program fitting in memory. All these IF statements and SEROUT statements take a lot of memory. It's much better to use a table of values that you create with DATA statements, then use a loop and READ statements to look up values in the table.
Something like:
"i" needs to be declared as a byte or word and "lower", "upper", and "value" need to be declared as words.
As usual, Mike is 110% right.
I'm just throwing out a simple alternate path, because many times simpler is better, especially since you say you're not proficient in PBasic. You don't need a Sci-Box to read temperature. You can get thermistors dirt cheap at an electronics supplier (I'll send you one free if you can't find one) and let any Stamp (even my beloved BS-1) read it directly. It's just a variable resistor that you can read with the RCTIME command and a capacitor, just like a photocell (plenty of examples in WAM or Robototicsw/BB). You'll get an integer value (0-255 byte or 0-32K word) for the temperature that varies with the temperature. You can calibrate the temp manually and do a curve-fitting equation for the temp range you need IF you need to display them on LCD screen. If you don't really need the LCD screen and you can live with two preset temperatures to switch your heater or cooler on, your work is greatly simplified. Of course, if that's the case, you don't even need a Basic Stamp, you could build a dedicated circuit and go fully analog with a $1 comparator like an LM339. Check out this thread: http://forums.parallax.com/showthread.php?p=690772. Depending on your situation, you might be able to use it.
A friend of mine has to generate his own power at a remote location near Gorda, CA. He has several surplus massive underground steam turbines that generate power and provide hot water for·his campground. At some point, the fancy (orig $5+) computerized control system (also surplus) that acted as a thermostat to open & close his hot water bypass valve failed. I replaced·the whole control panel·with $10 of Radio Shack parts (lm339 comparator, thermistor, pot & relay) and it has worked flawlessly for 8 years now. Simpler is usually better.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
Erco : Thanks, also but I have to use a SCi-BOX. THe whole project is around one.
It works like this :
1. I define the lowest temperature I want in the room
2. I define the highest temperature I want in the room
Both of these are done using a menu . After this I have to get the temperature from the thermistor, convert it, compare it with the low and the high and give the proper comman to the cooler or the heater. And so on ...
I did calibrate my thermistor. I went to 90degC and then back to the room temp. And i took the values at each 10 deg. I didn`t knew I wouldn`t be able to use exp or even decimals.
This is what I have done so far without Mike`s addition.
the last part was the experimental one with comparing a value and showing something on the display
I have to use this many spaces " " because again I couldn`t find a way to write something on the second line of my 16x2 LCD.
THe SCi-BOX manual doesn`t say too many things about it.