Shop OBEX P1 Docs P2 Docs Learn Events
BS1: Need help creating a program that supports push button activation — Parallax Forums

BS1: Need help creating a program that supports push button activation

Mike_DeveloperMike_Developer Posts: 14
edited 2008-05-31 15:36 in BASIC Stamp
Hello guys.

I'm trying to create a BASIC Stamp 1 (module) program with the BASIC Stamp Editor (V2.4) that will control a stepper motor (the very stepper motor offered by Parallax) by activating the motor with the push of a button, which I'm sure I can add onto one of the pins of the micro-controller.

Basically, I downloaded the "sample" program for the stepper motor off the site. It works fine and everything, but instead of the micro-controller activating the motor automatically, I would like to program it so it It will activate with a physical push-button attached to what I'm sure can be the micro-controller.

Does anyone know how I can achieve this? Any input would be much appreciated.

Comments

  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-28 14:48
    Hmm... Is programming the BASIC Stamp to activate the stepper motor with a simple input push button really that difficult?

    Any suggestions would really be helpful.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-05-28 15:06
    Mike,

    Perhaps it’s a question of clarity…it’s not clear to me from reading your message what you mean by activate the Stepper Motor. Does it turn so many steps when the button is pushed? What does it do afterward? Does it wait for another button press? You also don’t mention if the push button is wired for active high or low. Perhaps if you post what you have that works with the stepper motor now we might be able to offer assistance in modifying the program based on additional input.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-28 15:16
    Chris Savage (Parallax) said...
    Mike,

    Perhaps it’s a question of clarity…it’s not clear to me from reading your message what you mean by activate the Stepper Motor. Does it turn so many steps when the button is pushed? What does it do afterward? Does it wait for another button press? You also don’t mention if the push button is wired for active high or low. Perhaps if you post what you have that works with the stepper motor now we might be able to offer assistance in modifying the program based on additional input.

    Actually, my problem is that I don't know what commands in the BASIC Stamp editor represent push button feature. And I also don't know how to wire the push button with the micro controller (meaning what pins do I have to use).

    Here's exactly what I'm looking as far as how the program should control the stepper motor:

    - Push button
    - Activate stepper motor (in high torque mode) one revolution clockwise
    - PAUSE 3.5 minutes OR push button again
    - Activate stepper motor (again, in high torque mode) one revolution counter-clockwise
    - Return to begining

    Post Edited (Mike_Developer) : 5/28/2008 3:31:12 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-05-28 15:32
    Mike,

    You need to start with the program you do have…or at least what I am assuming you have. It sounds like you have the Stepper Motor program. So that can be the base you build off from. In the BASIC Stamp Manual there are examples of how to connect a push button listed under the BUTTON command. Both active LOW and active HIGH are listed. Each would connect to one I/O pin. It may help to experiment with the examples and code given to understand how the BUTTON command works. Once you know how the BUTTON command works, and you also have working Stepper Motor code, then you can work on integrating them. Can you post the code that you do have? Also, how is you Stepper Motor connected to the BS1?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • ercoerco Posts: 20,259
    edited 2008-05-28 15:47
    http://www.me.umn.edu/courses/me2011/robot/technotes/stepper/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-28 15:50
    Sure no problem. This is the program I'm working with (I tweaked it alittle, but it should be very similar to the one offered by the website.) My goal is to add lines to the program to support a push button which will activate the first revolution clockwise. Then there will be a pause of 3.5 minutes OR I can push the button again and it will then turn counter-clockwise.

    By the way, the connection for my stepper motor is exactly how the website recommends it. It's driven by a ULN IC and the pins are the same as again, recommended

    Here's the program:

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    SYMBOL StpsPerRev = 48 ' whole steps per rev
    SYMBOL idx = B2 ' loop counter
    SYMBOL phase = B3 ' new phase data
    SYMBOL stpIdx = B4 ' step pointer
    SYMBOL stpDelay = B5 ' delay for speed control
    Full_Steps:
    EEPROM 0, (%00110000, %01100000, %11000000, %10010000)
    Setup:
    DIRS = %11110000 ' make P4..P7 outputs
    stpDelay = 7.5 ' set step delay
    Main:
    FOR idx = 1 TO StpsPerRev ' one revolution
    GOSUB Step_Fwd ' rotate clockwise
    NEXT
    PAUSE 500 ' wait 1/2 second
    FOR idx = 1 TO StpsPerRev ' one revolution
    GOSUB Step_Rev ' rotate counter-clockwise
    NEXT
    PAUSE 500 ' wait 1/2 second
    GOTO Main
    END
    Step_Fwd:
    stpIdx = stpIdx + 1 // 4 ' point to next step
    GOTO Do_Step
    Step_Rev:
    stpIdx = stpIdx + 3 // 4 ' point to previous step
    GOTO Do_Step
    Do_Step:
    READ stpIdx, phase ' read new phase data
    PINS = PINS & %00001111 | phase ' update stepper pins
    PAUSE stpDelay ' pause between steps
    RETURN
  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-28 16:47
    Oh god, I can't figure this out for the life of me... I know it should be easy, but for some reason I can't figure it out.

    Seriously, any help from you guys would be above and beyond appreciated yeah.gif
  • FranklinFranklin Posts: 4,747
    edited 2008-05-28 17:24
    Did you read erco's link? It seems to explain thing quite well and even has sample code to try.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-28 22:13
    Franklin,

    I did read the link he provided. Although it does touches on the stepper motor, it mentions little to nothing about Push Button activation.

    Again, I'm still looking for help with this. So if anyone can help me further, it would be very appreciated.
  • FranklinFranklin Posts: 4,747
    edited 2008-05-28 22:17
    BUTTON in the stamp editor help file is one way to do something depending on a pushbutton. try writing a program that will see button presses and light two leds, one for forward and one for reverse then replace that with your stepper code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-28 23:43
    FWIW - This is what I'm using on my stepper bot:

    START:
    IF PIN0 = 0 THEN RUN
    PINS=%00000111· '=============== Turn off all coils to save power
    GOTO START

    RUN:
    IF PIN1 = 0 THEN GO_SLOW
    DELAY=5
    IF PIN2 = 0 THEN CCW
    GOTO CW

    GO_SLOW:
    DELAY=10
    IF PIN2 = 0 THEN CCW

    CW:
    '====================================== Run CW
    PINS=%00110000 'I/O pins 0 and 1 high
    PAUSE delay
    PINS=%01100000 'I/O pins 2 and 3 high
    PAUSE delay
    PINS=%11000000 'I/O pins 3 and 4 high
    PAUSE delay
    PINS=%10010000 'I/O pins 3 and 0 high
    PAUSE delay
    IF PIN0 = 0 THEN CW
    GOTO START

    CCW:
    '====================================== Run CCW
    PINS=%10010000 'I/O pins 3 and 0 high
    PAUSE delay
    PINS=%11000000 'I/O pins 3 and 2 high
    PAUSE delay
    PINS=%01100000 'I/O pins 2 and 1 high
    PAUSE delay
    PINS=%00110000 'I/O pins 1 and 0 high
    PAUSE delay
    IF PIN0 = 0 THEN CCW
    GOTO START

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-05-29 04:09
    http://www.parallax.com/Portals/0/Downloads/appnt/stamps/bs1appnotes.pdf

    These are the AppNotes from the old BS1 manual, I'm looking around for the rest of it.· Anyway, you'll find several examples of BUTTONs.· You could even use INPUT.

    If you want to change your direction while it's turning, you'll have to check the BUTTON between steps, which will slow things·down a smidge.

    Post Edited (PJ Allen) : 5/29/2008 4:15:01 AM GMT
  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-30 13:38
    Steve in NM said...
    FWIW - This is what I'm using on my stepper bot:

    START:
    IF PIN0 = 0 THEN RUN
    PINS=%00000111 '=============== Turn off all coils to save power
    GOTO START

    RUN:
    IF PIN1 = 0 THEN GO_SLOW
    DELAY=5
    IF PIN2 = 0 THEN CCW
    GOTO CW

    GO_SLOW:
    DELAY=10
    IF PIN2 = 0 THEN CCW

    CW:
    '====================================== Run CW
    PINS=%00110000 'I/O pins 0 and 1 high
    PAUSE delay
    PINS=%01100000 'I/O pins 2 and 3 high
    PAUSE delay
    PINS=%11000000 'I/O pins 3 and 4 high
    PAUSE delay
    PINS=%10010000 'I/O pins 3 and 0 high
    PAUSE delay
    IF PIN0 = 0 THEN CW
    GOTO START

    CCW:
    '====================================== Run CCW
    PINS=%10010000 'I/O pins 3 and 0 high
    PAUSE delay
    PINS=%11000000 'I/O pins 3 and 2 high
    PAUSE delay
    PINS=%01100000 'I/O pins 2 and 1 high
    PAUSE delay
    PINS=%00110000 'I/O pins 1 and 0 high
    PAUSE delay
    IF PIN0 = 0 THEN CCW
    GOTO START

    When you mention PIN1 and PIN2, your telling the program that those are the I/O pins and NOT the IC (module) pins correct?

    Meaning PIN1 of my BASIC Stamp 1 module is the Vdd, however, Pin8 is the 1st input/output pin of my IC. So do I label it PIN8 or still PIN 1?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-30 13:44
    PIN0 through PIN7 are the 8 I/O pins of the BS1 and correspond to the module's pins 7-14
  • David H.David H. Posts: 78
    edited 2008-05-30 14:31
    Mike,
    Basically you run +5v to a pushbutton, and the other line to any pin (Lets say pin1) of the stamp. Then run a pull down resistor (10K is good) from the same pin to ground. This keeps the pin from floating high and giving odd reading. When you push the button, a 5v HIGH will be sent to that pin. In the program you write IF PIN1 = 1 THEN,... So when the HIGH (1) signal is received, the program will do what you want. Like go to a sub-routine like FORWARD, BACKWARDS, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    David


    There are 10 types of people in this world,...
    Those that understand binary numbers, and those that don't!!!
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-30 14:35
    "When you mention PIN1 and PIN2, your telling the program that those are the I/O pins and NOT the IC (module) pins correct?"

    Correct. I'm using a BS1 + four MOSFETs as a stepper motor controller (x2). IOW - A homemade version of a stepper controller IC.

    "Meaning PIN1 of my BASIC Stamp 1 module is the Vdd, however, Pin8 is the 1st input/output pin of my IC. So do I label it PIN8 or still PIN 1?"

    Just for clarity (That confused me.·blush.gif·), BS1 physical Pin-1 is Vin, physical pin-5 generates Vdd as long as Pin-1 is > +5VDC. My code refers to the logic state of PINS0-2, which are·controlled by another BS1, but could just as easily be connected to three push-buttons (and were during development). Since I'm not using a·controller IC, I·believe the answer to your second question is PIN8.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
  • David H.David H. Posts: 78
    edited 2008-05-30 14:52
    Steve,
    Please read Mike's reply above. The physical pin 8 in the Stamp's PIN1, and in your program it will always be referenced as PIN1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    David


    There are 10 types of people in this world,...
    Those that understand binary numbers, and those that don't!!!
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-30 15:09
    Yup. I didn't mean to contradict. Just to clarify (In my mind) what Mike_Developer was refering to when he said, "Meaning PIN1 of my BASIC Stamp 1 module is the Vdd, ..."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-30 15:15
    HA! I just caught the crappy job of commenting in my code:

    PINS=%00110000 'I/O pins 0 and 1 high

    They are?!?!

    Would you believe I/O pins·4 and·5 high??? smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
  • David H.David H. Posts: 78
    edited 2008-05-30 15:49
    COOL,...
    It's always nice when an error is found and things start to work again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    David


    There are 10 types of people in this world,...
    Those that understand binary numbers, and those that don't!!!
  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-30 16:16
    Ok, here is how I wired the pushbutton. I think it might be wrong because I'm assuming Pin 2 of the BS1 Module is ground. Help me out here please.

    rhrgfhmd5.png
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-31 00:31
    Well I HOPE pin 2 is GND. smilewinkgrin.gif

    The problem I see it that you're pulling PIN0(8) to GND through the 10K res, then shorting across the 10K res with the switch - STILL·pulling PIN0 to GND. It won't work. It can never change logic state from a·LOW to a HIGH.

    So...

    Leave the connections to PIN0(8) alone, and either move the other end of the switch to Pin-5 or the other end of the 10K res to Pin-5.

    Moving the resistor to Vdd will cause a pull UP = when the button is pushed PIN0(8) will go LOW.

    Moving the switch to Vdd will cause a pull DOWN = when the button is pushed PIN0(8) will go HIGH.

    Try this: BEFORE you change anything, run this code

    MAIN:
    B2 = PINS
    DEBUG B2
    GOTO MAIN

    I believe you'll find that the contents of B2 never change. Now make one of the modifications above and see what happens.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
  • Mike_DeveloperMike_Developer Posts: 14
    edited 2008-05-31 01:22
    Steve in NM said...
    Well I HOPE pin 2 is GND. smilewinkgrin.gif

    The problem I see it that you're pulling PIN0(8) to GND through the 10K res, then shorting across the 10K res with the switch - STILL pulling PIN0 to GND. It won't work. It can never change logic state from a LOW to a HIGH.

    So...

    Leave the connections to PIN0(8) alone, and either move the other end of the switch to Pin-5 or the other end of the 10K res to Pin-5.

    Moving the resistor to Vdd will cause a pull UP = when the button is pushed PIN0(8) will go LOW.

    Moving the switch to Vdd will cause a pull DOWN = when the button is pushed PIN0(8) will go HIGH.

    Try this: BEFORE you change anything, run this code

    MAIN:
    B2 = PINS
    DEBUG B2
    GOTO MAIN

    I believe you'll find that the contents of B2 never change. Now make one of the modifications above and see what happens.

    Thanks for the help, but I have a few questions. When you say move one end of either the resistor or the switch to Pin-5, do you mean the RESET pin 5 of the IC or the PIN5 (I/O) pin? Also, what will happen if I make the move, i mean, what will I accomplish by moving the ends of the wires?

    Also, you mention moving the same things to Vdd. Is that another option over moving to PIN 5 or is it something I also have to do alongside the initial move to Pin 5?

    Finally, what setup can I use if I DON'T want to include a 5V source with the button, or do I MUST include that?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-05-31 02:02
    You must use the 5V (Vdd).·

    P1 is whichever Pin you're using.· (You can disregard the LED part of this pic.)

    blackbird.jpg
  • Steve in NMSteve in NM Posts: 54
    edited 2008-05-31 15:36
    When you say move one end of either the resistor or the switch to Pin-5, do you mean the RESET pin 5 of the IC or the PIN5 (I/O) pin?

    Uh-oh.

    Go here, print this, and study the functions of the pins: http://www.engr.udayton.edu/faculty/jloomis/ece445/stamp/stmpsche.htm
    Pin-6 is the RESET pin. Pin-5 is Vdd - the output of an on-board·regulator that outputs 5VDC @ 50 mA as long as Vin (on Pin-1, Rev-B can accept 5-40VDC) is > 5 volts.

    "Also, what will happen if I make the move, i mean, what will I accomplish by moving the ends of the wires?"

    As you have it shown, you've got Pin-8(P1) hardwired to GND and no matter what you do, unless you change the configuration, you can't change the logic state from a LOW (0 or zero) to a HIGH (1 or one).

    "Also, you mention moving the same things to Vdd. Is that another option over moving to PIN 5 or is it something I also have to do alongside the initial move to Pin 5?

    Finally, what setup can I use if I DON'T want to include a 5V source with the button, or do I MUST include that?"

    In situations where your code is testing for a change in logic state from a 1 to a 0, the generally accepted practice is to connect the IO pin to Pin-5(Vdd) through a pull-up resistor.· PJ Allen's·picture illustrates it perfectly, and as I recall from feeble memory, is the way to go if you're concerned about battery life as it will draw very little current.·A minimal circuit is shown here on Page 29: http://www.hth.com/filelibrary/PDFFILES/bs1book.pdf

    THIS is what you don't have in your drawing. Notice that they're showing you both pull-up and pull-down configurations. In both cases, the point labeled "+5" is Pin-5 (Vdd) on the BS1-IC.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not a complete idiot! Some of my parts are missing.
Sign In or Register to comment.