BS1: Need help creating a program that supports push button activation
Mike_Developer
Posts: 14
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.
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
Any suggestions would really be helpful.
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
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
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
Seriously, any help from you guys would be above and beyond appreciated
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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.
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
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?
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!!!
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.··), 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.
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!!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm not a complete idiot! Some of my parts are missing.
PINS=%00110000 'I/O pins 0 and 1 high
They are?!?!
Would you believe I/O pins·4 and·5 high???
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm not a complete idiot! Some of my parts are missing.
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!!!
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.
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?
P1 is whichever Pin you're using.· (You can disregard the LED part of this pic.)
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.