Shop OBEX P1 Docs P2 Docs Learn Events
Need Help Coding/Configuring Wireless Device In Basic Stamp 2 — Parallax Forums

Need Help Coding/Configuring Wireless Device In Basic Stamp 2

Im New To MicroIm New To Micro Posts: 42
edited 2010-12-17 08:02 in Accessories
Hi all,

Over at electro-tech-online.com I was asking others what I needed to buy to control things on my Board of education wirelessly, such as, control my Boe Bot wirelessly, or turn LEDs on and off wirelessly with a controller (one I create or a professional one already made).

Anyway, they referred me to the following two devices/chips, but the problem is, I have no idea what code I should use or if a tutorial is even out there to help me set these up to link to each other and send bytes back and forth.

http://www.sparkfun.com/commerce/product_info.php?products_id=8945

http://www.sparkfun.com/commerce/product_info.php?products_id=8947

I saw that Basic Stamp 2 uses the serin and serout, but it just didn't give me enough information on how to set these two particular components up.

Any help is appreciated!

Comments

  • Daniel HarrisDaniel Harris Posts: 207
    edited 2010-09-30 02:08
    Hello Im New...,

    I took a look at the datasheet for those wireless modules you linked to. They look pretty snazzy, and for a total cost of less than 10 bucks for the pair, thats pretty hard to beat :).

    The BS2 should be able to talk to these things nicely - there doesn't look to be any real configuration necessary. Now, Im not sure about this because I have never used these modules and their datasheets are a little sparse about how to communicate between them, but it looks like you can send data to the transmitter and have the receiver echo that data on the other side - this is very similar to the Linx Transceiver modules that Parallax sells (_this one_).

    The following is a short code sequence for the transmitter:
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    
    x VAR Word
    y VAR Word
    
    DO
    PULSOUT 0, 1200 'Sync pulse for the receiver
    
    SEROUT 0, 396, [ "!", x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE ]
    x = x + 1
    y = y + 1
    PAUSE 10
    
    LOOP
    

    This code is for the receiver:
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    
    x VAR Word
    y VAR Word
    recv PIN 0
    
    DO
    LOW recv
    SERIN recv, 396, [WAIT("!"), x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE]
    HIGH recv
    DEBUG ? x
    DEBUG ? y
    
    LOOP
    

    What this does is have the transmitter send a start byte (the "!") followed by 4 bytes. On the receiver side, the BS2 waits until it sees an "!" from the receiver and then copies the next 4 bytes to their respective variables. Once the receiving BS2 has this data, it can do whatever you want to do with it - I.E. control motors, turn on LEDs, play a tune...

    In the code above, I set the baud mode to 396. For a BS2, this sets up the serial transmission/receiving to 2400 Baud, 8 data bits, no parity, and one stop bit (2400 bps @ 8n1). Those serial modules you posted have some limitations on the transmission speed, which is why I chose 2400 baud.

    Something to consider with these wireless modules: there is no wireless network protocol that these modules adhere to. That is, you have to define to the transmitting BS2 the order in which you send bytes and program the receiving BS2 to receive bytes in that order and somehow validate the received data. This is the point behind sending and receiving a preamble of "!". Also, Sparkfun's page states that "Only one 315MHz transmitter will work within the same location.". This might not be good for your application because you cannot get bi-directional communication between your two devices.

    If you want a little more information about the theory of how those code segments work, check out the following PDFs - they are for the Linx transmitter and receiver modules. Parallax's Linx Transceiver module that I linked above is essentially both of the following devices rolled into one device (does that make sense?).

    Transmitter: TX Product Sheet
    Receiver: RX Product Sheet

    Did you pick up a pair of those transmitters/receivers? I am curious to see how they work for you :D.
  • Im New To MicroIm New To Micro Posts: 42
    edited 2010-09-30 11:21
    Hello Im New...,

    Did you pick up a pair of those transmitters/receivers? I am curious to see how they work for you :D.

    Yeah I did because of how cheap they were, but I'll definitely give that code above a shot to see how things goes. It's a lot to take in, but if all goes wrong, I'll just buy the parallax module.

    I'm sure I'll have other questions, so I'll keep you posted :)
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2010-10-01 00:19
    Cool. Keep me posted on how things go with those modules. I might spring for a pair if you have success with them. I would like to try to automate my apartment and these wireless modules would do the trick. (haha, things can get a little boring in the evenings when you live by yourself >_<)

    If you want, you can even post some of your code here - I would be happy to give you some pointers. Same with any questions as thats what Im here for :cool:
  • Im New To MicroIm New To Micro Posts: 42
    edited 2010-10-01 01:10
    If you want, you can even post some of your code here - I would be happy to give you some pointers. Same with any questions as thats what Im here for :cool:

    Will do. I'm just so busy with school this week and have an exam next Mon I need to study for, so I haven't been able to try out that code as quickly as I wanted. I should have some free time Saturday I hope. :)
  • Ken GraceyKen Gracey Posts: 7,387
    edited 2010-10-01 09:13
    Cool. Keep me posted on how things go with those modules. I might spring for a pair if you have success with them. I would like to try to automate my apartment and these wireless modules would do the trick. (haha, things can get a little boring in the evenings when you live by yourself >_<)

    If you want, you can even post some of your code here - I would be happy to give you some pointers. Same with any questions as thats what Im here for :cool:

    Hey Daniel, have you determined whether or not these RF modules handle the error checking for you? Remember, you can grab all the XBee stuff you want from inventory. Ahh - hassle-free RF is only 50 feet away from your desk. 2mW to 60 mW with the adapters and microcontrollers of your choice! You can have the best for free sometimes!

    Ken Gracey
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-10-01 09:39
    I didn't want to say it right away, since Daniel gave such an extensive answer, but I think that "New To Micro" will find that it's worth spending a little extra money and using XBees instead of those Sparkfun units. Unless you're much better at it than I am, you'll spend a lot of time trying to get those units doing what you want them to do, while the XBees will work quickly and easily, with much easier code, better range, and so on.

    I have one of those transmitter/receiver pairs sitting around here somewhere - I haven't touched them since I got my first XBees a few years ago.
  • Ken GraceyKen Gracey Posts: 7,387
    edited 2010-10-01 10:06
    sylvie369 wrote: »
    I didn't want to say it right away, since Daniel gave such an extensive answer, but I think that "New To Micro" will find that it's worth spending a little extra money and using XBees instead of those Sparkfun units. Unless you're much better at it than I am, you'll spend a lot of time trying to get those units doing what you want them to do, while the XBees will work quickly and easily, with much easier code, better range, and so on.

    I have one of those transmitter/receiver pairs sitting around here somewhere - I haven't touched them since I got my first XBees a few years ago.

    My perspective is the same. If one's time is of any value then it's really worth spending the money to get the XBee units. My only problem with the personal commitment to using XBee is that I'm now wearing RF "blinders". It would take a real convincing case and super easy technical transition to make me use something else at this point.

    The Lynx devices mentioned above work well and they're really simple, but you have to do the error checking/checksums in your code. This becomes a focus of its own sometimes.
  • Im New To MicroIm New To Micro Posts: 42
    edited 2010-12-16 22:47
    Sorry for taking so long to get back to you guys regarding this, but after looking at the second post, is 2 parallax boards required to get this to work, or can I do this with 1 Board of Education board?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-17 08:02
    It's not clear what you're asking. With either the xBees or the Lynx devices, you need some kind of microcontroller on each end of the connection. You can also use a PC if you have an interface for it since the PC doesn't normally provide a logic level serial port which the "wireless device" needs.
Sign In or Register to comment.