Shop OBEX P1 Docs P2 Docs Learn Events
BS2P24 to computer connection — Parallax Forums

BS2P24 to computer connection

spainespaine Posts: 51
edited 2005-05-05 12:44 in BASIC Stamp
I see SOUT and SIN on the BS2P24, and I understand that those are used to attach the BS2P to a computer for programming (and debugging).

However, during run-time, what do I use to communicate with a PC? Can I just use any I/O pin, and connect it to something like a Max232 device for connection to a computer?

Basically, my Stamp will be receiving sensor data, and then forwarding this data on to my PC (which if my above is correct will use one I/O pin), but then my PC will process the data, and then send updated data back to the Stamp (would this use another I/O pin)?

Thanks for the help.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 20:08
    What you'll probably want to do is use a MAX232 so that you can have flow control with the PC -- this will let BASIC Stamp do other things and cause the PC to hold its data until the Stamp is ready for it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • bishopbishop Posts: 82
    edited 2005-05-04 20:46
    wow...tons of questions on pc to bs2 communication on this board. seems to be a popular topic.
    almost need a separate forum channel for it.
    or maybe a pdf or doc file to refer people to.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    **************

    daniel woolston
    Teksystems Inc.
    www.danwoolston.com
    **************
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-04 21:32
    Hello,

    ·· You can also talk back to the computer through the programming port by using SERIN/SEROUT and using 16 for the pin number.· This will depend on how much data you need to process.· You will also have to filter out data sent to the Stamp, since it will be echoed back.· But you can use it if you don't want to add extra hardware.· However, the suggestion above is less problematic.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 5/4/2005 9:42:46 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-04 21:52
    Yup, SEROUT 16, 84 + 16384, [noparse][[/noparse]"Hi",CR] will send the string "Hi" <CR> to your computer.

    SERIN 16, 84 + 16384, [noparse][[/noparse]DEC MyVal] will recieve the string "10" <CR>, and put the value 10 into 'MyVal'.

    Now, you do need to be aware that anything you send to the BS2 will be echoed back, so you'll have to 'toss' those echo'ed bytes with your PC program. But otherwise, you can use the SIN/SOUT port this way with no other hardware needed.

    Oh, and you need to set DTR_Enable to FALSE -- otherwise the DTR signal will hold your BS2 in reset. Actually, the BOE board has two capacitors that let the BS2 run anyway -- look at the schematic for that board to see.
  • spainespaine Posts: 51
    edited 2005-05-04 23:05
    Allan,

    After seeing your reply, I have a PBasic programming question. I would like to receive GPS data from my Garmin eTrex on P8, and I want the entire line of data if that line starts with $GPGLL. The entire line would be placed in a Variable and then sent out another pin (possible 16, like you showed).

    Would it look like this:

    myPos var word

    SERIN 8, 84 + 16572,[noparse][[/noparse]WAIT("$GPRMC"),dec myPos]

    SEROUT 16, 84 + 16384 [noparse][[/noparse]myPos]
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-04 23:41
    Yes, actually you can make a very nice "recieve only" port with the BS2 by adding an in-line 22 Kohm resistor. So put a 22 Kohm resistor to pin 8, connect the other end to your Garmin, then remove the " + 16384" (because that says the signal is 'inverted', in other words goes through a MAX232 or equivalent, which the SIN/SOUT ports have).

    Also, you DO have to wire the TX signal from your PC, because the SIN/SOUT pins use the RS232 voltage from that pin when they send back. You don't have to send any messages on that line from the PC, just make sure you do connect it.

    And remember the BS2 is a single-tasking processor -- so when you are waiting to recieve data, it 'pends' until the data gets there (or you have a timeout). When you are sending data, the BS2 will ignore anything coming in pin 8.
  • spainespaine Posts: 51
    edited 2005-05-04 23:47
    Allan,

    I saw that you said that you mentioned BS2 being "single-tasking." However, what if I have other sensors that are transmitting data to other "receive-only" pins. That is, I might have an inclometer on pin 9, and a accelerometer on pin 10.

    Although the BS2p24 is single-tasking, I can still have some loop that checks each of the pins for the expected data right? Or am I mistaken?

    Thanks in advanced,
    Stephen

    allanlane5 said...

    And remember the BS2 is a single-tasking processor -- so when you are waiting to recieve data, it 'pends' until the data gets there (or you have a timeout). When you are sending data, the BS2 will ignore anything coming in pin 8.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-05 00:21
    Yes, you can check pins "in a loop", as you said. Just be aware that while you are reading once sensor, there's nothing 'storing' the state of an earlier sensor.

    If you are using SHIFTIN/SHIFTOUT to read sensors, then the sensor itself can store its state until you read it, not a problem.
    If the pins are all using SERIN, then you'll probably miss some messages. If the messages come pretty often, this doesn't have to be a problem either.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-05 01:29
    I still maintain that unless the BASIC Stamp is controlling communications between it and the PC, the best solution is an RS-232 chip and flow control. Yes, it costs a few pins a couple parts, but it eliminates a lot of general comm hassles that come up when using the programming port.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • bishopbishop Posts: 82
    edited 2005-05-05 12:44
    flow control will make your life easier.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    **************

    daniel woolston
    Teksystems Inc.
    www.danwoolston.com
    **************
Sign In or Register to comment.