Shop OBEX P1 Docs P2 Docs Learn Events
still having trouble with SHT11 Sensirion and EEPROM — Parallax Forums

still having trouble with SHT11 Sensirion and EEPROM

mellomarymellomary Posts: 3
edited 2007-03-14 16:07 in BASIC Stamp
This is Mary again.· When I try to run the suggested program with the SLEEP command, the light on my BS2 goes out (the green light under "Running").· Does this mean that the BS2 isn't running anymore?· I also tried to use the eeaddress = 0 to 1391, but when I run the READ program again, it only goes up to 252 and then starts at 0 again.· That means I can't get all the data I need.· It would only show me the data up until that point, and not any new data afterwards.· Here is the program again.· The first part is the portion of the code that shows the WRITE command.· The second part shows the program that READs the data.· thanks for your help.


'EEPROM
eeaddress VAR Byte
Initialize:
· eeaddress = 0
· GOSUB SHT_Connection_Reset····· 'reset device connection
· PAUSE 250
· DEBUG CLS,
······· "SHT11 Sensor Demo", CR,
······· "
", CR
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, "% "
··· 'FOR eeaddress = 0 TO 5760 STEP 4· I wanted to run this for 24 hours, so I did a 0·TO 5760, but I don't·think this works, so I commented it out
····· WRITE eeaddress, Word tF, Word rhTrue 'writes 4 bytes starting at eeaddress
··········· eeaddress = eeaddress + 4· '4 bytes per record
····· SLEEP 3599··"Running" light·goes out·with this command in the code
····· PAUSE 1000·for recording data every minute, i changed this to 60000 to correspond to the 0 TO 5760
··· 'NEXT·commented out
· LOOP
· END





' {$STAMP BS2}
' {$PBASIC 2.5}
tF· VAR Word
rhTrue· VAR Word
eeaddress VAR Byte
DEBUG "Retrieving Measurements", CR, CR
FOR eeaddress = 0 TO·1391 STEP 4 this does not work...it only goes up to 252 when i run it, so I know it wouldn't work if I had 0 TO 5760
· DEBUG DEC eeaddress, TAB
· READ eeaddress, Word tF
· READ eeaddress + 2, Word rhTrue
· IF rhTrue = -1 THEN EXIT···· 'this assumes that -1 marks premature END OF FILE
· DEBUG DEC3 tF, TAB, DEC3 rhTrue, CR
NEXT
END

Comments

  • DerekDerek Posts: 15
    edited 2007-03-14 01:37
    Mary,

    Im not an expert on the stamp by any means, but the power LED should not turn off when using SLEEP, is the LED off for the SLEEP duration you specified? It would seem to me that the code would restart everytime the power LED goes off and would debug the readings quickly rather then with the pause created by SLEEP.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-14 01:45
    I don't know what board you're using with the Stamp, but, on some of them, the LED will go out during SLEEP. This is part of the design to reduce power consumption during SLEEP mode.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-03-14 01:45
    Hi Mary,

    Please in general append followup questions to the original thread, which is
    http://forums.parallax.com/showthread.php?p=637747

    eeaddress needs to be a WORD. That is why it only gets up to 252. 252+4 = 256 and that is the same as zero in a BYTE variable.

    The BS2 is sleeping, but alert enough to keep track of the passage of time. There is nothing wrong with using PAUSE instead of SLEEP if you have enough power available; it is a difference of 50 microamps vs about 8 milliamps. PAUSE is in units of milliseconds, while SLEEP iis in units of seconds.

    I don't see where your LED indicator is referenced. Is it attached to a Stamp pin? Do you want it to flash briefly every few seconds indicate "Alive"?

    As Chris pointed out, it appears that the limit for data storage is 1392 bytes. You don't want it to go beyond that, otherwise it will wipe out the program (bad!). Instead of a FOR NEXT loop, I might finish off the main loop with,
    LOOP UNTIL eeaddress=1392
    END
    The program has to go around the whole DO LOOP to acquire the changing data to log in the eeprom.

    You asked in private mail how to erase the data file to start.
    Something like this at the top of the program:
    Initialize:
    FOR eeaddress=0 to 1391
      WRITE eeaddress,$ff   ' data file is initialized to all $FF
    NEXT
    Main:
    DO
     '' and so on
    



    The Retrieval routine uses a $FFFF (same as -1) to indicate a premature end of the data file, in case the experiment ends early.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • RandyRandy Posts: 79
    edited 2007-03-14 01:52
    Mary,

    I didn't read your code very carefully but the variable for the eeadress should be a word. You have it as a byte and·that can hold only 256 or 0 to 255. When the FOR NEXT adds 4 to 252 you have exceded what it can count.

    Randy
  • mellomarymellomary Posts: 3
    edited 2007-03-14 03:19
    Ok, I tried doing the FOR eeaddress = 0 to 1391, WRITE eeaddress, $ff, NEXT but I changed it to FOR eeaddress = 0 to 2048 so I could have all the room i needed. Using both ways, the debug terminal didn't display the values. And I had changed the eeaddress to a WORD, but when retrieving the data back, it only went up to 64 and not to 5067 like I hoped it would. What do you suppose is the deal with both of these issues? On a side note, I have a BS2, so it was probably designed to not turn the light on during SLEEP. I appreciate all the help with everything!
  • RDL2004RDL2004 Posts: 2,554
    edited 2007-03-14 04:06
    I think your program is mostly working right, I just think that for what you are trying to do, there isn't enough room in the Stamp's eeprom. Some of that memory space has to be used to store your program. I would look at using an external eeprom for data storage. Either an I2C or SPI type, neither is very hard to use.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-03-14 16:07
    Mary,
    You can't clear all the memory, 0 to 2047, because your program occupies a lot of that space. The program and data share the eeprom and overwriting the program is BAD! Suppose your program occupies 656 bytes in the eeprom. Then there are 2048-656 = 1392 bytes free for the data logging file. But you have to be sure that 1392 is the correct number. If you add or subtract code your the program, everything you do changes that number. Start out way on the conservative side until you get things working. Say, make the limit 800 bytes to start, 200 records.

    I changed my mind about how you should clear the memory for a new run. Since you are reloading the program each time to start a new run, use this line:
    Ndata CON 800 ' make the number of bytes reserved for the file a constant to use in the program
    DATA $FF(Ndata)
    Use that instead of the Iniitialize: routine I suggested in my previous post. The DATA syntax will initialize the data file to $ff at compile time but it will not take up space in the program and will be better overall given the way you are doing this. There are probably other ways to streamline the program here and there to leave more space for data, but not big time. The SHT11 takes that much code.

    If you really do need more room for data, take Rick's suggestion and use external eeprom, or switch to a BS2pe, which is ideal for data logging with 15 extra slots of 2k each.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.