Switches
Hello Everyone,
I am having a most difficult time using a simple momentary (normally
open) SPST switch. My code seems to be okay, but I'm starting to
doubt the wiring. I have a one leg of the switch going to the I/O
pin. The other leg of the switch connected to 5V+. I have a 10K
resistor connected from I/O pin to ground. I got the connection out
of the book dealing with the button function.
My Code uses the example in the programming manual on page 250 for
those who use it. The state never changes when I press the button.
If false then it is always false, etc...regardless if the button is
pressed or not on the switch.
Can anyone see the error of my ways?
Thanks,
FS
I am having a most difficult time using a simple momentary (normally
open) SPST switch. My code seems to be okay, but I'm starting to
doubt the wiring. I have a one leg of the switch going to the I/O
pin. The other leg of the switch connected to 5V+. I have a 10K
resistor connected from I/O pin to ground. I got the connection out
of the book dealing with the button function.
My Code uses the example in the programming manual on page 250 for
those who use it. The state never changes when I press the button.
If false then it is always false, etc...regardless if the button is
pressed or not on the switch.
Can anyone see the error of my ways?
Thanks,
FS
Comments
The button command must be in a loop; does your code do this?
Ray McArthur
Original Message
From: <Forbesits@y...>
To: <basicstamps@egroups.com>
Sent: Wednesday, December 27, 2000 11:46 PM
Subject: [noparse][[/noparse]basicstamps] Switches
> Hello Everyone,
>
> I am having a most difficult time using a simple momentary (normally
> open) SPST switch. My code seems to be okay, but I'm starting to
> doubt the wiring. I have a one leg of the switch going to the I/O
> pin. The other leg of the switch connected to 5V+. I have a 10K
> resistor connected from I/O pin to ground. I got the connection out
> of the book dealing with the button function.
>
> My Code uses the example in the programming manual on page 250 for
> those who use it. The state never changes when I press the button.
> If false then it is always false, etc...regardless if the button is
> pressed or not on the switch.
>
> Can anyone see the error of my ways?
>
> Thanks,
> FS
>
>
>
>
Yes it is in a loop.
Loop:
Button .....
condition code
goto Loop
BranchLine:
condition code ....
Thanks,
FS
--- In basicstamps@egroups.com, "Ray McArthur" <rjmca@u...> wrote:
> Hi FS,
>
> The button command must be in a loop; does your code do this?
>
> Ray McArthur
>
>
Original Message
> From: <Forbesits@y...>
> To: <basicstamps@egroups.com>
> Sent: Wednesday, December 27, 2000 11:46 PM
> Subject: [noparse][[/noparse]basicstamps] Switches
>
>
> > Hello Everyone,
> >
> > I am having a most difficult time using a simple momentary
(normally
> > open) SPST switch. My code seems to be okay, but I'm starting to
> > doubt the wiring. I have a one leg of the switch going to the
I/O
> > pin. The other leg of the switch connected to 5V+. I have a 10K
> > resistor connected from I/O pin to ground. I got the connection
out
> > of the book dealing with the button function.
> >
> > My Code uses the example in the programming manual on page 250
for
> > those who use it. The state never changes when I press the
button.
> > If false then it is always false, etc...regardless if the button
is
> > pressed or not on the switch.
> >
> > Can anyone see the error of my ways?
> >
> > Thanks,
> > FS
> >
> >
> >
> >
Why don't you post your actual code so we can look it over.
Tim
[noparse][[/noparse]Denver, CO]
>
> Hi,
>
> Yes it is in a loop.
> Loop:
> Button .....
> condition code
> goto Loop
>
> BranchLine:
> condition code ....
>
> Thanks,
> FS
error, if their is one.
Good luck,
Ray McArthur
Original Message
From: <Forbesits@y...>
To: <basicstamps@egroups.com>
Sent: Thursday, December 28, 2000 12:04 AM
Subject: [noparse][[/noparse]basicstamps] Re: Switches
> Hi,
>
> Yes it is in a loop.
> Loop:
> Button .....
> condition code
> goto Loop
>
> BranchLine:
> condition code ....
>
> Thanks,
> FS
>
> --- In basicstamps@egroups.com, "Ray McArthur" <rjmca@u...> wrote:
> > Hi FS,
> >
> > The button command must be in a loop; does your code do this?
> >
> > Ray McArthur
> >
> >
Original Message
> > From: <Forbesits@y...>
> > To: <basicstamps@egroups.com>
> > Sent: Wednesday, December 27, 2000 11:46 PM
> > Subject: [noparse][[/noparse]basicstamps] Switches
> >
> >
> > > Hello Everyone,
> > >
> > > I am having a most difficult time using a simple momentary
> (normally
> > > open) SPST switch. My code seems to be okay, but I'm starting to
> > > doubt the wiring. I have a one leg of the switch going to the
> I/O
> > > pin. The other leg of the switch connected to 5V+. I have a 10K
> > > resistor connected from I/O pin to ground. I got the connection
> out
> > > of the book dealing with the button function.
> > >
> > > My Code uses the example in the programming manual on page 250
> for
> > > those who use it. The state never changes when I press the
> button.
> > > If false then it is always false, etc...regardless if the button
>doubt the wiring. I have a one leg of the switch going to the I/O
>pin. The other leg of the switch connected to 5V+. I have a 10K
>resistor connected from I/O pin to ground. I got the connection out
>of the book dealing with the button function.
>...
> Loop:
> Button .....
> condition code
> goto Loop
>
> BranchLine:
> condition code ....
Verify the wiring with a simple loop program:
loop:
debug bin1 in0 ' if connected to P0
goto loop
Should show 1's only while the switch is pressed, otherwise 0's. It
is easy to refer to the wrong pin number. The button command adds
complexity that can mask simple problems.
good luck,
--- Tracy
btnWk var byte
btnWk = 0
Loop:
BUTTON 7,0,255,250,btnWk,0,noPress
debug "* "
noPress: goto loop
Before using the button command I used a loop like this:
The state never changed.
Loop:
debug bin in7,cr
goto Loop
--- In basicstamps@egroups.com, Tracy Allen <tracy@e...> wrote:
> >My code seems to be okay, but I'm starting to
> >doubt the wiring. I have a one leg of the switch going to the I/O
> >pin. The other leg of the switch connected to 5V+. I have a 10K
> >resistor connected from I/O pin to ground. I got the connection
out
> >of the book dealing with the button function.
> >...
>
>
> > Loop:
> > Button .....
> > condition code
> > goto Loop
> >
> > BranchLine:
> > condition code ....
>
> Verify the wiring with a simple loop program:
>
> loop:
> debug bin1 in0 ' if connected to P0
> goto loop
>
>
> Should show 1's only while the switch is pressed, otherwise 0's.
It
> is easy to refer to the wrong pin number. The button command adds
> complexity that can mask simple problems.
>
> good luck,
> --- Tracy
>The state never changed.
>
>Loop:
> debug bin in7,cr
>goto Loop
What state does it indicate, 1 or 0?
If you have a voltmeter, verify that the voltage on P7 does in fact
change from zero to +5 volts.
N.O. switch
P7
o----//---- Vdd=5 volts
|
|
'---/\/\--- Vss=0 volts
10kohm
Are you sure that the pushbutton and the resistor are connected to P7
and to the power supplies? Wiring errors are too easy!
Are the legs of the switch are connected correctly? Some pushbuttons
have 4 legs, and it is quite easy to mistake which ones to use.
Are you sure that P7 is configured as an input? (it will be an input
by default when the BS2 is reset)
input 7
loop:
debug bin in7
goto loop
good luck
-- Tracy
http://www.emesystems.com/BS2fsm.htm <-- more info on button command
> Hello,
>
> input 7
> Loop:
> debug bin in7,CR
> goto Loop
>
> Actually, the state reports mostly ones, but it is sometimes erratic
> and reports a mixture of 1's and 0's.
This is usually a pretty clear indication that your input pin is
"floating" i.e., not being driven to a high or low logic level,
probably because the pin is not connected to anything.
Let's review some basics. Your Stamp has 28 pins, including 16 I/O
pins. If you orient your Stamp so that the largest chip is to
the right, then I/O #7 is at the extreme right of the 14 pins on the
bottom.
It looks like you have good power and ground to the Stamp or it
wouldn't be accepting your programs and sending DEBUG data back.
With the program you have shown above, try this simple test. Take a
wire and carefully touch one end to physical pin #4 (fourth from the
left on the the bottom row). Touch the other end to I/O #7. This
creates a direct path to ground (a "low" logic level) for that I/O
pin. You should see the DEBUG display indicating zeroes whenever
the wire connection is made.
When you have this working, connect your resistor between I/O #7
and physical pin #21 (fourth from the left on the top row). This
connects the I/O pin to a "high" logic level. In this case, you
should see ones on the DEBUG screen when the connection is made.
When you have this working, leave the resistor connected as above
and use your wire again to make momentary contacts between I/O #7 and
ground on physical pin #4. This configuration causes the I/O pin to
see a default high logic level through the resistor, but a low logic
level if the wire connection is made. In essence you are doing with
the wire what the switch would do if it's working right. The DEBUG
display should show solid ones when the wire is not connected, and
solid zeroes when it is.
Finally, substitute your switch for the wire. If the wire worked
OK but the switch doesn't you probably have a bum switch.
Steve
input 7
Loop:
debug bin in7,CR
goto Loop
Actually, the state reports mostly ones, but it is sometimes erratic
and reports a mixture of 1's and 0's. Pressing the button has no
effect :-(
The voltmeter did reflect some light. The voltage went from 0 to 4.8
volts. I used a smaller resistor other than the 10K one but still to
no effect. The voltage was up to 5V. I stopped using the stamps
power source and used a seperate power source and still no effect. I
even changed to a different switch button. (By the way, the button
has only two legs.)
I've been working on this a long time and I'm at the point of giving
up for a while because something so simple should not be so hard.
Before I do, below I have described again my wiring. Hopefully
there's a simple error there.
Here's a breadboard illustration incase I am not interpreting the
schematics correctly:
_______ ______ ______
row 1 | | | _|_ | _|_
row 2 I/O pin _|_ _|_ _|_ 5V _|_ GND
Thanks
--- In basicstamps@egroups.com, Tracy Allen <tracy@e...> wrote:
> >Before using the button command I used a loop like this:
> >The state never changed.
> >
> >Loop:
> > debug bin in7,cr
> >goto Loop
>
> What state does it indicate, 1 or 0?
>
> If you have a voltmeter, verify that the voltage on P7 does in fact
> change from zero to +5 volts.
>
> N.O. switch
> P7
o----//---- Vdd=5 volts
> |
> |
> '---/\/\--- Vss=0 volts
> 10kohm
>
> Are you sure that the pushbutton and the resistor are connected to
P7
> and to the power supplies? Wiring errors are too easy!
>
> Are the legs of the switch are connected correctly? Some
pushbuttons
> have 4 legs, and it is quite easy to mistake which ones to use.
>
> Are you sure that P7 is configured as an input? (it will be an
input
> by default when the BS2 is reset)
> input 7
> loop:
> debug bin in7
> goto loop
>
> good luck
> -- Tracy
> http://www.emesystems.com/BS2fsm.htm <-- more info on button
command
>Loop:
> debug bin in7,CR
>goto Loop
>Actually, the state reports mostly ones, but it is sometimes erratic
>and reports a mixture of 1's and 0's. Pressing the button has no
>effect :-(
As Steve P. pointed out, the erratic response indicates that the pin
is open, not connected to anything.
>The voltmeter did reflect some light. The voltage went from 0 to 4.8
>volts.
That is a good sign!
Where did you probe the (+) voltage? Do it right on the Stamp pin.
Logical P7 is actually pin 12 of the 24-pin BS2 carrier. Or as
Steve said, it is also physical pin 14 on the SX28 chip that is
mounted on top of the carrier. I guess I should ask, are you using
the 24 pin BS2 module--and what breadboard?
>Here's a breadboard illustration incase I am not interpreting the
>schematics correctly:
>
> _______ ______ ______
>row 1 | | | _|_ | _|_
>row 2 I/O pin _|_ _|_ _|_ 5V _|_ GND
I do not quite understand this diagram. Which line is which part?
The real test is the voltage probed at the I/O pin, pin 12 on the
physical carrier board for logical P7.
-- Tracy Allen
electronically monitored ecosystems
http://www.emesystems.com
work with a basic stamp revb that will control when a servo will move.
I got it to work with a switch like the reset button.
When i wire the other the servo just moves back and forth constaly.
Can someone help??
reopeadres@y...