Shop OBEX P1 Docs P2 Docs Learn Events
Possible Problems with basic stamp — Parallax Forums

Possible Problems with basic stamp

morris4019morris4019 Posts: 145
edited 2009-05-08 01:37 in BASIC Stamp
I'm trying to test to make sure that i did not blow any of my pins while i was testing a program for a stepper motor. I'm wondering what resistor you guys think i should put in between 9v for the stamp to see a logic 1 or 0. You know what i mean, I'm trying to write a small program that I can test the pins as inputs to make sure everything is aok. I have one rail (the rail with the stamp connected running 9v, letting the onboard voltage regulator take care of it), and the other rail i have a 7805 with 5v regulated. I figured I could get away with running a jumper from pos to pin 0 (or whatever pin i was testing) through a resistor to get a logic 1 or 0 you know. But what size should it be?


-Mike

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
======

······ I'll try everything once [noparse]:)[/noparse]

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-07 20:19
    10K should work. The protective diode on the I/O pin can tolerate around 500ua and it begins conducting around 5.6V. 9V - 5.6V is 3.4V. By Ohm's Law, the resistance = 3.4V / 0.0005A = roughly 7K.
  • morris4019morris4019 Posts: 145
    edited 2009-05-07 21:17
    Ok thanks i'll give that a try. I did not want to do a test & check before i heard what you all had to say. I did not want to break the stamp.

    Thank you
    -Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ======

    ······ I'll try everything once [noparse]:)[/noparse]
  • morris4019morris4019 Posts: 145
    edited 2009-05-07 21:24
    Well here is the problem. I have tried with 5v and with 9v through a 10k resistor (brown/black/orange) to pin 0. For ease i have hooked it up through a switch, so when i press the switch the power goes through to pin 0. Below is the small sample code i am using and i am not getting any movement from 0 to 1 or vice versa when the button is pressed.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    top:
    IF (IN0=0) THEN DEBUGzero

    IF (IN0=1) THEN DEBUGone
    GOTO top

    DEBUGzero:
    DEBUG HOME, "Pin 0= 0"
    GOTO top

    DEBUGone:
    DEBUG HOME, "Pin 0= 1"
    GOTO top

    The debug window just stays at "Pin 0 = 1"... ????

    -Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ======

    ······ I'll try everything once [noparse]:)[/noparse]
  • morris4019morris4019 Posts: 145
    edited 2009-05-07 21:54
    I am getting ready to test a small stepper motor. I'm using LED's in place of the stepper motor, to get the pattern right, and verify my code. My pattern is fine, then I add a script that I thought should switch the direction of the LEDs (in place of the motor). I have, like you said, a switch with a 10k resistor comming from pos(+) to pin 15. When the switch is pressed It should switch the variable "direction" so that the lights go in reverse. But for some reason I can't get any of my inputs to work, maybe i am not using them properly. Here is the code:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    DIRA=$F 'Make the first 4 pins outputs
    INPUT 15 ' Make pin 15 an input for which direction we are going to run.

    delay CON 50 'Set a constant for time delay. (1/2 second)
    index VAR Byte 'Index is used for our counter.
    pattern VAR Byte 'Pattern is used for the particular pattern were on.
    direction VAR Bit 'Set a variable for which direction we are moving.


    top:

    IF (IN15=0) THEN
    direction=0
    ELSEIF (IN15=1) THEN
    direction=1
    ENDIF

    IF (direction=1) THEN

    FOR index = 0 TO 7
    LOOKUP index, [noparse][[/noparse]%0001, %0011, %0010, %0110, %0100, %1100, %1000, %1001], pattern
    OUTA=pattern
    PAUSE delay
    NEXT

    ELSEIF (direction=0) THEN

    FOR index = 0 TO 7
    LOOKUP index, [noparse][[/noparse]%0001, %0011, %0010, %0110, %0100, %1100, %1000, %1001], pattern
    OUTA=pattern
    PAUSE delay
    NEXT

    ENDIF

    GOTO top


    I will take a picture of my breadboard to show you how i have hooked up everything. It will be on here in just a few minutes.

    -Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ======

    ······ I'll try everything once [noparse]:)[/noparse]

    Post Edited (morris4019) : 5/7/2009 10:05:44 PM GMT
    640 x 480 - 62K
    640 x 480 - 62K
  • Clive WakehamClive Wakeham Posts: 152
    edited 2009-05-08 00:45
    I had a quick look at your first program.

    Did you realise that the Basic Stamp inputs "float" unless they are tied to +5v or to Gnd via a resistor?

    Because if you don't have a set condition for the program, you can't really read a different condition.
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-05-08 01:00
    A minor suggestion to your code.

    If you are testing variable which is logical, has only possible values 0 or 1, than IF statement needs only one evaluation:

    IF value = 1 THEN·· ' explicit test·for 1

    ·· statement(s)

    ELSE··················· ' implied "test" for 0

    ·· statement(s)

    ENDIF
  • morris4019morris4019 Posts: 145
    edited 2009-05-08 01:10
    So, Clive, how would I say, use a switch to control a the logic signal. The way I set it up was one side of switch going directly to the input pin. The other side of switch goes to a resistor and then pos(+). Is this not right? I figured that with no signal going to the pin it would be a 1 and with signal would be a 0.

    It does kind of make sense though, because this is why i am thinking i have a problem. Now mind you, i have no problems doing basically anything, except when it comes to inputs. If i have nothing connected to an input pin, when you would think it gets no signal, it randomly seems to get some sort of signal, which blinks the light every once in awhile. Thats why i was thinking that my stamp may be messed up.

    But how else should i connect a switch? I will be using just a small push button switch, and a 9v battery.

    Also, vaclav_sal, thanks for the tip. I have originally wrote it that way, but when i was getting unexpected results I went more specific and thought that way i could rule out code.

    Thanks everyone.
    -Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ======

    ······ I'll try everything once [noparse]:)[/noparse]
  • Clive WakehamClive Wakeham Posts: 152
    edited 2009-05-08 01:18
    Tie the pin to the +5v via a 10K resistor and have the switch connected to the pin and when you press it, it will earth the pin. This will show the pin going from logic 1 to logic 0. Of course you can swap it around and connect it to the earth via the resistor and the switch will then connect +5v to it giving a logic 0 to a logic 1.

    You should also think about changing the IN15 command to the (better) BUTTON command which will debounce the switch.
  • morris4019morris4019 Posts: 145
    edited 2009-05-08 01:37
    Awesome!!! YAY! I thought my STAMP was broken, but it is working fine. Thanks clive for the tip on the "floating" inputs. Works just as expected.

    -Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ======

    ······ I'll try everything once [noparse]:)[/noparse]
Sign In or Register to comment.