Can I activate a stepper motor with orangutan?

hay all
can I activate a stepper motor with orangutan or baby O? I want to make a x,y plotter.
Arbel

You can run one stepper motor, in full or half-steps, from the dual H-bridge on either an Oranguatn or Baby Orangutan. It will need to be either a bipolar stepper motor (which will have 4 wires) or a unipolar stepper motor with separate common lines (which will have 6 or 8 wires). It will also need to draws less than 1 amp per phase at whatever your battery input voltage will be (5V to 10V). If you’re scavenging these motors you can figure out how much current they’ll draw by measuring the winding resistance. I’ve had good results at 7.2V running stepper motors I got out of printers, like these ones:

You could also run more powerful motors, or just more motors from one Orangutan by adding your own dual H-bridge chips. For more power/higher voltages, I’ve had good luck with the L298 dual bridge chips. They have a weird pinout, but if you’re careful not to leave the pins touching you can force them into a 0.1" prototying board.

Are you familiar with how to control stepper motors?

-Adam

No, I have no experience with stepper motor and less experience with that H bridge. I will by very happy if you could explain to me about both of them. I know little about stepper motors, and noting about the H bridge (I mean, I know what the H bridge dose, but I don’t know how to make it do what it suppose to do.)

Thanks
Arbel
p.s

maybe it will be better to use a gearmotor for that?

It might be time for a little background reading then.

The short Wikipedia Article on stepper motors does a good job of explaining the basic physical concept of a stepper, but the second half of the article about control and driver circuits won’t really be that useful to you. They also have a good simple article on the concept of an H-Bridge. Basically an H-bridge is a circuit that lets you apply a voltage across something (a DC motor, one winding of a stepper motor) in either direction. This is very convenient if, say, you want to be able to switch the field direction of an electromagnet back and forth. Stepper motor operation is based on alternating the field directions of two electromagnet coils, so you need two h-bridges to control one stepper motor (actually, unipolar stepper motors can be controlled with just four transistors, but dual H-bridge drivers are more versatile, as they can control bipolar AND most unipolar motors, you’ll see why in the wiki article).

After that, Haydon Switch & Instrument has a neat primer on the operational theory of stepper motors, i.e. the different ways to make them go.

DC gearmotors are used in some positioning applications when extremely high torque is needed, and/or space is very limited. To do positioning control with a DC gearmotor you’ll also need to read a quadrature encoder for feedback. If you don’t need the super-high torque and you don’t have very tight space constraints, steppers are much cheaper and easier (well, less hard) to use. You can look at the fact that printers, scanners, and even laser cutters, generally use stepper motors these days.

-Adam

thanks for the info, Is there an example that shows how to use the H bridge with the orangutan? or maybe how to use a Pololu Micro Dual Serial Motor Controller to control the stepper motors? I need the code part. I got the pin settings of the micro dual serial motor controller, but I don’t know how to send the bytes…
Arbel

There’s a discussion (including some basic example code) on controlling a stepper motor with Orangutans on this thread.

Even though the uDSMC uses the same H-bridge chip as the Orangutan and Baby Orangutan, it isn’t really set up to control a stepper motor. Why not will make more sense after you’ve read those articles

-Adam

P.S. I’ve definitely toyed with the idea of making a clip-on programmer for the PIC on the uDSMC, a little code could make it into a simple serial stepper motor driver. The Baby O’s are so cheap and easy to use, and the ATMega48 Baby O only costs $2 more than the uDSMC, and is far more than capable of driving a stepper motor.

OK. I got the code there, but how do I turn the motor to the other way?
using the baby O as a driver to a stepper motor soundes like a good idea, I think I’ll give it a shot. can I drive a 12V stepper motor with the baby O as well?
Arbel

To reverse the direction of a stepper motor you reverse the order of your phase cycling. How to do that in practice depends on what kind of stepping you’re doing, and how you’re code works. It’s may or may not be as simple as just reversing the order of commands in your code. Here’s an interrupt driven stepper motor test code I wrote for the Orangutans, it’s a little more complicated than the code discussed in the other thread:

/*Stepper Motor Demo for Pololu Orangutan/Baby Orangutan ATMega168
V 0.1
Adam Borrell
12/14/07
To Do: Pick better counter prescaler for finer speed control?
*/

//Definitions
#define F_CPU 20000000//CPU clock (for Baby Orangutan)
//#define F_CPU 8000000//CPU clock (for Orangutan)

//Externals
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

//Global Variables
signed char i,j;//step index,direction
signed int k=0;//step counter

