Shop OBEX P1 Docs P2 Docs Learn Events
Stamp serial questions — Parallax Forums

Stamp serial questions

Tom PTom P Posts: 97
edited 2008-05-07 13:30 in BASIC Stamp
STAMPERS:
Here is my question?
I am collecting data from·a·few·TSL-230 light sensors on a BASIC STAMP 2, and relaying the data via a radio link to another STAMP 2 with the following program. Just looking at the·debug screen without·implementing the SEROUT command the data looks fine

But --·I'am trying to collect data on the second BASIC STAMP 2 and then trying to re-send out the data on the Internet via a serial device. but when I try to resend the data out via the SEROUT command, the·numbers shown on both the debug screen and the serial output on pin, do look correct.

Is it possible to receive data then re-transmit it again as I would like to do?
any suggestions to this problem??
'{$STAMP BS2}
'{$PBASIC 2.5}

'6-lightRx

cnt VAR Word
DO
· SERIN 7, 16780, [noparse][[/noparse]WAIT ("*"), cnt ]
· 'PAUSE 1
· DEBUG DEC5 cnt, (13)
· 'PAUSE 100
· 'SEROUT 1,16780, [noparse][[/noparse]DEC5 cnt,10,13]
LOOP

Comments

  • AmaralAmaral Posts: 176
    edited 2008-05-02 14:17
    I don't understand the question !

    do you want to change the serial data so it will not look correct ??

    if that look correct what's wrong ?

    amaral
  • Tom PTom P Posts: 97
    edited 2008-05-02 15:59
    I'am sending data from one BASIC STAMP 2 to another STAMP 2 via a radio link.
    The program above shows the receiving program on the second STAMP 2.
    When I read the debug statement on a PC - all looks fine, but when I add the SEROUT command to the program -- the readings from the debug output are no longer correct. although the debug reading and the serial output on pin 1 of the second STAMP 2 appear to be the same. So when the the SEROUT is added why do the reading become incorect.
    Is it posible to have and incoming serial reading on the STAMP 2 and then have the same data resent out on another serial pin?
  • MSDTechMSDTech Posts: 342
    edited 2008-05-02 16:10
    The first thought that comes to mind is the baud rate on the output is not matched. The data being read correctly in the DEBUG screen says the data in the variable is correct. Check that your output baud rate is matched to the receiving device.
  • Tom PTom P Posts: 97
    edited 2008-05-02 17:16
    yeah- the baud rate is the same and numbers are in fact readible to five digits but, - but the numbers groups do not represent the true reading as before the SEROUT statement was added. Once the SEROUT Statment is added the five digit number groups no longer represent the correct reading although the numbers are readible.
    tom
  • stamptrolstamptrol Posts: 1,731
    edited 2008-05-02 18:05
    When you're running your full loop ( serin and serout), the program is coming back to the serin at some indeterminate time. Because the stamp has no input buffer, you may be missing one or more digits of the incoming serial stream.

    Is there a leading character on your data stream so you can use the WAIT modifier? See the online help file for more info.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Tom PTom P Posts: 97
    edited 2008-05-02 18:58
    A STAMP 2 with the light sensors sends via radio link five digits for each sensor which sends a signal to the 2nd STAMP 2's receiver link. The information can be read on the second STAMP2 via the debug display and that part works fine.
    The sensor/sending STAMP 2 uses a wait modifier when sending to the second RX STAMP 2 which also uses the wait modifier as shown. The wait modifier between the radio links sending serial data appear fine.

    If I use: SEROUT 1,16780, [noparse][[/noparse] cnt ] in the program - the display is correct on the debug window but output on pin1 is gibberish

    If I use SEROUT 1,16780, [noparse][[/noparse]DEC5 cnt5,10,13] in the program -- the readings on the debug screen are not correct any more, but the output from pin1 is formated correctly for five digits and displays wrong numbers but they are readible.

    IS there a way to buffer the input from the output, there seems to be an strange interaction.
    Any ideas out there?
  • AmaralAmaral Posts: 176
    edited 2008-05-05 02:20
    thats Really Strange , but it could be some garbage in the line , Try to use a pull up or a pull down resistor in the serial line.. Sorry , that's all I can think of.

    Just a Question, your variables: (cnt) AND (cnt5) are the same ?? or is it a misstype ?


    Amaral
  • voodoofishvoodoofish Posts: 67
    edited 2008-05-05 20:36
    Out of curiosity, what serial device and wireless links are you using to input/output your data? I've been working on something similar this past weekend, though I only use one bs2 and a direct serial link from the second transceiver. This seemed like the easiest way to do things as it removes a possible issue like you are running into.

    This is the data collector: L[noparse][[/noparse]transceiver]<->bs2<->sensors I also have a serial lcd screen to verify that the data is going out correctly.
    The receiver end is like so: L[noparse][[/noparse]transceiver]<->rs-1 serial interface adapter-->PC. I used minicom(linux) and hyperterm(windows) to test the data.
    The transceivers I'm using are a pair of hac-um96 wireless links. I'm working on writing a perl script that collects the data and puts it to a db.

    I've yet to run into any issues with receiving. Do you have the means to run a direct link to the PC and remove the second bs2? It's just a thought and worked well for me so far.
  • Tom PTom P Posts: 97
    edited 2008-05-06 11:15
    I'am using the parallax 433.92mhz separate transmitter and receiver, they appear to work fine.
    But I've been told by STAMPers that the receiver fed to the STAMP 2 cannot be used to mirror the serial input data, beacuse the STAMP has no buffer memory. I want to use the second STAMP to futher manipulate the incoming data.
    tom
  • voodoofishvoodoofish Posts: 67
    edited 2008-05-06 22:39
    Have you tried testing nibs of data, just to make sure that it goes through correctly and can be sent out correctly?
    You could try doing a looped count to 5 and making sure that you get all of that data correctly?

    count = 1
    for count to 5
    debug count
    serout the count value
    count = count + 1
    loop
    --[noparse][[/noparse]above is just an example]--

    One other thing, you mention 5 digit groups which should be something that would fit in a word var, but do you know if it exceeds the words max value? One way to overcome this would be to use an array value for each character if this is the case.

    Another thing to try is to send some dummy value, like 11111 to debug and to the serial device prior to the loop. Set the main loop to a for/next loop and set it to capture 5 times, then reset and send the dummy value(11111) again to see if the above values gets sent.

    Last thing, you mentioned this in a previous post. "If I use SEROUT 1,16780, [noparse][[/noparse]DEC5 cnt5,10,13] in the program -- the readings on the debug screen are not correct any more, but the output from pin1 is formated correctly for five digits and displays wrong numbers but they are readible."

    Where are the readings being displayed, are you sending this to a term program? I'm just curious how you have it all hooked up...
    Debug goes to the stamp editor prog, were does the serout go to?
  • MSDTechMSDTech Posts: 342
    edited 2008-05-06 23:10
    With both stamps doing processing and with neither having any buffering capabilities, you will need to create your own flow control to consistantly be able to transmit the data. You will need to use a serial transceiver to allow a two way communication between the stamps to keep them both working together. Also, since the stamps to not have interrupt processing, one is going to have to be sitting and waiting for the other to send a message.

    Since the stamp currently receiving is going to be processing the data, which can take a variable amount of time, you should make it the Master. The other stamp will be the Slave, only performing work when requested of the master. The typical flow would go like this:

    1. The master is ready to process the next data value and sends the request to the slave.
    2. The slave receives the request, reads the appropriate sensor, does any processing necessary on its end and replys to the master with the requested data.
    3. The master processes the requested data and starts the loop again.

    Sample code that I used on a similar two stamp system:
    On the Master:
    Get_Data:
    · SEROUT bt_tx, BlueBaud,[noparse][[/noparse]"DR",Instrument]
    · SERIN bt_rx,BlueBaud,5000, Oops,[noparse][[/noparse]WAIT (Instrument), DataIn1,DataIn2]
    RETURN
    The Oops·routine is used to handle the situation where the Slave if off-line

    On the Slave:
    DO
    SERIN bt_rx,bluebaud,[noparse][[/noparse]WAIT ("DR"), Instrument]
    SELECT Instrument
    · {code here to process the selected value for instrument}
    ENDSELECT
    SEROUT bt_tx,bluebaud,[noparse][[/noparse]Instrument,DataOut1,DataOut2]
    LOOP

    Remember, the serial communication is just a stream of bits and if you don't jump in at exactly the right point the values you get out will be jibberish. In the above example, I was using a Bluetooth connection, but any device that is a serial link would work the same.

    By the way, my second stamp is also sending the data to the internet using a PINK. You can see the output at http://weather.msd.k12.mo.us.



    Post Edited (MSDTech) : 5/6/2008 11:26:41 PM GMT
  • Tom PTom P Posts: 97
    edited 2008-05-07 13:30
    Thanks for everyone for their input. Nice job MSD tech on the website and tips for flow control, and your solution looks like the optimum. However I only have a separate transmitter and receiver for this project, my options are more limited at this point!

    Can I use a BS2e and try and utilize the buffer memory for the second STAMP in the project?
    So here is the code so far:
    1)code for the TX portion using RF transmitter
    2)code for RX portion using RF recevier.
    Code shown is what I have so far --- for the second STAMP 2e.
    need some code help on the RX side with buffering ideas in order to send SEROUT from the BS2e to Internet serial device
    thanks
    Tom
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' program to scan 6-TSL230 sensors & send data via RF Xmit

    DIRL = %11111100 ' Set OE pins 2 through 7 to OUTPUT
    IN PIN 0 ' Common TSL230R output to BASIC Stamp
    OEPINS VAR OUTL ' Tie I/O pins 2 through 7 to the OE's of the six TSL230R's
    cnt VAR Word(6)
    i VAR Nib
    mask VAR Byte
    bdmd CON 16780 '2400 baud
    tpin CON 8


    Scan:
    PULSOUT 8, 1200
    mask = %11111011 ' These are the values for the OE pins.
    FOR i = 0 TO 5
    OEPINS = mask & %11111100 ' Keep input pin low
    COUNT IN, 100, cnt(i)
    mask = (mask << 1) | %0000001
    NEXT
    OEPINS = %11111100 ' Turn them all off
    DEBUG HOME
    FOR i = 0 TO 5
    DEBUG DEC5 cnt(i)
    SEROUT tpin,bdmd, [noparse][[/noparse] "*", cnt(i),10,13 ]
    IF i < 5 THEN DEBUG " "
    NEXT
    GOTO scan

    ' STAMP 2e RX program
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    '{$PORT COM1}
    '6-lightRx


    cnt VAR Word

    DO

    SERIN 7, 16780, [noparse][[/noparse]WAIT ("*"), cnt ]
    PAUSE 1
    DEBUG DEC5 cnt, (13)
    PAUSE 1
    SEROUT 1, 16780,1, [noparse][[/noparse]cnt ]
    LOOP
Sign In or Register to comment.