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.

16th stepping stepper motor with A4988 driver carrier from Pololu

So in an effort to control the stepper motors more accurately I’ve invested in some Pololu Stepper motor driver carrier boards. This gives 2 advantages over a traditional H bridge arrangement,

  • Micro stepping,
  • Current limiting.

Using the diagram from here but with a few changes, I pulled ms1,2,3 to high to enable a resolution of 16 microsteps, and wired it to an Arduino for control.

#define stepPin 2
#define dirPin 3
#define enablePin 4
void setup()
{
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(enablePin, LOW);
delayMicroseconds(10);
digitalWrite(dirPin, HIGH);
}
void loop()
{
digitalWrite(stepPin, LOW);
delayMicroseconds(2);
digitalWrite(stepPin, HIGH);
delayMicroseconds(80);
}

this simple code allowed me to achieve around 3.8 revolutions per second, or ~230rpm. Which is a lot more than in full stepping mode without jumping.

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

CNC router no more. I’ve decided….

… to make a laser cutter instead.

I’ve always wanted a laser cutter, but I’ve never really been able to afford one.

So i’m putting the CNC router on hold for the time being and building a laser cutter. It’ll have around a 1W laser and have a cutting bed of 600 by 800mm… which is quite big for a starter project.   I want to build it spending less than £300 on parts…. so cheaper than the CNC router too.

How hard can it be? Here’s a quick Google sketch up of my idea’s

my laser cutter

my laser cutter

 

 

Arduino based DMX DeMUX – Analogue – part 2

I realised I’ve left this project hanging a while now and that’s partly to do with he fact that the chips I was hoping to use didn’t arrive quickly then other things got in the way.

I’ve also hit upon two other snaggs,

  • The power supplied from the dimmers is not 10v, so this means adding in two power regulator circuits (one for 5v data and the other a 10v reference),
  • The chips will only do 0-5v, which obviously is no good for the 0-10v that’s required.

Never mind – this is still a project i’m working on – just a little more complex than I first thought.

 

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

Had a tripping weekend…

So this weekend just gone, there was an incident when an artist decided that pouring beer into a 4 way on stage was a good idea. Safe to say it wasn’t and it tripped the RCD for stage power. But it also tripped two more upstream RCD’s, taking out monitor world.

This has got me thinking about the best possible way to avoid this in the future.

The first thing to understand is what happened on this gig, why it failed and why it took out all of the stage and mon’s power.

  • The main distro there was a 63a 30mA RCD over 2 32A outputs,
  • One fed the monitor racks and the other fed a small distro, 
  • The small distro had 30mA 16a RCBO’s on 4 16A outputs, powering the monitor desk, the stage power, and most importantly the fridge and kettle,
  • Stage power had a further distro with one 16a RCD/BO with 4 16A outputs running to various on stage 4ways.

On this gig, the main PA was fed from the other 2 phases and FOH power was ran from a 16a on the distro on a differing RCD. The main RCD on the main distro was of a higher trip rating than 30mA. This was lucky as loosing FOH power or PA power would have been significantly more of an issue.

The key thing here is that the water/beer in the 4way caused a cascade of RCD/BO trips, firstly the stage power distro, then the small distro then the main distro. When powering back up to identify where the fault was (not knowing where at that time) the RCBO’s caused an issue of upstream tripping.

The key thing I’ve learnt from this is that RCBO’s should NOT be used for stage power as isolators to fault find, and as such they should not be used for stage power. It’s a better idea to have RCD’s with separate MCB isolators. This allows you to isolate the circuit before resetting the RCD, then when resetting the MCB, if the earth leak still exists, it’ll trip that RCD and not an upstream one (assume your discrimination between RCD’s is correctly set up).

 

re-visiting racks

Today I’ve been tidying up some paperwork and I came across some old cut plans for making racks. The thing that I was working on was – how much can I get from a 8 by 4 sheet of 18mm ply?

My initial rambling drawings show that I can get 3 4u racks from a sheet or a 14u rack from a sheet. But I thought seeing as I have a few spare moments I’ll draw up the cut sheet and then I thought why not actually work out what the maximum size I could get would be? Lowe and behold apparently I can get 3 5u racks from a sheet or 1 18u rack, which is better than I thought possible.

Anyway – here’s a quick model I knocked up in SketchUp, and a pdf cut sheet for making three of the racks (with lids) from one sheet of ply.

5u rack model

5u rack model

5u cut sheet

Arduino Mega2560 with 3.2″ TFT LCD Touch Display

I received today in the post an Arduino Mega with 3.2″ TFT LCD Display made by SainSmart, from Amazon. Click here

I was impressed how easy it was to assemble – however it isn’t exactly a robust set-up. The screen board is attached at one end, so it’d be quite easy to bend the pins between the LCD PCB and the Arduino Shield .

To use the screen you need to use a library which I found on SainSmart’s website. However – there is an issue (in my Arduino IDE anyway) with this library. Namely that it refers to another library WProgram.h which has been renamed to Arduino.h. You’ll need to rename this once extracted or download my copy with the mod to your arduino/libraries/touchscreen directory (you’ll have to make one). Without this mod you’ll get an error when you compile;

In file included from ITDB02_Graph16_Demo_Landscape.cpp:18: C:\Program Files\arduino-1.0\libraries\touchscreen/ITDB02_Graph16.h:69:22: error: WProgram.h: No such file or directory

But once that’s done, it should work fine and dandy. There are two example sketches in the library – one uses the touch screen to make a sort of etch a sketch and the other displays some of the more advanced graphics that could be displayed.

Below’s a video of that second example running on the device. (sorry it’s a tad blurry)