Shop OBEX P1 Docs P2 Docs Learn Events
save data in another program — Parallax Forums

save data in another program

ADAD Posts: 3
edited 2005-06-15 16:19 in BASIC Stamp
I'm using sht11 sensor to measure temp, the program below outputs data on debug window. how can I save (send) this data to another program like Text editor or Excel?

Thanks,

' =========================================================================
'
' File...... SHT11_Demo.BS2
' Purpose... Interface to Sensirion SHT11 temperature/humidity sensor
' Author.... Parallax
' E-mail.... support@parallax.com
' Started...
' Updated... 19 JUL 2003
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
' Program Description
'
' This program demonstrates the interface and conversion of SHT11/15 data
' to usable program values. This program uses advanced math features of
' PBASIC, specifically the ** operator.
'
' For detailed application information on the use and application of the
' ** operator, see Dr. Tracy Allen's web page at this link:
'
' -- http://www.emesystems.com/BS2math1.htm
'
' For SHT11/15 documentation and app notes, visit:
'
' -- http://www.sensirion.com
'
' Revision History
'
'
' I/O Definitions
'
ShtData PIN 1 ' bi-directional data
Clock PIN 0
'
' Constants
'
ShtTemp CON %00011 ' read temperature
ShtHumi CON %00101 ' read humidity
ShtStatW CON %00110 ' status register write
ShtStatR CON %00111 ' status register read
ShtReset CON %11110 ' soft reset
Ack CON 0
NoAck CON 1
No CON 0
Yes CON 1
DegSym CON 186 ' degrees symbol for DEBUG
'
' Variables
'
ioByte VAR Byte ' data from/to SHT11
ackBit VAR Bit ' ack/nak from/to SHT11
toDelay VAR Byte ' timeout delay timer
timeOut VAR Bit ' timeout status
soT VAR Word ' temp counts from SHT11
tC VAR Word ' temp - Celcius
tF VAR Word ' temp - Fahrenheit
soRH VAR Word ' humidity counts
rhLin VAR Word ' humidity; linearized
rhTrue VAR Word ' humidity; compensated
status VAR Byte ' status byte
'
' EEPROM Data
'
'
' Initialization
'
Initialize:
GOSUB SHT_Connection_Reset ' reset device connection
PAUSE 250 ' let DEBUG window open
DEBUG CLS,
"SHT11 Sensor Demo", CR,
"
", CR
'
' Program Code
'
Main:
DO
GOSUB SHT_Measure_Temp
DEBUG CRSRXY, 0, 3,
"soT...... ", DEC soT, CR,
"tC....... ", DEC (tC / 10), ".", DEC1 tC, DegSym, " ", CR,
"tF....... ", DEC (tF / 10), ".", DEC1 tF, DegSym, " "
GOSUB SHT_Measure_Humidity
DEBUG CRSRXY, 0, 7,
"soRH..... ", DEC soRH, CR,
"rhLin.... ", DEC (rhLin / 10), ".", DEC1 rhLin, "% ", CR,
"rhTrue... ", DEC (rhTrue / 10), ".", DEC1 rhTrue, "% "
PAUSE 1000
LOOP
END
'
' Subroutines
'
' connection reset: 9 clock cyles with ShtData high, then start sequence
'
SHT_Connection_Reset:
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]$FFF\9]
' generates SHT11 "start" sequence
' _____ _____
' ShtData |_______|
' ___ ___
' Clock ___| |___| |___
'
SHT_Start:
INPUT ShtData ' let pull-up take high
LOW Clock
HIGH Clock
LOW ShtData
LOW Clock
HIGH Clock
INPUT ShtData
LOW Clock
RETURN
' measure temperature
' -- celcius = raw * 0.01 - 40
' -- fahrenheit = raw * 0.018 - 40
'
SHT_Measure_Temp:
GOSUB SHT_Start ' alert device
ioByte = ShtTemp ' temperature command
GOSUB SHT_Write_Byte ' send command
GOSUB SHT_Wait ' wait for measurement
ackBit = Ack ' another read follows
GOSUB SHT_Read_Byte ' get MSB
soT.HIGHBYTE = ioByte
ackBit = NoAck ' last read
GOSUB SHT_Read_Byte ' get LSB
soT.LOWBYTE = ioByte
' Note: Conversion factors are multiplied by 10 to return the
' temperature values in tenths of degrees
tC = soT ** $1999 - 400 ' convert to tenths C
tF = soT ** $2E14 - 400 ' convert to tenths F
RETURN
' measure humidity
'
SHT_Measure_Humidity:
GOSUB SHT_Start ' alert device
ioByte = ShtHumi ' humidity command
GOSUB SHT_Write_Byte ' send command
GOSUB SHT_Wait ' wait for measurement
ackBit = Ack ' another read follows
GOSUB SHT_Read_Byte ' get MSB
soRH.HIGHBYTE = ioByte
ackBit = NoAck ' last read
GOSUB SHT_Read_Byte ' get LSB
soRH.LOWBYTE = ioByte
' linearize humidity
' rhLin = (soRH * 0.0405) - (soRH^2 * 0.0000028) - 4
'
' for the BASIC Stamp:
' rhLin = (soRH * 0.0405) - (soRH * 0.002 * soRH * 0.0014) - 4
'
' Conversion factors are multiplied by 10 to return tenths
'
rhLin = (soRH ** $67AE) - (soRH ** $83 * soRH ** $5B) - 40
' temperature compensated humidity
' rhTrue = (tc - 25) * (soRH * 0.00008 + 0.01) + rhLin
'
' Conversion factors are multiplied by 10 to return tenths
' -- simplified
'
rhTrue = (tC - 250) * (soRH ** $34) + rhLin
RETURN
' sends "status"
'
SHT_Write_Status:
GOSUB SHT_Start ' alert device
ioByte = ShtStatW ' write to status reg cmd
GOSUB SHT_Write_Byte ' send command
ioByte = status
GOSUB SHT_Write_Byte
RETURN
' returns "status"
'
SHT_Read_Status:
GOSUB SHT_Start ' alert device
ioByte = ShtStatW ' write to status reg cmd
GOSUB SHT_Read_Byte ' send command
ackBit = NoAck ' only one byte to read
GOSUB SHT_Read_Byte
RETURN
' sends "ioByte"
' returns "ackBit"
'
SHT_Write_Byte:
SHIFTOUT ShtData, Clock, MSBFIRST, [noparse][[/noparse]ioByte] ' send byte
SHIFTIN ShtData, Clock, LSBPRE, [noparse][[/noparse]ackBit\1] ' get ack bit
RETURN
' returns "ioByte"
' sends "ackBit"
'
SHT_Read_Byte:
SHIFTIN ShtData, Clock, MSBPRE, [noparse][[/noparse]ioByte] ' get byte
SHIFTOUT ShtData, Clock, LSBFIRST, [noparse][[/noparse]ackBit\1] ' send ack bit
INPUT ShtData ' release data line
RETURN
' wait for device to finish measurement (pulls data line low)
' -- timeout after ~1/4 second
'
SHT_Wait:
INPUT ShtData ' data line is input
timeOut = No ' assume no timeout
FOR toDelay = 1 TO 250 ' wait ~1/4 second
IF (ShtData = 0) THEN EXIT
PAUSE 1
NEXT
IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout
RETURN
' reset SHT11/15 with soft reset
'
SHT_Soft_Reset:
GOSUB SHT_Connection_Reset ' reset the connection
ioByte = ShtReset ' reset command
ackBit = NoAck ' only one byte to send
GOSUB SHT_Write_Byte ' send it
PAUSE 11 ' wait at least 11 ms
RETURN

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-06-13 19:36
    Exit the Stamp Editor, turn Stamp off, open Hyperterminal, capture the data to an Excel file .txt or .prn,turn Stamp on.· There will probably be a lot of garbage in the captured file, but you can clean it up in Excel./

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Need a bezel for your LCD?

    Newzed@aol.com
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-06-13 20:38
    AD:
    Parallax has just the utility for you: StampDAQ, it is an excel plugin that can be used to aquire up to 10 channels of information from your stamp. Best of all, its free!
  • ADAD Posts: 3
    edited 2005-06-14 01:19
    I have tried to use the stampDAQ but I don't know how to combine these two programs to get temp and %RH data on excel. I'd appreciate if you help me.

    Thanks
  • OrionOrion Posts: 236
    edited 2005-06-15 00:07
    For StampDAQ look at the help file for the examples (off the start menu in the parallax inc-stampdaq folder). But here is a start..
    1. Add to the last line of your "Initialize" routine:

    DEBUG CR,"LABEL,TIME,soT,tC,tF,soRH,rhLin,rhTrue",CR

    2. Relace your

    DEBUG CRSRXY, 0, 3,
    "soT...... ", DEC soT, CR,
    "tC....... ", DEC (tC / 10), ".", DEC1 tC, DegSym, " ", CR,
    "tF....... ", DEC (tF / 10), ".", DEC1 tF, DegSym, " "

    With

    DEBUG "DATA,TIME,",DEC soT,",",DEC(tC / 10), ".", DEC1 tC,",",(tF / 10), ".", DEC1 tF,","

    3. Replace your

    DEBUG CRSRXY, 0, 7,
    "soRH..... ", DEC soRH, CR,
    "rhLin.... ", DEC (rhLin / 10), ".", DEC1 rhLin, "% ", CR,
    "rhTrue... ", DEC (rhTrue / 10), ".", DEC1 rhTrue, "% "

    with

    DEBUG DEC soRH,",",DEC (rhLin / 10), ".", DEC1 rhLin,",",DEC (rhTrue / 10), ".", DEC1 rhTrue,CR

    That should get you started.
  • ADAD Posts: 3
    edited 2005-06-15 16:19
    Thank you very much, it worked.

    ·
Sign In or Register to comment.