Yoshihiro TSUBOI
/
A4988_sample
A simple sample to try to control stepper with Allegro A4988 stepper driver
Revision 0:b9c1a7c906f5, committed 2014-03-22
- Comitter:
- ytsuboi
- Date:
- Sat Mar 22 15:41:45 2014 +0000
- Commit message:
- first commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r b9c1a7c906f5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Mar 22 15:41:45 2014 +0000 @@ -0,0 +1,47 @@ +// simple A4988 sample +// jumper reset and sleep together +// connect VDD to mbed VOUT +// connect GND to mbed GND +// connect 1A and 1B to stepper coil 1 (GREEN and BLACK wire) +// connect 2A and 2B to stepper coil 2 (BLUE and RED wire) +// connect VMOT to power source (to AC adapter) +// connect GRD to power source (to AC adapter) +// connect STEP to mbed p22 +// connect DIR to mbed p21 + +#include "mbed.h" + +DigitalOut A4988STEP(p22); +DigitalOut A4988DIR(p21); +int a=0; + +int main() { + A4988DIR = 0; + A4988STEP = 0; + + while(1) { + if (a < 200) //sweep 200 step in dir 1 + { + a++; + A4988STEP = 1; + wait(0.008); + A4988STEP = 0; + wait(0.008); + } + else + { + A4988DIR = 1; + a++; + A4988STEP = 1; + wait(0.008); + A4988STEP = 0; + wait(0.008); + + if (a>400) //sweep 200 in dir 2 + { + a = 0; + A4988DIR = 0; + } + } + } +}
diff -r 000000000000 -r b9c1a7c906f5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Mar 22 15:41:45 2014 +0000 @@ -0,0 +1,1 @@ +http://world3.dev.mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43 \ No newline at end of file