Shop OBEX P1 Docs P2 Docs Learn Events
Transmitting data and recieving During SLEEP mode — Parallax Forums

Transmitting data and recieving During SLEEP mode

pbasic7pbasic7 Posts: 5
edited 2011-08-08 07:26 in BASIC Stamp
edit post edit post

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-08-02 21:27
    Rather than posting code and asking us to debug it, how about trying to compile it yourself and see what errors you get, correct the ones that you understand and ask us for clarification of any that you don't understand. The way you debug a program like your transmitter is to add DEBUG statements that show you what the program is doing. You also should have DEBUG statements that show what is being transmitted. You'd use a DEC formatter so the bytes being sent would be understandable in the DEBUG output. Once you have the transmitting program working the way you expect it, you'd start on the receiving program. You'd also use DEBUG statements to show what's received and so you can follow along with your source code.
  • pbasic7pbasic7 Posts: 5
    edited 2011-08-03 11:41
    edit post edit post
  • stamptrolstamptrol Posts: 1,731
    edited 2011-08-03 12:46
    You've got the switch in the receiving program, near as I can see. You never are ready to receive unless the button is down. Is that what you want? The transmitter should be the master and the receiver has to always be ready to receive.
    Then, the program will wait at the first SERIN until it sees the expected "!".

    In the transmitting program, you are sending "z" and "a" but I don't see where they have been given valid values.

    If I were trying to get things working, I'd put the transmitter in a loop where it sends two or three characters repeatedly. Then I'd work to get the receiver to be able to grab them reliably.

    The Helpfile in the programming environment has a simple example of serial communication that is a good place to start. Get it to work with a hard connection, then put the radios in, then go for your final arrangement.

    Cheers
  • pbasic7pbasic7 Posts: 5
    edited 2011-08-03 14:14
    I am trying to loop until z= 1 is s
  • stamptrolstamptrol Posts: 1,731
    edited 2011-08-03 16:28
    OK, so the receiving end is really the transmitter to get things going. That means the transmitting end has to be sitting at the SERIN instruction in order to receive.

    The code in your last post should work (other than DEBUG is mis-spelled). Also the second program will sit at the SERIN and wait for "ABC", which is what you want. I don't know why you're using the HIGH 0, LOW 0 unless its required by the radios.

    So, again, I'd set the first program to continuously loop, sending out "ABC" until you successfully get it at the other end. This might mean reverting to wire (a data wire plus a ground wire) between the units until you get the first information exchange to work.

    Despite the information in the first post, you are really building a two-way communication link. Your program(s) have to make sure the unit that is going to receive something is sitting there when the transmitting unit sends, otherwise the receiver will miss the data because there is no comm buffer.
  • pbasic7pbasic7 Posts: 5
    edited 2011-08-04 13:02
    I am trying to transmit and recieve on 2 trancsievers with the debug terminals. I got the values
    to display in both of the debug screen, but my tranmitting end keeps trying to send the same values
    over and over again. After a while it start to send random data values on the same debug terminal.
    I am trying to put a stop so it only sends my x and y values to the other side and not float after
    that. i have tried to use the debug to work through code but cant figure out what the problem
    is. I want the values to display everytime the button is pressed. Please help.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    x VAR Word
    y VAR Word
    k VAR Word

    k=1
    HIGH 1
    DO


    IF (IN3=1) THEN

    DO

    PULSOUT 1, 1200
    SEROUT 0, 84, ["!", k.HIGHBYTE, k.LOWBYTE]
    PAUSE 500

    LOW 1
    PULSOUT 0, 1200
    SERIN 0, 84, [WAIT ("ABC"), x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE]
    HIGH 1
    PAUSE 10
    'SLEEP 3

    DEBUG ? x
    DEBUG ? y
    LOOP

    ENDIF

    LOOP




    ' Tcvr_TxCode_v1.1.bs2
    '{$STAMP BS2}
    '{$PBASIC 2.5}

    k VAR Word
    x VAR Word
    y VAR Word

    k = 0
    x = 70
    y = 80

    HIGH 1
    LOW 13

    DO
    DO WHILE (k = 0)
    'SLEEP 1
    LOW 1
    SERIN 0, 84, [WAIT("!"), k.HIGHBYTE, k.LOWBYTE]
    HIGH 1
    DEBUG ? k
    'SLEEP 1
    LOOP

    'IF (k = 1) THEN

    PULSOUT 0, 1200
    SEROUT 0, 84, ["ABC", x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE]

    PAUSE 10
    'SLEEP 3
    DEBUG ? x
    DEBUG ? y
    SLEEP 1
    'ENDIF

    k = 0
    LOOP
  • stamptrolstamptrol Posts: 1,731
    edited 2011-08-08 07:26
    In both programs, you sometimes use PULSOUT 1, 1200 and PULSOUT 0, 1200; what is their purpose?

    Is pin 1 a rec/transmit control on the radio?

    Maybe add a few brief comments in the code.

    Also note that the Parallax store has some sample programs which may assist. See the "Products" section
    http://www.parallax.com/Store/Accessories/CommunicationRF/tabid/161/CategoryID/36/List/0/SortField/0/Level/a/ProductID/582/Default.aspx
Sign In or Register to comment.