Testing two axis stepper control on two A4988’s

So last night I breadboarded the two driver circuits and wrote some simple command line style Arduino Sketch.

Here’s the code,

#define stepPin 2
#define dirPin 3
#define enablePin 4
#define stepPin2 5
#define dirPin2 6
#define enablePin2 7
int incomingByte;

void setup()
{
pinMode(enablePin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(enablePin, HIGH);

pinMode(enablePin2, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
digitalWrite(enablePin2, HIGH);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// up
if (incomingByte == ‘U’) {
digitalWrite(enablePin2, LOW);
delayMicroseconds(10);
digitalWrite(dirPin2, HIGH);
for(int x=0;x<3200;x++){
digitalWrite(stepPin2, LOW);
delayMicroseconds(2);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(80);
}
digitalWrite(enablePin2, HIGH);
Serial.println(“Moved up”);
}
if (incomingByte == ‘D’) {
digitalWrite(enablePin2, LOW);
delayMicroseconds(10);
digitalWrite(dirPin2, LOW);
for(int x=0;x<3200;x++){
digitalWrite(stepPin2, LOW);
delayMicroseconds(2);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(80);
}
digitalWrite(enablePin2, HIGH);
Serial.println(“Moved down”);
}
if (incomingByte == ‘L’) {
digitalWrite(enablePin, LOW);
delayMicroseconds(10);
digitalWrite(dirPin, LOW);
for(int x=0;x<3200;x++){
digitalWrite(stepPin, LOW);
delayMicroseconds(2);
digitalWrite(stepPin, HIGH);
delayMicroseconds(80);
}
digitalWrite(enablePin, HIGH);
Serial.println(“Moved left”);
}
if (incomingByte == ‘R’) {
digitalWrite(enablePin, LOW);
delayMicroseconds(10);
digitalWrite(dirPin, HIGH);
for(int x=0;x<3200;x++){
digitalWrite(stepPin, LOW);
delayMicroseconds(2);
digitalWrite(stepPin, HIGH);
delayMicroseconds(80);
}
digitalWrite(enablePin, HIGH);
Serial.println(“Moved right”);
}
}
}

It receive’s a letter, U, D, L or R and moves the respective stepper motor one turn in that direction. Trivial but it’s a step forward (hehe).

While doing this I’ve had to learn a lot about how the Arduino handles power and how the power pins actually work. Feeding 5v into the 5v pin turns out not to be a good idea. A better thing to do (arguable the proper thing) is feed 12v to the Vin pin and use the on-board regulator. This also (I believe from the schematic) disables the 5v from the usb from the Arduino (meaning I don’t feed 20a into my USB port :D). One annoying thing I’ve noticed is that the Vin pin will output a voltage while running on USB. there is no protection diode on the Vin bus – there is a diode between the 2.1mm input jack and the Vin but tho.

Onwards and upwards I’ve also made a board up to hold the drivers and have output’s and things all nice and tidy, with pins for Vin, gnd, Vout and 5vin and GND to the Arduino, and then 2 6 way headers for stepper control and 2 4 way headers for the stepper motors. Here’s what it looks like now:

New driver board

New driver board (the breadboard is just a 5v rail while I change the code to use different stepping methods)

Next steps will be to continue working on the code , Might move to an Arduino Mega so i can use a touch screen too.

Running stepper motors on 12v

So today I’ve continued hacking an ATX PSU into a power supply for my laser cutter, and I thought I’ld give the stepper motor a try on the 12v bus.

I used the same code as in http://crazy-logic.co.uk/archives/314 but this time I managed to get it rotating with 2ms between steps, as opposed to 4ms on 5v supply. I have 200 steps per revolution so

1/200*0.004 = 1.25rps = 75rpm for 5v,
1/200*0.002 = 2.5rps = 150rpm for 12v.

This is an obvious improvement. This will be further improved I imagine after trying a different driving arrangement for the stepper motors with micro-stepping. I did try 1ms, however the stepper motor didn’t really appreciate the speed.

12v stepper motor arrangement

12v stepper motor arrangement

New to Stepper Motors

So as part of a few projects I’m attempting soon I thought I best actually get a stepper motor and all the jiggery pokery to control it working.

Parts I have to play with:

  • Arduino Uno SMD,
  • “Dual H Bridge DC Stepper Motor Controller Board Shield L298N”
  • Nema 17 stepper motor.

Great, so lets get started.

What’s a Stepper Motor?

So a stepper motor is a special type of motor. Unlike other motors such as DC and AC motors, it has a discontinuous cycle, or it moves in steps. This is due to the internal structure of the motor. It has advantages and disadvantages as with everything in life. The main advantages of stepper motors are that they are easy to control precisely without having a feedback loop, and they have a high holding torque. This makes them ideal for precision control. Unlike servo’s stepper motors will not correct their position if moved, without additional components.

There are two types of stepper motor, Unipolar and Bipolar. I’m using a Bipolar stepper motor. More information on the differing types can be found in the references at the bottom of this page.

How do we control a Stepper Motor.

We control stepper motors by setting the polarity of different coils inside the motor to different states. Tom Igoe Has a good in depth page here about how we can do this and differing methods. IMO the best method is 4 wire control and a dual H bridge. It’s simple and has the advantage that you can turn the stepper motor completely off (which you can’t do with the 2 wire method).

So here’s how I’m wiring it up (for experiment purposes).

Pins 8,9,10,11 are wire 1 thru 4. obviously Arduino needs 5v and gnd too…
The Dual H bridge takes a pair (wire 1+2) for one H bridge and a pair (wire 3+4) for the other H bridge.
My stepper motor has red and blue wires for one coil, and green and black for another coil. I’ve wired these into the outputs of each H bridge. Note that each H bridge and coil is operated completely independently of the other in terms of electronics. The H bridge will also need 5v, gnd and a voltage for the stepper motor (I’m using 5v throughout for my experiment)

H bridge wired to a bipolar stepper motor

H bridge wired to a bipolar stepper motor

 

http://arduino.cc/en/Reference/StepperBipolarCircuit – has a good diagram of how to wire a bipolar stepper motor up to a H bridge.
http://www.youtube.com/watch?v=5nDaHJqruq0 – The first ten mins or so explains a bit more on how a H bridge is wired.

One question I came up with is which wires go with which coil? – well just use a multimeter to find this out (or maybe a datasheet?). And other is what happens if I get the order of the stepper muddled up, polarity of each coil or the coils the wrong way? The simple answer, without going into detail, is the direction of movement will change. (Easy to fix in software/firmware or swap a coils polarity at a latter point.)

Anyway here’s a simple bit of code showing how you can drive a stepper motor without any additional libraries (assuming wired as above). Change time to be the milliseconds between steps (I started at 500 and worked down to 4 (the lowest I could get to work with 5v)).

void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
}