//cX variables control starting/direction changing speed (constant acceleration)
//lower numbers are higher speds
//frequency=9765.625/(cX+1) steps/second
unsigned char cstart=40;//Starting speed
unsigned char ctarget=12;//Final speed

//Interrupt Handlers
ISR(TIMER1_COMPA_vect){//Two Phase On Half Step frequency=9765.625/(OCR1A+1) steps/second

	if(j==1){//Forward
		switch(i){
			case 0:
				PORTB|=(1<<PB1);//phase A fwd
				break;
			case 1:
				PORTD&=~(1<<PD6);//Phase B off
				break;
			case 2:
				PORTB|=(1<<PB2);//phase B fwd
				break;
			case 3:
				PORTB&=~(1<<PB1);//phase A off
				break;
			case 4:
				PORTD|=(1<<PD5);//phase A reverse
				break;
			case 5:
				PORTB&=~(1<<PB2);//phase B off
				break;
			case 6:
				PORTD|=(1<<PD6);//phase B reverse
				break;
			case 7:
				PORTD&=~(1<<PD5);//phase A off
				break;
		}
	}else{//Reverse
		switch(i){
			case 7:
				PORTB|=(1<<PB1);//phase A fwd
				break;
			case 6:
				PORTB&=~(1<<PB2);//phase B off
				break;
			case 5:
				PORTD|=(1<<PD6);//phase B reverse
				break;
			case 4:
				PORTB&=~(1<<PB1);//phase A off
				break;
			case 3:
				PORTD|=(1<<PD5);//phase A reverse
				break;
			case 2:
				PORTD&=~(1<<PD6);//Phase B off
				break;
			case 1:
				PORTB|=(1<<PB2);//phase B fwd
				break;
			case 0:
				PORTD&=~(1<<PD5);//phase A off
				break;
		}
	}

	k+=j;

	if(k>2400){
		j=-1;
		OCR1A=cstart;
	}else if(k<-2400){
		j=1;
		OCR1A=cstart;
	}

	i+=j;

	if(i==8){
		i=0;
	}else if(i==-1){
		i=7;
	}

	if(OCR1A>ctarget){
		OCR1A--;
	}
}

/*
ISR(TIMER1_COMPA_vect){//Two-Phase-On full step frequency=19531.25/(OCR1A+1) steps/second
	switch(i){
		case 0:
			PORTB|=(1<<PB1);
			PORTD&=~(1<<PD6);
			break;
		case 1:
			PORTB|=(1<<PB2);
			PORTB&=~(1<<PB1);
			break;
		case 2:
			PORTD|=(1<<PD5);
			PORTB&=~(1<<PB2);
			break;
		case 3:
			PORTD|=(1<<PD6);
			PORTD&=~(1<<PD5);
			i=0;
			return;
	}
	i++;
}*/

int main(){
	i=0;
	j=1;

	DDRB|=(1<<PB1)|(1<<PB2);
	DDRD|=(1<<PD5)|(1<<PD6);

	OCR1A=cstart;//set Timer1 CompareA value
	TIMSK1|=(1<<OCIE1A);//enable Timer1 CompareA interrupt
	TCCR1B|=(1<<WGM12);//set Timer1 to CTC mode CompareA top
	TCCR1B|=(1<<CS12)|(1<<CS10);//set Timer1 to operate on system clock/1024
	sei();

	while(1){
	}

	return 0;
}

The actual stepper motor control happens in the ISR(TIMER1_COMPA_vect) function. It basically runs a stepper motor in one direction for 2400 steps, then back 2400 steps, which happens to be the length of a linear stepper actuator I’ve been playing with. There are variables for controlling speed and direction, and also a little rudimentary startup acceleration (see the comments). This demo is using two-phase-on half stepping, but there is also a commented out version of ISR(TIMER1_COMPA_vect) that uses a much simpler, one direction two-phase-on full step mode.

Neither of these versions of the function can simply have the commands reversed to drive the motor in the opposite direction, since I’m only using one of the H-bridge control pins at a time to shut off power to a phase. I suppose I should have just set both control pins of a phase low every time I was trying to turn that phase off, that way I think I could have run either of these forward or backward by just incrementing or decrementing the step index variable. I forget if there was a good reason why I didn’t do that or not. Oh well, tracking revisions to my code with version numbers makes me feel better about weird things like this, after all, this is only version 0.1!

As to using 12V motors, that’s a little beyond the spec of the dual H-bridge chip used on the Orangutan and the Baby Orangutan. It might work if the motors were very small and drew little current, but my guess is that you would throw the chip into thermal shutdown mode, or maybe even damage it.

