Shop OBEX P1 Docs P2 Docs Learn Events
Help with Transciever code between to stamps. Can two stamp communicate between — Parallax Forums

Help with Transciever code between to stamps. Can two stamp communicate between

hybridhybrid Posts: 16
edited 2005-11-16 18:07 in BASIC Stamp
Hey Parallax group. Here is my question: I have two basic stamps communicating over the rf modules. I am having trouble synchronizing the two stamps. If i send a serout command for stamp1 over rf and have stamp2 to recieve the signal it creates a synchronization dilema. There is a chance that the sent message from stamp1 is not recieved by stamp2. The first stamp will continue with its code. In my case it has several serout commands in a row. I could make the serin comman on stamp 2 use a timeout option, but then the following serin commands on stamp 2 would not match with the serout commands of stamp1. Is there anyway to code around this sychronization problem. Someone said something about the stamps handshaking, but i don't know what that means. Any help would be great. Thank you very much.

Comments

  • JonathanJonathan Posts: 1,023
    edited 2005-11-16 03:08
    Hybrid,

    Welcome to the world of RF communicatons...

    What you describe is a classic problem. With one way communication, it can be a toughie. With two way comms you can use a checksum and retransmit if needed scheme. In a one way, you can use a checksum or byte count to know if you got all the data, but you can't request a resend. Most RF units do not support handshaking, which is a system of sending bytes only when the recivier is ready.

    One totally trouble free way of doing it is with transeiver units that have built in error checking. I use Parallax's EB500 bluetooth unit, and it takes care of all the error checking, I just get clean data from the output. I beleive there is at least one other Parallax RF product that has error checking.

    What are you trying to do, exactly? There may well be ab accepatable way of doing it with the units youi have. What RF unit are you using, BTW?

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • BeanBean Posts: 8,129
    edited 2005-11-16 03:22
    Hybrid,
    It sometime helps to prefix the data like this:
    255, 0, 255, 0, 255, 0, id , data

    Then program the receiver to wait for 255, then wait for 0 then wait for a byte that is NOT 0 or 255, that number is the id, and the next byte is the databyte.

    If the id matches the id of the last reception, then it is a repeat so ignore it.

    What you do is send this multiple times with the same id. The receiver ignores anything with the same id after it gets data.
    Repeat it as many times as you need to get good data (will take some trial and error).

    All you have to do is change the id for the next data byte. (id cannot be 0 or 255, I would roll it from 1 to 254 then back to 1 again). The receiver can also use the id to make sure it didn't miss a datebyte.

    Hope this makes sense...
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    Those that would give up freedom for security will have neither.


    Post Edited (Bean (Hitt Consulting)) : 11/16/2005 3:25:01 AM GMT
  • hybridhybrid Posts: 16
    edited 2005-11-16 12:45
    Well here is the whole story of what i am trying to do. I currently have three basic oem stamps. Two stamps are configured to collect data using sensors and adc's to collect data. The third stamp is a base station pretty much which will recieve the data over the parallax RF transmitter and reciever modules from the two other stamps collecting the data. I can't have both remote stamps sending data at the same time or else I would get intereference. So what i would like to do is turn one stamp one at a time. The base station sends a signal to one station waiting for a start sequence different from the start sequence of the other remote stamp. The trouble lies here though. When one of the remote stations starts sending data, it serouts different variables. I tried adding a start sequence to each different variable, but this still doesn't get around the main problem. If the base station is to recieve the data what happens in this scenario. Stamp sends a signal but it isn't recieved by the base station. If i don't put a time out option on the serin command the recieve code will never continue. If i do put a timout the transmit code will send the first byte but if its not recieved the recieve stamp will wait for the timout to finish. When the timeout finishes the next serin command on the reciever will not coincide with the serout command of the transmitter.
  • hybridhybrid Posts: 16
    edited 2005-11-16 12:50
    Bean I had a question to your proposa. Do your serin commands with the start sequence have a timout option. If not are you assuming that when you send the data, it will be recieved even if you send the data several times???
  • hybridhybrid Posts: 16
    edited 2005-11-16 12:54
    I also thought about having the data be placed into some type of array of bytes and having both transmitters send data to the base station even if they overlap. This would mean I have basically two serin command at the base station. One to recieve the array from one stamp and the other serin to recieve the array from the other stamp. But i would think the signals would interfere since im using the same transmitter modules. If so is there anyway to alter the frequency of the transmitter/reciever so they don't interfere.
  • stamptrolstamptrol Posts: 1,731
    edited 2005-11-16 13:33
    Hybrid,

    One very common standard way of doing this is to have the base station query the the field units one at a time.

    The field units use the SERIN "WAIT" feature and sit there until they see they address, as per Bean's earlier post.
    When the field unit sees its address, then it can send the data back, knowing that no one else will be transmitting at the same time.

    I've used this technique on both wired and RF systems.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2005-11-16 14:01
    Seems to me that you can use the same scheme in either wired or RF form.

    It means that you can set up a breadboard without the RF transcievers in order to get your code debugged, and then add them in later.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Tom WalkerTom Walker Posts: 509
    edited 2005-11-16 14:51
    Stamptrol,
    I think that that would imply that the remote Stamps have a means of "detecting" that it is their turn to transmit...implying another transmitter/receiver pair. I think that hybrid is trying to find a solution using only the transmitters on each of his remotes and the receiver on his base station.

    Does that sound right, hybrid?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • hybridhybrid Posts: 16
    edited 2005-11-16 16:41
    If I could do it with only the transmitters on the remote field stamps and only a reciever at the base that would be great. I do have though transcievers at all locations. Now the problem I had is not really solved by using the wait() option. Suppose i use the wait option on a field stamp. When the field stamp recieves the correct sequence given by the wait option it will send its data back to the base stamp. However, the base stamp has no way of synchronizing the data with the field stamp. This is what i stated previously. The base stamp might rcv the data but if it doesn't should it wait for the a restransmit or timeout after a certain amount of time. If I wait for data to be resent, how long do I wait. This timing issue insn't easily resolved
  • stamptrolstamptrol Posts: 1,731
    edited 2005-11-16 17:41
    Hybrid,

    What we did was make the interaction a two step one. The master asks the slave for recent data. As the slave transmits the data, it sets a flag. When the master receives data, it then sends back a character which acknowledges receipt and tells the slave to reset its flag.

    If the master doesn't receive data from a slave, it knows to re-query. The slave knows which data to re-send because of the flag.

    This was used on a 1000 HP air blower system and has been running for 6 years or so. The data exchanged included all data measurements, start-stop commands for the motors and the data used by the trending software. The system had one master set up as described and 6 slaves; one by RF and the others by hardwire RS-485.

    Cheers
  • hybridhybrid Posts: 16
    edited 2005-11-16 18:07
    Stamptrol. I like your idea. I think i'll try this and if I have any question i'll let you know. Appreciate everyone help. Thank you. Finally, some light has been shed to this problem.
Sign In or Register to comment.