Shop OBEX P1 Docs P2 Docs Learn Events
Extracting Digits from SERIN — Parallax Forums

Extracting Digits from SERIN

HitmanHitman Posts: 5
edited 2007-02-15 00:41 in BASIC Stamp
Hello I have (again) A problem with teh BS2.

I want to extract two digits from 'sdata' (see example)

SERIN 9, 396,[noparse][[/noparse]STR sdata\8]

I have used '' sdata(0) " and " sdata(1) " but I want them together in one nibble.

E.g. the 'sdata\8' is a date (for example 12-12-07) I want the day so I can compare it with another day·this comes from a DS1302 RTC.

When I use sdata(0)+sdata(1) it just increases. Same as sdata(0+1).
I have looked in the stamp manual but I can't find anything.


Thanks in advance


[noparse][[/noparse]Subject added by Moderator]

Post Edited By Moderator (Chris Savage (Parallax)) : 2/7/2007 9:08:58 PM GMT

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-02-08 17:59
    Hi Hitman, Str sdata\8 stores the serial input as an ASCII string 8 bytes long. To arrive at the digit·each ASCII·byte represents you must subtract 48. The the left digit multiplied by 10 plus the right digit of each field will give you the number you require. Here is an example of one way to do it and it assumes that sdata is in the format you show, eg 12-12-07.

    sdata VAR Byte(8)
    Month VAR Byte
    Day VAR Byte
    Year VAR Byte

    main:

    · DEBUGIN STR sdata\8
    · Month=((sdata(0)-48)*10) + (sdata(1)-48)
    · Day=((sdata(3)-48)*10) + (sdata(4)-48)
    · Year=((sdata(6)-48)*10) + (sdata(7)-48)
    · DEBUG ? Month,? Day,? Year
    · DEBUG "Month + Day = ",DEC month + day

    GOTO main

    Jeff T.
  • HitmanHitman Posts: 5
    edited 2007-02-09 16:33
    Hi Unsoundcode, I will try this tonight. But so far looks great.

    Thanx.

    Emile T.
  • iramseyiramsey Posts: 12
    edited 2007-02-10 18:25
    Hi,

    I have question pertaining to logging data from a gps string. My problem now is verifying that the string is actually stored in the EEprom. I am trying to pull out the·characters 10-16·of the string. The problem with GPS is that it only works outside, therefore my program only has write instructions in it. Can anyone give me a suggetion on how I would verify that this data was actually stored.

    //my code
    ' {$STAMP BS2}
    sio···· CON·· 6
    gps···· VAR·· Byte(7)
    eeAddr· VAR·· Byte(7)
    samples CON·· 5
    log···· DATA· 5
    endLog· CON·· log+samples-1
    SERIN 6, 188, [noparse][[/noparse]WAIT("GPRMC,"), SKIP 8, STR gps\7]

    FOR eeAddr = log TO endLog
    WRITE eeAddr, gps
    PAUSE 30000
    NEXT
    STOP
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-10 18:36
    You can read it back with a READ statement and compare byte by byte to the value still in "gps".
  • iramseyiramsey Posts: 12
    edited 2007-02-14 15:46
    thanks for the advice. only problem is that I must first run the write program, then take the gps reciever outside to collect me data. I then must bring it back inside to run the read program. won't this wipe away the data the I stored from having gone outside?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-14 15:59
    You can easily use the same program for both parts if you have an unused I/O pin. Just use a switch or jumper to connect the pin through a 10K resistor to either ground or +5V. At the beginning of your program, check the pin. If it's high, go do the write routines. If it's low, go do the read routines.

    Unless the program is very large, it won't affect the low end of program memory when it's downloaded.
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-02-15 00:41
    SERIN 9, 396,[noparse][[/noparse]DEC2 Month,SKIP 1, DEC2 Day,SKIP 1,DEC2 Year]

    but I would add a WAIT to synch better with the data:

    SERIN 9, 396,[noparse][[/noparse]WAIT ("!"),DEC2 Month,SKIP 1, DEC2 Day,SKIP 1,DEC2 Year]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR
Sign In or Register to comment.