Shop OBEX P1 Docs P2 Docs Learn Events
Storing String from Serial to EEPROM — Parallax Forums

Storing String from Serial to EEPROM

SteelSteel Posts: 313
edited 2005-09-02 15:15 in BASIC Stamp
I am having some trouble converting types and storing them for later use.·

I used the Data command to write information to the EEPROM:
DATA %01111111, %11000001, %00100000,··%10111111, %11000011, %11100000

Instead of having that in the code, I decided that I wanted to send the data through serial.

I created a VB.Net application to send this to the Stamp through COM1:
"!%01111111, %11000001, %00100000,··%10111111, %11000011, %11100000"· (Same as above)

I set up this code on the Stamp:

IncomingData1······· VAR···· Byte
T9600············· CON···· 84
Inverted······· CON···· $4000
SERIN 16, T9600 + Inverted, [noparse][[/noparse]WAIT("!"),IncomingData1]

-How can I format the 'IncomingData1' Variable to take a String from the ComPort instead of a Byte or word?
-How can I take the variable "IncomingData1" and store all of that information the same way I would with the "DATA" command?
-If I performed a Read, would I pull the data out of the EEPROM in the same fashion?

Any help would be appreciated.
Shaun

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-01 23:05
    Steel,

    ·· You can not input a string from the COM Port.· You can input bytes one at a time, and deal with them on the fly.· You can try getting a byte from the serial port in a loop and writing to EEPROM, but speed may be a factor.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • StampUSRStampUSR Posts: 48
    edited 2005-09-02 13:10
    What Stamp are you using?

    If it is one that supports SERIN directly to the ScratchPad ram (BS2P and up I think) you can input a string directly from SERIN in one call.

    The only 'gotcha' is the call doesn't return how much data is received. I don't have the editor in front of me but basically all you need to do is:

    First fill scratchpad with x00.

    The do the SERIN read of however many bytes the ScratchPad can hold with a timeout too. Have it go to the same place in code either way.

    Then you woud want to do something like...

    Set a byte to 0 to denote the position you are in the scratch pad.

    Then read a word from scatchpad at the position byte. If the word is 0000 loop back to the read or move on in your code as you hit the end of the received data. (Or the call timed out with no data)

    Else read a byte at position byte and write it to EEPROM. Increment the position byte by one.

    Then loop back to reaching/checking the Word from scratchpad.

    If there is the possibility of a long string being received you should also check that position byte is equal to or less then the max number of bytes the scratchpad can hold.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-02 13:55
    Actually, you can input a string serially -- you just have to tell the BASIC Stamp that it's coming (the BIN, DEC, HEX modifiers work in both directions).· By adding the BIN modifier you can rx the string; the atteched demo uses a manually-opened DEBUG window to demontrate this.· I used it with your string and it does work.· Remember that the Stamp needs to know how many bytes you're going to transmit; if the SERIN line gets long you might want to put it into a loop.

    Once you have the data, you can use WRITE to store it (you'll have to keep track of where WRITE is writing to).

    And yes, READ pulls a value from the EEPROM (again, you supply the address for READ).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 9/2/2005 2:01:39 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-02 15:11
    Okay,

    ·· I see I missed something in your original post.· I thought you were sending the data exactly as it was to be stored in the DATA statements, because of the line (Same as above).· I now·see you are actually trying to send each byte/value as 9 bytes of ASCII data representing each binary value.

    ·· I couldn't see doing that (Or a reason) so in my mind I was looking at the RAW Values of the binary bumbers and thinking, "You can only get these one byte at a time", which is true.· But the Stamp BIN modifier is converting that sequence into a single byte, which is then put into an array element.· Just out of curiosity, why send the bits as ASCII values?· Why not send the actual binary value?· You would be sending a lot less data.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-02 15:15
    I've used this strategy to input numeric values using a standard terminal program where sending the value as a single byte is difficult. There is also a NUM operator which will convert from ANY numeric format -- you just need to tell it that you're using binary (% prefix) or hex ($ prefix). For example:

    · SERIN Sio, Baud, [noparse][[/noparse]NUM myValue]

    ... will accept "32" or "$20" or "%100000" and put the 32 into myValue.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.