HELP PLEASE with PBASIC
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:
table data word 430, word 444, word 457, word 470, word 484, word 498, word 511, word 537 data word 551, word 565, word 583, word 593, word 603, word 613, word 623, word 634 data word 644, word 656, word 678, word 690, word 696, word 702, word 708, word 714 data word 721, word 729, word 737, word 746, word 754, word 762 data word -1 ' marks end of table read table, word lower i = table + 2 tryNext: read i, word upper if upper = -1 then goto notFound if (lower <= value) and (value <= upper) then goto foundIt lower = upper i = i + 2 goto tryNext notFound: serout sled, baud, [noparse][[/noparse]"Invalid value"] goto doItAgain foundIt: serout sled, baud, [noparse][[/noparse]"T ", dec3 value, "/ ", dec2 i, " gr.C"] goto doItAgain"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.
'{$STAMP BS2sx} '{$PBASIC 2.5} BAUD CON 240 CMD CON $FE SLCD PIN 7 SWITCH1 PIN 0 SWITCH2 PIN 1 SWITCH3 PIN 2 SD PIN 13 Tmin VAR Word Tmax VAR Word T VAR Word VALUE VAR Word INCALZIRE VAR Word RACIRE VAR Word PAUSE 1000 SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,2] ' Cursor home Tmin=0 Tmax=Tmin SEROUT SLCD,BAUD,[noparse][[/noparse]"Tmin = ",DEC2 Tmin," gr.C "," Tmax = ",DEC2 Tmax, " gr.C"] 'Reglare Tmin si Tmax' DO IF SWITCH1=1 THEN Tmin=Tmin+1 Tmax=Tmin PAUSE 250 SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,2] SEROUT SLCD,BAUD,[noparse][[/noparse]"Tmin = ",DEC2 Tmin," gr.C "," Tmax = ",DEC2 Tmax, " gr.C"] ELSEIF SWITCH2=1 THEN Tmax=Tmax+1 PAUSE 250 SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,2] SEROUT SLCD,BAUD,[noparse][[/noparse]"Tmin = ",DEC2 Tmin," gr.C "," Tmax = ",DEC2 Tmax, " gr.C"] ENDIF IF (SWITCH3=1) THEN EXIT LOOP PAUSE 1000 SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] DO PAUSE 1000 SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] LOW SD : PAUSE 1 : HIGH SD SEROUT SD,BAUD,[noparse][[/noparse]0] SERIN SD,BAUD,[noparse][[/noparse]VALUE.LOWBYTE,VALUE.HIGHBYTE] DEBUG "Read data = ",DEC4 VALUE,HOME IF (VALUE>500)AND(value<520) THEN T=27 SEROUT SLCD,BAUD,[noparse][[/noparse]"T = 27",DEC2 T," gr.C "] ENDIF IF (VALUE>520)AND(value<540) THEN T=28 SEROUT SLCD,BAUD,[noparse][[/noparse]"T = 28",DEC2 T," gr.C "] ENDIF IF T<Tmin THEN SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,2] ' Cursor home SEROUT SLCD,BAUD,[noparse][[/noparse]"T = ",DEC2 T," gr.C "," RACIRE"] ELSE IF T>Tmax THEN SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,1] SEROUT SLCD,BAUD,[noparse][[/noparse]CMD,2] SEROUT SLCD,BAUD,[noparse][[/noparse]"T = ",DEC2 T," gr.C "," RACIRE"] ENDIF ENDIF LOOPthe 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.