Shop OBEX P1 Docs P2 Docs Learn Events
Triggering/Running a PC Program via BASIC Stamp Input — Parallax Forums

Triggering/Running a PC Program via BASIC Stamp Input

KriscKrisc Posts: 16
edited 2005-12-12 07:01 in General Discussion
Triggering/Running a PC Program via BASIC Stamp Input

Hi,

I have a project where I want to be able to start or stop a program on a PC via a simple rocker switch. I was referred to use the BASIC stamp. I used one a long time ago but didn't really understand everything. I do have quite a bit of programming experience and understand the language for the stamp but do not know how to go about doing what I want.

Any ideas? sad.gif

~Krisc

Edit: I have a feeling this went in the wrong forum now that I browsed around a bit. If it is supposed to be in the BASIC forum, I apologize!

Post Edited (Krisc) : 12/1/2005 10:22:46 PM GMT
«1

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-01 22:27
    The most complex aspect will be on the PC side, which you seem to be skilled at. Communication from the BS to a PC is easiest through the serial port, the Stamp will send a value indicating the position of the rocker switch whenever it changes. A program on the PC will sit listening to the serial port and take the appropriate action when it receives the rocker value.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • KriscKrisc Posts: 16
    edited 2005-12-01 22:35
    Thanks Paul for the fast response! I am guessing inside the BS I would have to output to the Serial port (SEROUT?) then?

    I have yet to buy a BS since I do not know which will best fit this application. I want multiple switches as well, how would I differ between them on the serial port?
    Paul Baker said...
    The most complex aspect will be on the PC side, which you seem to be skilled at. Communication from the BS to a PC is easiest through the serial port, the Stamp will send a value indicating the position of the rocker switch whenever it changes. A program on the PC will sit listening to the serial port and take the appropriate action when it receives the rocker value.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-01 22:48
    You are correct that you would use the SEROUT command. This is a pretty lightweight application that could be done by a BS1, but I would suggest getting a BS2 variant if you want to do further projects (more program and data space, faster execution, more IO pins).

    I would send an 8 bit value each time a switch changes, say you have 3 switches that have an off and on position Id create a table like this:

    $01 Switch 1 off
    $02 Switch 1 on
    $03 Switch 2 off
    $04 Switch 2 on
    $05 Switch 3 off
    $06 Switch 3 on

    nothing special about the values chosen or the order. Whenever the PC program receives the value $03 it knows that the second rocker switch has been turned off. The table can be expanded for more or less switches, or even multiple position switches.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • KriscKrisc Posts: 16
    edited 2005-12-01 23:35
    Awesome. Something like this then?
    www.parallax.com/detail.asp?product_id=27290
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2005-12-02 00:45
    Hey!!, look in the "Sale" section -- those BS2 OEMs are still $30 over there.· Solder a little & save a lot.

    http://www.parallax.com/detail.asp?product_id=27291
  • KriscKrisc Posts: 16
    edited 2005-12-02 00:57
    You say that as if I can solder. blush.gif Okay, I can a bit... but I wouldn't trust myself with building one of these...
    PJ Allen said...
    Hey!!, look in the "Sale" section -- those BS2 OEMs are still $30 over there. Solder a little & save a lot.

    http://www.parallax.com/detail.asp?product_id=27291
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-02 02:58
    Personally I would choose the BS2sx, but I understand why you want the OEM; since it has an integrated serial port, you don't need a carrier board so its cheaper.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • KriscKrisc Posts: 16
    edited 2005-12-02 03:25
    Yeah, I ordered the OEM.. Trying to keep it pretty simple and relatively cheap.

    I came up with this wiring diagram. I think it should be correct...

    It is relatively simple, and I haven't figured out power to the board yet. It is just the BS2 as well, not the full OEM board.

    project_003.jpg

    Post Edited (Krisc) : 12/2/2005 3:28:19 AM GMT
  • KriscKrisc Posts: 16
    edited 2005-12-02 06:57
    Well now people are telling me I need all sorts of stuff because the voltage will have spikes and problems because it comes from a car batter and that the 5v regulator will fry. They are talking about diodes and filtering caps...

    ugh!

    project_004.jpg
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-02 14:39
    They are correct that you cannot supply more than 5V to any of the pins on the Stamp (except Vin). Your original drawing was feeding 12V straight to the P0 pin which would likely burn out that pin. I know you are just starting out, so post your proposed schematics for us to check over before trying to wire it up, your current diagram looks ok (except the 5V regulator will have a connection to ground and will need two capacitors, but you'll see that when you look at the specification sheet for the regulator you choose).

    Also check out some free schematic drawing programs, as a beginner I would go with http://www.expresspcb.com/·since it is fairly easy to use, and most people are happy with the PCBs the service produces (you dont need to do PCB designing, it also contains a schematic editor). At first it will take you longer laying out schematics using the program, as opposed to drawing them yourself, but with practice you'll find it faster and more legible. After you become more skilled and want to be making professional PCBs we can switch you to a more versatile program (also free) that is more powerful (but also more difficult to learn if you aren't familiar with electronic design).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 12/2/2005 2:47:24 PM GMT
  • KriscKrisc Posts: 16
    edited 2005-12-02 19:22
    So something like this?

    I haven't added the capacitors as I don't know where they go just yet. I am just trying to get used to the program. Pretty nifty it is...

    project_005.jpg
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-02 19:31
    Yup, you got it. Here's the datasheet for the LM7805, it will have a drawing of the capacitors·and thier suggested values.

    http://www.fairchildsemi.com/ds/LM/LM7805.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • KriscKrisc Posts: 16
    edited 2005-12-03 21:21
    Paul Baker said...
    Yup, you got it. Here's the datasheet for the LM7805, it will have a drawing of the capacitors and thier suggested values.
    http://www.fairchildsemi.com/ds/LM/LM7805.pdf

    I am a tad confused about what that says to do... I copied the correct diagram into mine but do not understand if the wire between the capacitors crosses with the ground or if they don't touch it... I though that would cause a short circuit?
    I also added an LED into the diagram so I can give some status from the program...
    Also, is a 33pf capacitor a 0.33uf capacitor?

    project_006.jpg
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2005-12-03 22:14
    No, a 33pF = 0.000033 uF.· A 0.33 uF you may find marked "334" (330,000 pF, it's 33 with 4 following 0's as pF.)

    You need a current limiting resistor between the LED and P15 (330 - 1000 ohms, 680 would be good.)
  • KriscKrisc Posts: 16
    edited 2005-12-03 22:36
    PJ Allen said...
    No, a 33pF = 0.000033 uF. A 0.33 uF you may find marked "334" (330,000 pF, it's 33 with 4 following 0's as pF.)


    You need a current limiting resistor between the LED and P15 (330 - 1000 ohms, 680 would be good.)

    Aw, dang. I have the wrong thing then. burger.gif Here are what the capacitors say and what the container reads.

    As for the LED, I didn't add it in...but the LED has a built in resistor and can take 12 volts.

    project_007.jpg
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-03 22:42
    I am a tad confused about what that says to do... I copied the correct diagram into mine but do not understand if the wire between the capacitors crosses with the ground or if they don't touch it... I though that would cause a short circuit?
    I also added an LED into the diagram so I can give some status from the program...
    your drawing is correct, capacitors block DC Voltages and transmit AC voltages. When determining a short circuit it is the DC voltage path you need to worry about, since the capacitors block DC voltages, it's not a short. The two capacitors act as filters making the input and output voltages more DC-like, any fluctuations in the input or output voltages get transmited through the capacitors and dumped into ground, capacitors used in this manner are "bypass capacitors".

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2005-12-04 00:07
    The CAP values aren't included in your box o' caps.

    Maybe everyone will jump on my case for saying so, but you may find that you can go without.·

    Ordinarily, on the input I go with a 0.1 uF (usually marked "104"), a 0.01 uF ("103")·will get you there, too; on the output use a 1 uF (electrolytic or tantalum).

    [noparse][[/noparse]You'll have to make another trip to RadioShack.· If you decide to go without, I don't see you wrecking anything.]
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-04 00:23
    This isn't really a jumping on your case, but in general the output capacitor (the 0.1 µF) is more important than the input capacitor. Many new regulators absolutely need the output capacitor or the output will oscillate. However, the 7805 is a old type of regulator, and Im not sure if it is quite so picky. Now the input capacitor isn't as critical especially if you are supplying it with an already regulated power supply, that is why it's value is so small.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • knightofoldcodeknightofoldcode Posts: 233
    edited 2005-12-04 01:37
    There is also another consideration that I think was neglected. If you're using an external 5V regulator, you can't power the BS2 with the VIN pin.

    I don't understand why the external voltage reg is needed? Can't he just throw the 12V at the VIN pin and let the onboard regulator do it's thing? He wouldn't be supplying any external components with this method so it shouldn't be a high amperage draw.

    Also, if the SIN SOUT VSS ATN pins are used to communicate with the computer you'll run into some echoing issues that will have to be dealt with on a PC software basis. I'm not sure if the BS2 sends something if it's echoed or not, I don't think so. But if you ever progress to sending something to the BS2 with the programming port, you'll need to be aware of this.

    These switches being used, I would assume have lights on them to indicate status? (Hence the need for the ground, load and supply labels). If this is the case then why would the LED be needed? (No problem if you just want two, just reminding you of the light on the switch. [noparse];)[/noparse]

    Also, this project doesn't require the power of a BS2. Depending on what language you are programming, you can get away with doing this all via a parallel port. However, if you ever upgrade to more than 8 switches, or want more power in your application, then you'll have to switch to the BS2, so if you're not going to change this in anyway, I'd suggest looking into the parallel port option. The only problem is that most newer computers don't have a parallel port. [noparse]:([/noparse] You can still purchase PCI cards to add a parallel port. If you're only needing one or two switches, you can actually get away with a serial port. Switching the status lines of the serial port is an option, but it only allows a few switches. I'm not sure offhand how many.

    It's much easier to use the Basic Stamp, but cheaper to use the serial port or parallel port directly. It's also much safer to use the Basic Stamp, in terms of frying a parallel or serial port.

    My $0.02,
    Knight.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
    This message transmitted with 100% recycled electrons.
    -=-=-=-=-=-
    Gravity doesn't exist. The Earth sucks.
    -=-=-=-=-=-
    Make a man a fire, and he will be warm for the night.
    Light the man on fire, and he will be warm for the rest of his life.
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
  • KriscKrisc Posts: 16
    edited 2005-12-05 01:04
    The second LED is mostly for debugging purposes. I want to make it so the PC sends a signal back signalling that recording has started successfully. This project is just the start for what I want to do with the BS2. Definately will expand with other projects and ideas later on.

    What is the problem with using an external regulator? The problem I will run into is that a car battery is dangerous for drawing power from as it fluctuates a lot in voltage and amperage apparently. I just don't want to risk frying the BS2.
  • ForrestForrest Posts: 1,341
    edited 2005-12-05 01:56
    There's no problem using an external +5V regulator and it's probably a good idea to protect against surges. Better to cook a $1 regulator than a $50 Stamp. For a more robost +5V regulator circuit for automotive use - see www.seetron.com/an_vpwr1.htm

    It's imperative than you connect the Vss on the stamp with the ground on your PC serial port to communicate successfully.
  • knightofoldcodeknightofoldcode Posts: 233
    edited 2005-12-06 10:55
    Krisc said...
    The second LED is mostly for debugging purposes. I want to make it so the PC sends a signal back signalling that recording has started successfully. This project is just the start for what I want to do with the BS2. Definately will expand with other projects and ideas later on.

    What is the problem with using an external regulator? The problem I will run into is that a car battery is dangerous for drawing power from as it fluctuates a lot in voltage and amperage apparently. I just don't want to risk frying the BS2.

    Copied out of the BS2 FAQ:
    BS2 FAQ said...
    How do I power the BASIC Stamp?
    The BASIC Stamp runs on 5 to 15 volts DC. All BASIC Stamps feature an on-board 5-volt regulator which will
    convert an input 6 to 15 volts (on the VIN pin) down to the 5 volts that it’s components require. If your power
    supply is 6 to 15 volts, you should connect it directly to the VIN and GND pins or to the battery clips on the
    development board. The VIN and GND pins are pin number 1 and 2 on the BASIC Stamp rev. D or BS1-IC or
    pin 24 and 23 on the BS2-IC, BS2E-IC and BS2SX-IC. If your power supply delivers a regulated 5 volts, you
    should connect it directly to the +5V and GND pins (14 and 2 on the BASIC Stamp rev. D, 5 and 2 on the BS1-
    IC, and 21 and 23 on the BS2-IC or BS2SX-IC). NOTE: When using battery or wall-pack power supplies, it is
    recommended to limit the voltage to 9 volts on the Stamp 1 and Stamp 2, and 7.5 volts on the Stamp 2e and Stamp
    2sx.

    You won't need a regulator for this application, as it stands. The BS2 has one built in. However, if you do something more with this project, at some point you will need to get a regulator, if you're going to be powering many other components. Hopefully this may have cleared something up?

    Also note... if you do have a external regulator, that outputs at 5V, such as the 7805, then you'll need to power youre BS2 via the VDD pin and NOT the VIN pin. The VDD pin is for constant 5V ONLY... The VIN pin is for 6V to 15V current. If you feed the output of a 7805 into the VIN, it won't work, I don't know what'll happen, but it won't be pretty, probably it just won't work.

    Knight.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
    This message transmitted with 100% recycled electrons.
    -=-=-=-=-=-
    Gravity doesn't exist. The Earth sucks.
    -=-=-=-=-=-
    Make a man a fire, and he will be warm for the night.
    Light the man on fire, and he will be warm for the rest of his life.
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
  • m_fabio2m_fabio2 Posts: 49
    edited 2005-12-07 20:49
    Caps are for the WEAK !
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-07 20:55
    m_fabio2 said...
    Caps are for the WEAK !
    ¿Que? I dont think I buy any products you've made! [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • KriscKrisc Posts: 16
    edited 2005-12-09 20:33
    It came today!!!!! Yay! This thing is so small. Okay... I am a little confused. Do I just hook up a 12v power supply to VDD and the ground to VSS? It also has a 5v regulator, but I don't think I hook anything up to that directly do I?

    Just want to be sure before I do anything.
    Thanks... tongue.gif

    project_008.jpg
  • ForrestForrest Posts: 1,341
    edited 2005-12-10 00:18
    Connect the 12V power supply to VIN and the ground to VSS

    Basic Stamp Frequently Asked Questions document should answer all you questions - download it here www.parallax.com/detail.asp?product_id=27290
  • KriscKrisc Posts: 16
    edited 2005-12-10 01:04
    Forrest said...
    Connect the 12V power supply to VIN and the ground to VSS

    Basic Stamp Frequently Asked Questions document should answer all you questions - download it here www.parallax.com/detail.asp?product_id=27290

    Hmmm... Ok, I got it all hooked up... but am having trouble getting the program to run. It keeps saying it cannot find the stamp. Any ideas?

    edit: Nevermind, I hooked up to the wrong tab on the 12v female plug I think. I will go resolder now.

    Ok, now I know the BS is getting power, but the program still says none found.

    Post Edited (Krisc) : 12/10/2005 1:43:17 AM GMT
  • ForrestForrest Posts: 1,341
    edited 2005-12-10 03:39
    You need to use a DB9 straigtht thru cable to connect the BS2 to your serial port, NOT a null-modem cable. If you're not sure about the cable - each pin continuity on both ends of the cable with a multimeter.
  • KriscKrisc Posts: 16
    edited 2005-12-10 03:49
    Forrest said...
    You need to use a DB9 straigtht thru cable to connect the BS2 to your serial port, NOT a null-modem cable. If you're not sure about the cable - each pin continuity on both ends of the cable with a multimeter.

    I am using this... http://www.parallax.com/detail.asp?product_id=800-00003
  • knightofoldcodeknightofoldcode Posts: 233
    edited 2005-12-10 07:33
    Krisc, can you send us a diagram of your connections? You have to make certain that on the VDD pin you ONLY PUT FIVE VOLTS to it. Anything more, and it'll fry it! Anything less and it simply won't work.

    The 12V has to be connected to the VIN pin, NOT the VDD Pin!

    Please send a schematic! [noparse]:)[/noparse]

    Knight.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
    This message transmitted with 100% recycled electrons.
    -=-=-=-=-=-
    Gravity doesn't exist. The Earth sucks.
    -=-=-=-=-=-
    Make a man a fire, and he will be warm for the night.
    Light the man on fire, and he will be warm for the rest of his life.
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
Sign In or Register to comment.