Shop OBEX P1 Docs P2 Docs Learn Events
EEPROM to store SEROUT data? — Parallax Forums

EEPROM to store SEROUT data?

FalconFalcon Posts: 191
edited 2011-11-22 16:48 in BASIC Stamp
My Home Monitor project is exploding with SEROUT commands that are starting to put a squeeze on my onboard memory space. I have 16 sensors that are read, and based on the condition of each, the following peripheral devices are used:

4x20 Serial LCD – displays all condition changes
SEROUT LCDPin, LCDBaud, [LcdCLS, Line0, "GARAGE DR CLOSED"]

DEBUG – displays all condition changes
DEBUG "GARAGE DR CLOSED "

PINK Web Server (to update variables) – updated for all condition changes
SEROUT TX, Baud, ["!NB0W01:100", CLS]
SEROUT TX, PINKBaud, ["!NB0W21:CLOSED", CLS, ",", "!NB0W20:", CLS]
SEROUT TX, PINKBaud, ["!NB0W20:", CLS]
SEROUT TX, PINKBaud, ["!NB0W60:", HEX2 month, "/", HEX2 date, "/", HEX2 year," ", HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs, CLS]

PINK Web Server (to send email) – sends email for critical condition changes
SEROUT TX, PINKBaud, ["!NB0SM",CLS, “,”,"!NB0WES:GARAGE DOOR OPEN", “,” , CLS, “,” ,"!NB0ST"]
SERIN RX, PINKBaud, 1000, TIMEOUT, [nbvar]


The SEROUT commands to the PINK are text statements surrounded by quotation marks and are separated using delimiting. Can these text statements in the above SEROUT commands be stored in EEPROM (either onboard a BS2px or on an external 24LC128) and then retrieved using the READ command and placed in the SEROUT statement only when required? Would they then only need to be separated by commas?

