Shop OBEX P1 Docs P2 Docs Learn Events
noob... basic pushbutton input to light LED... problem — Parallax Forums

noob... basic pushbutton input to light LED... problem

maxx233maxx233 Posts: 11
edited 2009-08-15 01:39 in BASIC Stamp
So I'm going through the "what's a microcontroller" tutorial, and ch3 (digital input) has a circuit to push the little button and have the stamp read the input signal and flash an LED as long as the button's depressed. Mine doesn't work :\ After fiddling for an hour I've figured out that when I turn the board off, then back on... it'll pretty much work for up to 8 seconds or so. It will indeed actually flash the LED as it's supposed to. But then it stops. And it won't work again after that until I reset the board. And if I reset the board, but then write the same program to it again, it won't work even if I haven't tried it yet since the last reset. At this point I'm pretty sure my programming logic works, since it does blink immediately after reset when I push the button. Why does it stop working/never works after writing to the board? I don't want to keep trying if I'm missing something stupid and jack up my stamp, but receiving input is kinda pivotal and all [noparse];)[/noparse] So I figure I'll put it down for tonight and ask you fine folks. Any help is much appreciated, thanks!

maxx

Comments

  • jbalatjbalat Posts: 96
    edited 2009-08-13 11:00
    Please post your code ?
  • DufferDuffer Posts: 374
    edited 2009-08-13 13:25
    Tried fresh batteries?
  • maxx233maxx233 Posts: 11
    edited 2009-08-13 18:09
    Here's the code I'm using.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DO
    DEBUG ? IN3
    IF (IN3 = 1) THEN
      HIGH 14
      PAUSE 50
      LOW 14
      PAUSE 50
    ELSE
      PAUSE 100
    ENDIF
    LOOP
    


    I'm not getting the LED blinking, and and I'm only showing 0s in the debug window except for briefly & sporatically after powering the board on and trying it - it'll show 1s (with a couple 0s mixed in), and the light will blink for a while.


    I have it plugged in with a wall wart, so no batteries.

    I had it all plugged in on an offboard protoboard originally for easy working, and after posting I feared that might have been the culprit somehow. So I took it all apart and put it on the onboard proto area exactly as in the book, to no avail. It seemed like it was working better, but it was just because I'd turned it off while plugging it all back in, so when I turned it back on it worked for a while.
  • FranklinFranklin Posts: 4,747
    edited 2009-08-13 18:33
    50 miliseconds is not a long time. try 500 while you are testing and reduce it later if need be.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • maxx233maxx233 Posts: 11
    edited 2009-08-13 18:36
    Franklin said...
    50 miliseconds is not a long time. try 500 while you are testing and reduce it later if need be.

    I'll try it, but even the debug window shows no input, so I don't think it's a matter of just not seeing the light or anything unforetunately :\
  • FranklinFranklin Posts: 4,747
    edited 2009-08-13 18:52
    Sounds like your circuit is pulling the batteries down or you are powering the led through the stamp and overtaxing the on board regulator.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-13 19:14
    Without a schematic, it's impossible to tell, but do you have a current limiting resistor for the LED in series with the Stamp I/O pin. 330 Ohms or 470 Ohms is a common value used.
  • maxx233maxx233 Posts: 11
    edited 2009-08-13 20:01
    Yeah, I've got a 470 Ohm in series with the LED. I'm using the same code and schematic as in the book, seen here on page 81 (page 90 of the PDF itself)...

    I'll post a pic (hopefully it shows up!) I took last night and never posted it because I thought it'd just be confusing (plus to further confuse things, now I've moved everything onboard to match the book exactly, just to rule that factor out) It's hard to see what's going on, but basically there's three long jumpers (black, red, green) from the board to an external proto board where I put the switch, just for ease & space. So hopefully you can see the circuit (and hopefully I didn't screw it up!) Like I said, now I've moved it all onboard to reduce problem factors, but still no go.

    Franklin, I see what you mean now about reducing the blink rate - like maybe it was just blinking so fast it was overtaxing the regulator? In the exercise before this one I had it blinking at 1 to 50 milliseconds on a for next counter, so it has blinked faster before and worked, but it's worth a shot - I'll try reducing the pause when I get home just to verify. I've been in IT for a long time, specifically programming for the last year or so, and at this point I'm getting the distinct feeling that I screwed something incredibly simple up - or there's a problem with the board :\
    2048 x 1536 - 627K
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-13 20:24
    The diagram on page 76 of WAM? is what you need. If that's what you actually have hooked up, the I/O pin will become high when you push the button and low when you're not pushing it. I assume you've changed the delays in your program as Franklin suggested to at least 500ms. If you used the diagram on page 79, it works the opposite way, high when not pushed and low when pushed.

    The LED has a polarity and the book (WAM?) shows how to tell which end is which. It won't light if it's hooked up backwards.
  • maxx233maxx233 Posts: 11
    edited 2009-08-13 20:32
    Yup, I've got it as on page 76 and 81. The polarity on the LED is correct. The killer complication is the fact that it *does* work correctly when I first turn the board on, but only for a couple seconds. Franklin's suggestion I'm trying when I get home. It seems logical - something must be overloading or whatnot for it to stop working. I'm also going to try changing out the resistor going to the input pin, even though it measured out right on my meter
  • $WMc%$WMc% Posts: 1,884
    edited 2009-08-14 01:43
    Maxx233

    Try this

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DO
    HIGH 14
    PAUSE 1000
    LOW 14
    PAUSE 1000
    LOOP

    This will help with a wiring issue or a reset problem with the stamp.The LED should blink on and off @ around 1Hz (over and over)

    When I have trouble with something complicated, Its usually something simple that helps me fix it.

    __________$WMc%________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
  • maxx233maxx233 Posts: 11
    edited 2009-08-14 05:19
    OK... now I've got even more interestingness... I *think* I got it working by switching the side of the pushbutton that Vdd was coming in at. Not that polarity was wrong, more like the prong on the switch was broken, so switching it to the other electrically connected side worked. It was working great, for a couple minutes. Then I moved it all back over to my offboard proto area

    AND NOW... the stamp sees every input as being true! Finally to prove this I'm running this code:
    DO
    DEBUG HOME
    DEBUG ? IN2
    DEBUG ? IN3
    DEBUG ? IN4
    LOOP
    



    With *nothing* connected to the onboard proto area it's showing all 3 inputs as 1 in the debug window. What on earth?!? I mean, I suppose I could just switch my programming logic so that if IN3 = 0 then blink the light instead if IN3 = 1... but... obviously something's wrong :\ This newbie can't catch a break, what's goin on??
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-14 05:38
    You didn't say what's connected to I/O pins 2, 3, and 4. If there's nothing connected to them, they could show up as true or false or vary back and forth depending on how close your hand is to the board. Unconnected input pins are high impedance inputs. They draw virtually no current and are voltage sensitive. They react to nearby electrostatic fields including induced AC from nearby house wiring. Anything below 0.8V is low and anything above 2V is high. Anything between 0.8V and 2.0V is unknown and not guaranteed to be either.
  • maxx233maxx233 Posts: 11
    edited 2009-08-14 05:46
    OK... that's actually the first thing that's made some sense! [noparse]:)[/noparse] *twitch*... How do I tell it what's connected? I've definately noticed that if the board moves at all, or I accidently nudge a jumper cable with my finger while I'm holding the button it seems to tweak it out. Do I have to design my circuits so that when pushing a button there's like no chance of touching anything else, or the metal parts of the button even?
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-08-14 13:54
    Hardware rule #1:

    Unused (open) pins are undefined.

    Used input must be tied to + - pull up or - pull down potential via a resistor. 10 kOhms is fine.

    Your input pin3·should always read 0 (connected thru·pull down resistor of 10 KOhms to ground) if your button is not active.

    If·it reads anything else especially at random - you are missing this pulldown resitor.

    If you run

    Do

    DEBUG BIN ? INS··

    pause 1000

    loop

    You will see·all the inputs at once·and the "open" ones will almost always read 1. ( Unless you are using pull up resistors as mentioned above)
    ·
    ·
    ·
    Hardware rule #2
    The on board regulator is only for the board. It is temperature protected (to a degree) and will shut down when overloaded. ( this is where your several seconds of correct operation is comming from). Or let out the smoke in worst case!
    ·
    Your LED may draw more current than the regulator (especially the older bargain type one) can handle ( about 50 ma) and will make the regulator to shut down. And when it recovers it will ---·reset the processor and start over...
    ·
    Feed all external components via a separate supply - not via on board regulator.

    ·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-08-14 19:53
    As you can see in the pic provided, the OP has a Board_of_Ed and it·has a 7805-type regulator which supplies "V_dd" and he's using a wall-pack to run it.· So, there's no power issue as such.
  • maxx233maxx233 Posts: 11
    edited 2009-08-14 21:34
    OK.. FYI, my end conclusion is that there's something wrong with either my board or the stamp. So I spoke with parallax support and they thought it was very weird as well. I took a youtube video to show them, you can check it out too if you want at

    Anywho, long story short - I'm sending it back, they're going to test it and conclude once and for all that I'm either an idiot, or the unit is bad. ((crosses fingers for bad unit)) [noparse];)[/noparse]
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-08-14 23:25
    I see a problem here

    In the photo on page 81 show Vdd and the the 220 ohm on·one side of the switch ·and the 10k is on the Vss·of the switch and

    ·In the wiring diagram it show the 10 k and the 220 ohm on the Vss side· of the switch and Vdd on the other side of switch

    The one in the photo would make the INPUT HIGH when the switch is not pushed on a·NO switch and would not be LOW unless the button was pushed

    I have not· try-ed this set up to see how it really works but I will try it and see what happens the one in the photo


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-08-15 00:44
    Let's back off a little. I still think you do not have the pull down resistor wired correctly.
    Try this - disconnect both·LED and your switch.
    Connect·10kOhm resistor from IN3 to ground. Run the test I suggested without any other devices.
    Does IN3 reads 0 always? If yes than add your limiting resistor in series with this pull down resistor. Run the test again. Should have same result - IN3 reads 0.
    Now connect your switch to the junction of limiting resistor and pull down resistor.
    With the switch open you should read same – 0 on IN3. Now connect the other side of the switch to +.· Operate the switch and you should read 1 on IN 3.
    Ignore any other inputs or change the debug to read IN3 only.
    Remove the PAUSE from the test program!
  • maxx233maxx233 Posts: 11
    edited 2009-08-15 01:13
    Sal,
    I actually ended up getting the inverted input state working. Or rather, it started working properly just as randomly as it stopped working properly. Now all the inputs do show 0 as they should. But there's additional problems now/still: when I write a program to the stamp that deals with inputs at all, I have to power cycle the board before it will ever register the inputs. power cycle, not reset, etc. And it still stops working after a short while.

    But I did run through you whole suggestion, and everything is wired right - just to be sure, so thanks for that. At this point I'm pretty much resigned to an official ruling I think. Or rather, I will be when I package it back up and stick it in the mail in a bit.

    Thanks all, will post the outcome once I hear back from parallax!
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-08-15 01:39
    Now this is a long shot - are all the pins in the stamp module properly seated?
    I had an older long unused module and it would periodically quit. You have mentioned some intermittent behavior when you move you hand over. Also cold solder joints are possibility since it works for few seconds. Good luck.
    ·
Sign In or Register to comment.