Step 4Taking the Motor for a Test Drive
Hook up the wires directly up to your microproc and burn it up with the following code:
/* Playing with getting the small stepper motors driven. */ /* Include delay function */#define F_CPU 1000000UL #include /* Pin defs for ATTiny2313 */ /* Clockwise order */ #define BLUE _BV(PB0) #define BLACK _BV(PB1) #define RED _BV(PB2) #define YELLOW _BV(PB3) #define DELAY 200 /* milliseconds between steps */ int main(void){ DDRB = 0xff; /* Enable output on all of the B pins */ PORTB = 0x00; /* Set them all to 0v */ while(1){ /* main loop here */ PORTB = BLUE; _delay_ms(DELAY); PORTB = BLACK; _delay_ms(DELAY); PORTB = RED; _delay_ms(DELAY); PORTB = YELLOW; _delay_ms(DELAY); } }
How simple is that code? Really simple.
All it does is make some nice definitions so I could refer to the wires by color rather than their pin-names, and then it toggles them on in sequence with an adjustable delay in between. For starters, I selected a half-second delay between steps.
See the short video for the results. If you're really on your game, count the number of steps per cycle to figure out the motor's single-stepping angular resolution.
(Oh yeah. PS. Drives with no load at 3.6v easily. See battery in video.)
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|












