int time = 4;

void loop() {
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(13, HIGH);
delay(time);

digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(13, LOW);
delay(time);

digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(time);

digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(time);
}

Failing this you can use the example in File>Examples>Stepper>forward reverse. (OWTTE.)

I wont go into depth on using the Stepper commands that Arduino have in the library.

References

Intelligent fixtures as follow spots part 2

I tried my Lego prototype today with a moving head. The results weren’t as good as I was hoping. After a bit of tweaking and jiggery pokery, managed to get the moving head to move in sync with me moving the tracking system. By ‘in sync’ I mean the same directions and speeds, but not scale yet (although it was close), and managed to use both of the handle encoders to change the dimmer of the fixture (individually and not both at the same time – that would be silly!).

Rite now there is one problem – it’s Lego. The problem is accuracy of movement to encoders and there is an error here. As you move the Lego, you have some play in the parts before the pots sense the movement, and this means it is not accurate. So until a more accurate device in the real world (out of laser cut wood, with 20bit or more AD’s) can be made, this project is on the back burner. (Plus I need to focus on my studies.)

 

For those interested in where I got to, have a look at the pictures in this post, and the code below – it is similar to the code for the simple DMX desk here.

 #include <DmxSimple.h>

// this is the code for a track pod idea and it takes 4 analogue ins to
// a number of analgue outs.

// this code channels is for a mac 250 mode 2
// 1 strobe
// 2 dim
// 3 colour
// 4 gobo
// 5 gobo rotate
// 6 focus
// 7 prism
// 8 pan
// 9 pan fine
// 10 tilt
// 11 tilt fine

// two in’s are for pan and tilt – so the 10bit will need to be translated
// to 16 bit and split up and sent on channels 8+9/10+11,
// one will be used for dim and one will be used for focus. both will need
// 10->8bit reduction.

void setup() {
DmxSimple.usePin(3);
DmxSimple.maxChannel(512);
}

void loop() {
// read the value from the sensors:
int value1 = analogRead(A1);
int value2 = analogRead(A2);
int value3 = analogRead(A3);
int value4 = analogRead(A4);

//need to change from 10bit to 8bit
value3 = value3 / 4;
value4 = value4 / 4;

//spliting the 8bit output from the 10bits.
int valuep = value1 / 4;
int valuet = value2 / 4;

//spliting the 2bit output from the 10bits.
int valuepf = (value1 – (valuep * 4)) * 64;
int valuetf = (value2 – (valuet * 4)) * 64;

//output
DmxSimple.write(2, value3);
DmxSimple.write(6, value4);

DmxSimple.write(8, valuep);
DmxSimple.write(9, valuepf);
DmxSimple.write(10, valuet);
DmxSimple.write(11, valuetf);
}

 

Intelligent fixtures as follow spots

The other night while working on an event I though about this and well – “how hard can it be?”

So i’m currently designing and looking at building a tracking system (similar to the Martin TrackPod) that will allow the user to change a moving head or scanner fixture into a follow spot over DMX. I plan to be using Arduino for this project and If I can get the maths to work this will become a very advanced and feature rich project.

Stage 1 will be to create a input system to track the users input and produce DMX from it. (Did I mention I like Lego?)
Stage 2 will be to increase the interface features and add extra use input such as basic mapping and dim/focus input parameters.
Stage 3 will be to introduce wall mapping and multi-fixture support.

I’ll post again about this once the first stage is complete. 🙂

Update: Lego prototype with 2 pots attached.

Lego TrackPod

Lego TrackPod

Update: Lego prototype with 4 pots and cables attached. (A mess but it is only a prototype.)

Lego Trackpod with cables.

Lego Trackpod with cables.

A simple Arduino DMX controller

So recently i was testing some old Clay Paky Pin Scans with a friend and i reached for a simple 6 channel DMX controller we had in the workshop – only to find that it was broken :(. So i thought to myself how hard can it be to make one? After all it’s simply some faders (potentiometers) some A/D and a chip to read the values and convert them to DMX code and transmit them. SIMPLE.

Well actually yes it is. Arduino offeres an open source platform for doing this and best of all – the hard work has already be done. http://www.arduino.cc/playground/Learning/DMX shows work that others have done and DMXSimple is an install-able library that makes the sending of DMX well, simple! Continue reading