-Adam

THANKS!!!
one more question, can I use any port or do I have to use the H bridge ports because of the timer?
Arbel

Hello.

The current Baby Orangutan revisions cannot handle 12 V, but there are new ones in the works that will be able to. They should be available next week.

- Jan

If you’re going to use the built-in H-bridge on an Orangutan, you have to use the pins connected to the control pins on the H-bridge to operate it. If you’re going to hook up your own H-bridge you can use any pins you like. If you notice in the code I posted, I am using a timer, but the control routine isn’t PWMing a particular pin using the timer’s hardware. Instead, I’m just using the timer to generate precise interrupts, and then manually setting pins in the interrupt handling function. You could use this approach to control any pins you want.

-Adam

here is the thing, my H bridge on the baby O is burned. So I have to use an external H bridge. The problem is that I don’t know HOW to connect the external H bridge to the pins in the baby O…
Arbel
(thanks for ALL your help)

What make/model of H-bridge are you going to use?

Also, you could send your Baby-O back to Pololu for a quick replacement job. How did you burn it out?

-Adam

I don’t know how I burned my baby O I think that it was connected when I soldered some thing, I’m not sure.
can I really send it back? how do I do that???

I want to use this H bridge. I think it will be very good practice for me to use an external component. So far I used only on board stuff.
Arbel

If you want to return your Baby Orangutan for repair, just get in touch with the Pololu guys (by any of the ways listed on the contact page) and they’ll give you an RMA number to use.

The L29As are definitely good choices for high power motors, and will work with lower power ones too. As to how to connect one up to control a stepper motor, here’s a wiring diagram I drew up a while ago for connecting one to a stepper motor, and a particular connector on an OOPIC microcontroller board. Let me know if it’s unclear.

If you’re having trouble seeing the whole picture (i.e. if you’re using Firefox and you don’t have a HUGE monitor) you can see it here.

The four control lines and two enable lines can be connected to any six pins you like on your Baby Orangutan, but you should probably look at what other hardware features those pins can be used for, so you don’t use up ones you’re going to want to use for something else later. Also, if you want to use fewer pins there are a couple of tricks you can do, like pulling the enable lines high with resistors and only manipulating the control lines.

Also, I don’t show them here in the diagram, but if you’re going to be controlling high-power motors (lets say over 500mA per winding, just guessing though) you probably want to include what are called “fly-back” diodes to protect the motor driver chip. They’re shown in a couple of the schematic diagrams in the data sheet.

-Adam

P.S. Did you look at the new Baby Orangutan B’s Jan mentioned? They’re up on the website now, and they’re blue! Looks like they match the micro dual serial motor controllers.

Also, since the new version came out, the older Baby Orangutan’s are on super-sale until they’re all gone. If you want to control some low-power stepper motors with them you can pick up the ATMega48 versions for just $15!

Adam

the new baby O’s are GROOVIE!!!

I got 2 things,

  1. I don’t understand your diagram. not that it’s bad or some thing like that, I have little know how in electronics so… I didn’t understand the parts I will need to build this thing.

  2. If I will get another baby O to make a stepper motor driver, I think I will use him to control more then 1 motor, using a couple of H bridge. So I don’t have to worry about pin assignment.

another thing, about your diagram, did the middle part, from the H bridge to the motor, is that stuff that is inside the motor pcb? or do I have to build that to?

Thanks
Arbel

No problem, maybe this will be a little more clear:

(again, here’s a link to the full picture)

The green box is a schematic/logic block diagram of the inside workings of the L298 (mostly copied from the one on page 1 of the datasheet). Basically the green box is the chip, and the numbered lines connecting to it are the connections you have to make (1 through 15, corresponding to the pin numbering scheme on page 2 of the datasheet).

The blue box is a bipolar stepper motor (with two simple coils) and the little purple pill shapes are external capacitors (always good to use the recommended capacitors). The remaining black rectangle on the left is just a box drawn around the connections you will make to your Orangutan. If you want, you can actually just connect the two “enable” lines through resistors to the +5V line, and use only the control lines to run the stepper motor (the same way as with the Orangutan’s built-in H-Bridge).

By the way, do be sure to connect the motor ground pins (pins 1 and 15, misleadingly called “sense” pins by the datasheet) to ground, and connect that ground to your microcontroller ground as well (pin 8).

Does that make more sense?

-Adam

YES!!!
Thanks for now, I’ll let you know how it worked out…
Arbel