falcon

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-10-06 10:17
    Yes, that is the way to go to save a lot of space. Each string needs to be terminated with a null, ascii zero. And it takes a little player subroutine, something like the following:
    index = garage_door
    ' enter with index pointing to start byte address of the string, and set for the slot in which it resides
    player:
      DO 
        READ index,char
        IF char = 0 : EXIT
        SEROUT TX,baud,[char]
        index = index + 1
      LOOP
    
    garage_door   DATA "GARAGE DR CLOSED",0
    
  • FalconFalcon Posts: 191
    edited 2011-10-07 04:32
    Thank you Tracy,

    I'll give that a go.

    falcon
  • FalconFalcon Posts: 191
    edited 2011-11-08 16:58
    I''ve been using with this code on a BS2 to get the bugs worked out before I place it into my bigger program. I'm really struggling with the whole EEPROM thing. I've read the BSM sections on READ, WRITE, DATA and STORE but it just isn't all clicking together for me. Can anyone help me with a few questions? I will use the term "string" although I know that PBasic does not use strings but rather Arrays.

    1. So far I have this code working to write a text string into the onboard EEPROM and read it back
    strAddr         VAR     Word
    char            VAR     Byte
    
    
    Phrase0         DATA    "Garage Door Closed.", 0, CR
    
    Main:
      strAddr = Phrase0                        ' set to start of message
      GOSUB String_Out
      END
    
    String_Out:
      DO
        READ strAddr, char                  ' read byte from EEPROM
        IF (char = 0) THEN EXIT             ' if 0, exit routine
        DEBUG char                          ' otherwise print char
        strAddr = strAddr + 1               ' point to next character
      LOOP
      RETURN
    

    I was looking at some code written by Xanatos where he used the following DATA statement format. He was writing 30+ strings to EEPROM
    Phrase0         DATA    00, "System Initialized and Online.", CR
    Phrase1         DATA    00, "Command completed", CR
    Phrase2         DATA    00, "Outside Water, ", CR
    

    I saw the following code in the BSM to specify the EEPROM location to write a variable using the "@" symbol:
    DATA @100, 0 (20)
    

    What is the difference between using the 00 after DATA, and using the "@" symbol? Does it have to do with multiple READ statements? Since I'm using
    SYMBOLS for each text string I guess I don't have to use the "@" symbol to specify the location. Is that correct?

    2. Do I need to keep track of the EEPROM location for each of the statements for any reason? Or will the SYMBOL be all I need know?

    3. How would I use the "player routine" to write a line of code like the following with multiple text strings in it?
    SEROUT TX, PINKBaud, ["!NB0W21:CLOSED", CLS, ",", "!NB0W20:", CLS] 
    

    I suppose I would start out by placing the individual strings into DATA statements like this:
    PINK0         DATA    "!NB0W21:CLOSED", 0, CR
    PINK1         DATA    "!NB0W20:", 0, CR
    

    How would I then use the player routine to get those two strings into the SEROUT statement shown above?

    I will ultimately store all of my text strings on a 24LC16B connected to a BS2PX24 using the I2C protocol. Will the same general approach apply?

    I appreciate any and all replies. I'm sure I'll have more questions but I want to start with this small snippet and understand it before I just throw it into a bigger program.

    falcon
  • FalconFalcon Posts: 191
    edited 2011-11-09 16:12
    I thought I was on to something but the quotation marks are throwing me for a loop (no pun intended). I planned to break the following line of code up into the individual phrases and send them to the EEPORM.
    SEROUT TX, PINKBaud, ["!NB0W21:CLOSED", CLS, ",", "!NB0W20:", CLS]
    
    The difficult part is "reassembling" it along with the CLS commands and the delimiting commas.

    I then though I could just treat the entire contents inside the brackets as one long text string, and send it to the EEPROM. The problem with that is the DATA statements require the data to be inside a set of quotation marks(""), AND, in this case, the PINK module also requires the data to be inside a set of quotation marks. So the following line of code will not compile with the two quotation marks at the beginning.
    [code]
    PINK0 DATA ""!NB0W21:CLOSED", CLS, ",", "!NB0W20:", CLS"

    I did, however, answer my own question 1. The 00 before(and the CR after) the data is required by the V-Stamp module. So I don't need to worry with that until I start integrating my V-Stamp.

    Anyone know a work-around?

    falcon
  • ercoerco Posts: 20,256
    edited 2011-11-09 17:09
    A related warning about writing to EEPROM: http://forums.parallax.com/showthread.php?81846-still-trying-to-store-data-to-eeprom&p=559347&viewfull=1#post559347

    It is possible to "wear out" an EEPROM location by writing to it continuously. I have heard life estimates of a half-million times to several million write cycles. Not normally a problem unless you inadvertently get into an endless loop (check that GOTO thread!) that keeps writing to the same location a thousand times each second.
  • FalconFalcon Posts: 191
    edited 2011-11-09 17:56
    erco,

    I read that thread earlier today while researching but I don't see that going on here. Did you mean that as a general warning, or were you refering to a specific bit of my code?

    falcon
  • ercoerco Posts: 20,256
    edited 2011-11-10 02:12
    Just a gentle and general reminder. :)
  • FalconFalcon Posts: 191
    edited 2011-11-11 18:23
    A bit more progress...
    I decided to try using ASCII characters to write the entire string to EEPROM, and then READ it out and use it to update the PINK. I came up with this:
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    strAddr         VAR     Word
    char            VAR     Byte
    
    RX              PIN     14                                           'PINK Serial Receieve Pin
    TX              PIN     15                                           'PINK Serial Transmit Pin
    
    PINKBaud        CON     1646
    
    
    Phrase2         DATA    34,33,78,66,48,87,50,50,58,67,76,79,83,69,68,34,44,67,76,83,0         ' "!NB0W22:CLOSED",CLS
    
    
    Main:
      strAddr = Phrase2                        ' set to start of message
      GOSUB String_Out
    SEROUT TX, PINKBaud, [char]
      END
    
    String_Out:
      DO
        READ strAddr, char                  ' read byte from EEPROM
        IF (char = 0) THEN EXIT             ' if 0, exit routine
        DEBUG char                          ' otherwise print char
        strAddr = strAddr + 1               ' point to next character
      LOOP
      RETURN
    
    I'm getting the following on the DEBUG screen:
    "!NB0W22:CLOSED",CLS

    ...but the PINK variable 22 is not updating.

    I know the following line of code works because the PINK updates fine when this line is used as is (without being sent to, and read from EEPROM).
    'SEROUT TX, PINKBaud, ["!NB0W22:CLOSED", CLS] 
    

    My immediate goal is to save this, and many other, long text strings to EEPROM to free up some program space. Long term goal is to write these strings to an external EEPROM.

    falcon
  • FalconFalcon Posts: 191
    edited 2011-11-21 18:20
    Still trying to figure this out.

    I switched to trying to use the external EEPROM 24LC16B with the following code to write a simple phrase.
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    
    
    SDA             PIN     0               ' I2C SDA pin
    SCL             PIN     1               ' I2C SCL pin
    LcdPin          PIN     13
    
    addr            VAR     Word            ' internal address
    char            VAR     Byte
    
    LCDBaud         CON     396
    char = 65
    addr = 5
    
    Write_To_EEPROM:
    
    
        I2COUT SDA, $A0 , addr, ["Garage", 0]
    '    I2COUT sda, $A0, addr, [71, 65, 82, 65, 71, 69, 32, 68, 79, 79, 82, 48]          'tried this but still not working
        PAUSE 50
    
    DEBUG "OK", CR
    
    
    
    
    READ_From_EEPROM:
    
      DO                                    ' Start Of LOOP
        I2CIN SDA, $A1,  addr, [char]
     PAUSE 50
       SEROUT LCDPin, LCDBaud, [char]
    PAUSE 50
        IF char = 0 THEN EXIT              ' Check For End Of String
    
    DEBUG char, CR
         addr = addr + 1                   ' Increment Index (Offset)
      LOOP
    
    
    END
    

    Can anyone help get this snippet working so I can keep this project moving?

    Thanks,

    falcon
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-11-21 22:48
    In the code for post #9, the instruction to send the chars to the PINK has to be inside the String_out loop. As it is, it only sends the final char that happens to be there when the subroutine returns.


    SEROUT TX, PINKBaud, [char] '<-- this goes inside the String_out loop

    In the newest post, what is it that doesn't work? What happens?
  • FalconFalcon Posts: 191
    edited 2011-11-22 04:48
    Thank you for replying Tracy,

    As written, the DEBUG screen returns the following (without the text in the parenthesis):
    ÿ
    ÿ
    ÿ
    ÿ
    ÿ (this character is displayed ~ 60 times)
    € (I then get this character one time)
    ÿ (then this character is displayed another ~60 times.



    In the extended ASCII table, the character ÿ is a DEC159 or HEX 9F, and the € is DEC 128 or HEX 80

    I do not get any characters on the LCD screen.

    I'm using the I2CIN circuit from the BS Syntax and Reference Manual page 219.

    The LCD works fine when I load a different program that uses it


    falcon
  • FalconFalcon Posts: 191
    edited 2011-11-22 16:48
    Tracy,
    I put that SEROUT statement inside the String_out loop and it is now writing to the PINK.
    I also had to remove the ",CLS part of the DATA statement because that was being written to the PINK too.
    All is now good regarding writing from the BS2px EEPROM to the PINK.
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    strAddr         VAR     Word
    char            VAR     Byte
    
    RX              PIN     14                                           'PINK Serial Receieve Pin
    TX              PIN     15                                           'PINK Serial Transmit Pin
    
    PINKBaud        CON     1646
    
    Phrase2         DATA    34,33,78,66,48,87,51,51,58,67,76,79,83,69,68,0         ' "!NB0W33:CLOSED",CLS
    
    Main:
      strAddr = Phrase2                        ' set to start of message
      GOSUB String_Out
    SEROUT TX, PINKBaud, [char]
      END
    
    String_Out:
      DO
        READ strAddr, char                  ' read byte from EEPROM
        IF (char = 0) THEN EXIT             ' if 0, exit routine
        DEBUG char                          ' otherwise print char
    PAUSE 100
    SEROUT TX, PINKBaud, [char]
        strAddr = strAddr + 1               ' point to next character
      LOOP
      RETURN
    

    Now, to get this to the external 24LC16B...

    falcon
Sign In or Register to comment.