Shop OBEX P1 Docs P2 Docs Learn Events
Simple Question on a switch — Parallax Forums

Simple Question on a switch

MrDookuMrDooku Posts: 2
edited 2007-02-18 04:11 in General Discussion
Hi-

I am having trouble connecting a switch (on/off) to the javelin stamp.· I'd like to connect a switch and be able to read the state of the switch with readPin.

This sounds really simple but I'm not sure how to wire it up.

1:· I tried connecting a 10K resistor to P11, and then connecting the switch to that and VSS.

With the switch open, readPin on pin 11 gives alternating 0 and 1 values.. Funny.· With the switch closed I get a true for P11.

2: I tried connection a 10K resistor from P11 to VDD, then running the switch across that to VSS.··
My power light goes out when I throw the switch.· Scary!·


It's funny, because I have pins 1-7 driving a fairly complicated set of amplifiers·--> relays --> solenoids running some cool robotics.· No problems there.· But I am having the hardest time with a switch...

Any suggestions
Thanks
Mr Dooku
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-18 03:52
    For reference, download "What's a Microcontroller?" tutorial from the Stamps in Class portion of Parallax's website. It has all kinds of information on connecting stuff to Stamps and the same thing apply to the Javelin.

    Connect the 10K resistor between pin 11 and either Vdd or Vss depending on what you want for an "off" reading (Vss for low and Vdd for high). The switch goes between pin 11 and the other power supply terminal. If the resistor is connected to Vdd, connect the switch to Vss. If the resistor is connected to Vss, connect the switch to Vdd. The idea is that the resistor holds the I/O pin in the default state and the switch forces the I/O pin to the other state. The reason for the resistor is to limit the current when you close the switch (that's why the light went out!)

    The reason you got the "unstable" readings when the switch was open is that the I/O pin wasn't connected to anything (effectively) and it would tend to float around the middle of its range. It's a high impedance point and static and noise in the area would drive it one way or the other just enough to read as high or low.
  • MrDookuMrDooku Posts: 2
    edited 2007-02-18 04:11
    Mike-

    Thanks, that worked perfectly!

    Your explanation was spot on.· I didn't have a clue about vss holding the pin in one state and the switch toggling it to another, but it makes sens now.· That·floating 1/0 value had me pretty puzzled.

    There's more going on here than a regular light switch.· [noparse]:)[/noparse]

    Thanks
    MD
Sign In or Register to comment.