Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT to send strings, rather than bytes, from EEPROM DATA — Parallax Forums

SEROUT to send strings, rather than bytes, from EEPROM DATA

xanatosxanatos Posts: 1,120
edited 2011-11-21 14:16 in BASIC Stamp
Hi there,

I'd like to be able to send a string to a device using the SEROUT command. I've been doing so quite successfully using

SEROUT pin, baud [CR, "some string stuffed in here", CR]

But I'm wanting to store larger strings in EEPROM. Problem is that those strings read back byte by byte, and so rather than the string I want flowing smoothly, it comes out a character at a time.

I know I can use an array with the STR command ( STR myArray\10 for example), but the array would need to be partitioned to 60 bytes, which of course is far too huge for the EEPROM, and intuitively, it just feels wrong... :-)

So - the question is, is there a way to output a DATA string read in from EEPROM, using the SEROUT command, where the strings can be as long as 60 characters?

Ultimately I will want to do this with an external EEPROM such as the 24LC32A. I am using the BS2SX, but can also use the BS2P40.

Ideas?

Thanks,

Dave

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-02 17:58
    There is no built-in way to do it. You have to process the string itself, character by character. For example, you might have this loop:
    loop:
    READ addr, temp
    addr = addr + 1
    if temp = 0 then return
    SEROUT pin,mode,[temp]
    GOTO loop
    
    This would be called as a subroutine with the EEPROM address of the string in "addr".
  • xanatosxanatos Posts: 1,120
    edited 2011-05-02 18:12
    That's what I thought. For this application I guess I'm just stuck with a limited number of strings as embedded SEROUT lines in a SELECT CASE listing. I've started up on my V-Stamp speech project after being too busy for the last year...

    Here's a snippet of the code I'm using now:

    IF CTS = 0 THEN

    SELECT cmd
    CASE 0
    SEROUT VTX, Baud, [CR, "System initialized and online.", CR]
    CASE 1
    SEROUT VTX, Baud, [CR, "Guydance systems initializing.", CR]
    CASE 2
    SEROUT VTX, Baud, [CR, "Guydance systems online.", CR]
    CASE 3
    .........

    Gotta love the creative spelling required! :-)

    The problem is that as the message count increases, the space available for the program decreases.

    I'm thinking that this project may require a dedicated stamp for just the messaging system, with another stamp or propeller actually running the show. Unless you have a brainstorm... :-)

    Thanks for your input,

    Dave
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-02 20:41
    If you use a BS2p series module, you'd have use of the STORE statement which allows a program in one slot to reference data in another slot. That way you'd have a table at the start of the message slot which would consist of a series of words, each with the offset from the start of the slot of the start of the message that goes with that number. The message ends with a zero byte and the next message starts with the next byte. It's really easy to write a subroutine that takes a message number, looks up the offset, and outputs the message. If you want to use an external EEPROM for the table and messages, it's similarly straightforward. You'd be better off with an SPI EEPROM rather than an I2C one because the BS2 and BS2sx doesn't have built-in I2C support. The easiest thing is to use a BS2p series module and the Stamp Editor can load up the other slots for you.
  • xanatosxanatos Posts: 1,120
    edited 2011-05-03 10:18
    OK, IGNORE EVERYTHING BELOW HERE! :-) The last few lines reflect me coming upon the light of understanding. It wasn't the limitation of the EEPROM data delivery, it was my method of delivering the data to the module from the EEPROM. The EEPROM data itself needs the prefix and suffix data strings. Moreover, the codes are compatible: $00 and $AA.

    THANKS MIKE! You got me thinking! :-)

    Now I can store wads of strings off-chip on an external EEPROM like I was originally wanting, and save the BS2's EEPROM for program code!

    '
    [ Previous thinking that led to my enlightenment ]

    That's a cool function and since I have a few BS2P40s sitting around looking for work, I will play with that - but the issue of the characters being delivered as bytes vs. strings still exists with this method, am I correct in that?

    Basically, looping through EEPROM DATA with a string stored as "Testing", for example, yields, on SEROUT to the V-Stamp, the speech "t, e, s, t, i, n, g", whereas the same string delivered directly within the SEROUT line yields the speech "testing".

    What I can't figure is why I was able to store speech phrases in EEPROM with the old EMIC module, and loop through them and have it actually speak the phrase, identically to the speech generated if the same phrase was included directly within the SEROUT command to the EMIC.

    Unless there's some oddity about how I am storing the phrases in EEPROM... The Emic had everything stored prefixed with the constant "say", which was $00, and suffixed with EOM ($AA):

    Phrase0 DATA Say, "System ready. ", EOM

    In the case of the EEPROM data for the V-Stamp, I was using just the phrase itself in the EEPROM:

    Phrase0 DATA "System initialized and online"

    And in the looping structure, the SEROUT command was structured to contain the requisite functionalities:

    SEROUT VTX, Baud, [CR, char, CR]

    Where char is the character indexed by eePntr...

    I'll be playing with all this later this evening, hopefully I can get it figured out soon, but I can survive if I need to dedicate a stamp for speech operations...

    Thanks again,

    Dave
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-03 10:31
    The only difference between using SEROUT with one or more literal strings and a string stored in a separate EEPROM, is timing. Using a single SEROUT takes less time than outputting the same characters as I've shown earlier. See this website for information on statement timing (click on app-notes).
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-05-03 10:46
    I think the whole phrase, not individual chars, should be framed by the CR:
    phrase:
      SEROUT VTX, Baud, [CR]
      DO
        READ idx, char
        IF char=0 THEN EXIT
        SEROUT VTX,Baud,[char]
        idx = idx + 1
      LOOP
      SEROUT VTX, Baud, [CR]
      RETURN
    
  • xanatosxanatos Posts: 1,120
    edited 2011-05-03 11:24
    It turns out to be similar- the data prefixes & suffixes needed to be included in the EEPROM DATA like it was on the Emic module. Here's the DATA format:

    Phrase0 DATA 00, "System initialized and online.", CR

    Here's the SEROUT generation:

    DO
    READ eePntr, char
    PAUSE 10
    SEROUT VTX, Baud, [char]
    eePntr = eePntr + 1
    LOOP UNTIL (char = CR)
    PAUSE 50

    I currently have 30 (relatively long) phrases in EEPROM and that occupies a little under 40% of EEPROM, with program code being about 10% of that. These being just demo phrases for development, the actual phrases will likely be shorter, and I really don't need much more than 50 or 60 phrases max. This is working quite well now, thanks everyone for your input and willingness to look at my questions and contribute your ideas.

    Dave
  • FalconFalcon Posts: 191
    edited 2011-11-21 04:51
    xanatos wrote: »

    Ultimately I will want to do this with an external EEPROM such as the 24LC32A.

    Dave

    Dave,
    Did you ever code this to use the external EEPROM? I looked over the most recent 3-Slot code for your Home Automation System but didn't any reference to an external EEPROM.

    I have a number of SEROUT text string phrases I would like to save to a 24LC16B but am not sure about how to get them to it without taking up a lot of BS2 EEPROM space in the process. Won't the I2COUT code with the various phrases use up a lot of memory in the process of being sent to the EEPROM?

    As far as the external EEPROM address for each phrase, would I just find the longest phrase and increment the address variable that number of bytes each time to keep it simple?

    falcon
  • xanatosxanatos Posts: 1,120
    edited 2011-11-21 14:16
    Wow... blast from the past! I have been offline with my home automation system since a) the tornado hit and b) I got swamped with design contracts... I *WILL* be revisiting the home automation system soon as I have a number of new developments I wish to add (including keyboard input for setting time/date and other items without needing to hook up the laptop!)... I have also found some ways to use a BS2px to create a "flat" EEPROM which may eliminate the need for an external EEPROM (STORE command). It is a project that is constantly evolving, even when I am not "directly" working on it. The ultimate goal is to replicate the function of the Star Trek Enterprise "D" computer... :-)

    I tend to "cycle" on these projects, and what I have up here historically so far is version 1.0. Version 2.0 will blow 1.0 away. Leveraging the power of the BS2px and the Spinnerett web server will be a quantum leap over v 1.0. I can only imagine what the Propeller versions will be like! :-)

    Best,

    Dave
Sign In or Register to comment.