Shop OBEX P1 Docs P2 Docs Learn Events
Newbie question — Parallax Forums

Newbie question

deejayspinzdeejayspinz Posts: 6
edited 2010-09-17 00:24 in BASIC Stamp
Hi all,

I have a newb question about a project I am working on. It is about using momentary switches to trigger actions. I did some research and found the button command, but want to understand more about how to actually hook up the switch. Is it as simple as connecting the switch between 2 pins, setting 1 high and monitoring the second to see when it goes high and performing some action? Are there more efficient ways of doing this? Any other components that should be used (eg resistors?)

There are two things I would like to do:

1) to conserve battery power, I plan on having an LCD hooked up to display status info, but I dont want the LCD to be always on. So I was thinking that pressing the switch would turn the LCD on for say 5 seconds for example (and display stats), then turn back off.

2) I will be driving a number of IR LEDs as a Beacon using another part of the application. I have a robot that will 'dock' to the beacon and would like to turn off the PIN that drives the LED's when another switch is pressed (and remains pressed while the robot is docked).

Suggestions or code samples would be much appreciated. Thx!

Comments

  • eod_punkeod_punk Posts: 146
    edited 2010-09-15 04:53
    Check out "What's a Microcontroller" (WAM). You can download it for free here.
    http://www.parallax.com/Store/Books/AllBooks/tabid/763/CategoryID/41/List/0/SortField/0/catpageindex/2/Level/a/ProductID/139/Default.aspx

    One of the early chapters talks about how to hookup a push button.
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-09-15 07:51
    The BUTTON instruction is a switch debounce routine so you don't have to write one of your own. When a button is pressed, the contacts can/will "bounce" or have periods of intermittent contact before fully engaged..... So you write a debounce routine (or use BUTTON) to ignore changes in state for a period of time..... I like 20ms, but it's really whatever works..... switch dependent I'm sure.

    If I were doing this, I'd designate one pin on the BS as the button input..... tie the input to ground through a 10k resistor (so the input doesn't float) then hook your input to +5 through the switch:

    The 10k resistor bleeds any noise to ground off the input pin. When you supply +5 to the input via the switch 0.5mA is bled though the resistor to ground. That lost current is TINY so the BS sees the HI state on the input pin.

    Use your button instruction, set it to look for a HI state, set the debounce duration to 20ms and let it fly. If the results are flaky, you might need to increase the duration to as much as 100ms.
  • deejayspinzdeejayspinz Posts: 6
    edited 2010-09-15 12:28
    Thanks for the suggestions gang. One question - Im supplying power via 9V battery. What is the best way to obtain a 5V source? Can I choose another pin and set it to hi at the beginning of the app and use it? Im using a Basic Stamp 2SX btw.
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-09-15 14:22
    You didn't mention which BS module you are using, however:

    If you are using a 9V battery straight to the BS module (Not BOE board) then you should be powering the Vin pin (pin 24 on the 2px for example). The BS has an in-chip regulator and will allow you to use this regulator to power stuff..... so to pick 5V off the BS you'd connect your accessories to VDD (pin 21 of the 2px for example)

    Be warned though, you can't pull a huge amount of power off the in-chip regulator and a short circuit could be very bad. You could fuse it, use a current limiting resistor or use a separate voltage regulator cheap from Radio Shack. Be careful.

    Look in your manual, or pull the schematic off Parallax to determine which pin supplies 5V from your particular BS

    P.S. I use the term "In-chip" loosely.... just to eliminate confusion
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-09-15 14:23
    deejayspinz

    What is the best way to obtain a 5V source? Can I choose another pin and set it to hi at the beginning of the app and use it?

    The PIN marked VDD is 5 volt How Ever DO NOT use it for any more than LED and very small servo not more than 100 milliamps MAX

    Im supplying power via 9V battery.

    This will not last long you need to use a wall wart or nicads to power your board
  • deejayspinzdeejayspinz Posts: 6
    edited 2010-09-15 15:42
    [
    Spiral_72 wrote: »
    You didn't mention which BS module you are using
    Actually, I did, look up :-). Stamp Stack 2 SX - just missed the 'stack' bit. Dont think that the board has a dedicated 5V output. I found the samples in the manual and it appears that I can set one pin to high and with some resistors to GND, I can detect it. Thx all for helping me get some direction.
  • ercoerco Posts: 20,256
    edited 2010-09-16 16:21
    Re: battery life. A 9-volt battery is convenient, but won't last very long. Not much current capacity there. You're better off using 4 AAA or even better 4 AA cells in series. You can hook that to the Stamp's Vin pin. Alternatively, you could drop that 6+ volts down to ~5V through 2 series silicon diodes. This 5-ish volt supply (always test to be sure, don't go over 5.5V) can power all your other circuitry, and be applied to your Stamp's Vdd pin.
  • AmaralAmaral Posts: 176
    edited 2010-09-17 00:24
    [
    Actually, I did, look up :-). Stamp Stack 2 SX - just missed the 'stack' bit. Dont think that the board has a dedicated 5V output. I found the samples in the manual and it appears that I can set one pin to high and with some resistors to GND, I can detect it. Thx all for helping me get some direction.

    You want to set a Pin High and drive you LCD by it ?

    The Stamp SX can Source/Sink : 30 mA / 30 mA current per I/O, witch means that you CAN NOT drive anything larger than that .. but that is not the best way to power anything anyway, the minimum you could do is connect this CONTROL I/O Pin (Let's call it POWER Pin) to and 1K Ohm resistor and to the BASE pin of an transistor, and let the weigh all for the transistor. Take a look at Nuts $ Volts #06. You can use the 5 Volt pin Vcc (Pin 21 on ALL DIP24 Basic Stamp) as an output, but it's not recommended just because the 5 Volt regulator of the BS module itself is considered an delicate power supply (due to size and funcionality).

    Hope to Help

    Amaral.
    pdf
    374K
    nv6.pdf 374.1K
Sign In or Register to comment.