(note if you just want some sample code go to my post on 21st September)
After much searching the web and bashing my head against the wall I have my stepper actually going round. Which doesn't make me an expert.
On the way it has sat doing nothing , buzzing but doing nothing and generally being annoying. So, in case I forget, and with the possibility that it is of help to someone else, I post my observations. And I will put them in a more useful order than the order in which I found them.
I am using a stepper driver from Arc Euro and a hybrid motor with an Uno.
The first puzzle was the eight wires coming out of the motor together with the four terminals on the driver. The instructions with the hybrid motor required joining pairs of wires that would result in one of three configurations: BiPolar SERIES, BiPolar PARRALLEL, and UniPolarFour Phase.
So which should I use? The driver is described as a BiPolar Stepper - so that left two. In fact, I found out, that for my purposes there isn't much differences between the three the differences are the profile of acceleration and torque. So I merrily went for BiPolar SERIES. Apart from getting the pairs of wires right the driver didn't mind which way round I put them.
Power to the driver was rated at anything between 18V and 50V. That was easy.
Them came the impressive array of DIP switches.
The easy one is : number of pulses per revolution. I had a problem partly caused by this being at the highest value. Start low is my advice.
Current is interesting. The motor is rated at 2A per Phase. With DIP switch options for 1.93 and 2.4 which should I choose? I then found very clear instructions that the current should be the minimum value that will work and must not exceed the motor's requirement. So I have mine at 1.9 and it is working. (originally I had it set to maximum and I got very odd readings off the voltmeter on my power supply and the motor did not work. But there may have been other contributory reasons!)
There is an automatic half-current-mode switch which I left at automatic.
And an internal jumper for single or dual clock mode - I have not got a clue what this is for.
This leaves three pairs of connections: Dir-Direction, Pul - Pulse; and Enb -Enable.
This motor (and all that I have seen) has 200 steps. So as a circle is 360 degrees, A step is 360/200 degrees or 1 full step is 1.8 degrees. Finer steps can be taken dependent on the controller - mine goes to 25,600 micro-steps.
Enb is interesting. It is the last bit I used but is quite simple. Put 5V on Enb and the motor is disconnected (ie stops ata full step).
Dir defines which direction the motor rotates - I have left this alone for the moment.
Pulse is the next bit.so I used some code I found elsewhere:
do {
digitalWrite(pin9PULSE, HIGH);
delayMicroseconds(mSecPulseInterval);
digitalWrite(pin9PULSE, LOW);
delayMicroseconds(mSecPulseInterval)
But nothing worked! So I will document what I should have done first.
Because this was experimental I needed to try various values and see what worked.
So I set up a loop of 0 to 500 in increments of 10 writing each value to the Serial port so I could see them on my PC.
int i = 0;
Serial.begin(9600);
...
void loop {
i=i+10;
if (i>500) {i=0;}
Serial.print(i);
Serial.print("\n");
delay(500);
}
On the PC using the Arduino IDE (the programme in which you write your code) you need to have set the baud rate and the COM port. To check which COM port the Arduino is connected to you need to use Windows Device Manager.
Now one thing I found doing this is that The Arduino would regularly say the port is already in use or not available - when there should not have been a problem. I would love to know a better solution but unplugging the USB and sometimes resetting the Arduino (pushing the little button on the Arduino) usually made it all work ok.
Note: I also came across a new programme failing to the Done Uploading - this was because I had accidentally changed the type of board.
Uploading this programme and clicking on the serial monitor button on the Arduino IDE should give a satisfyling list of numbers which we will use as the pulse interval..
Now a slight digression: originally I thought I would be clever and calculate the interval needed and my loop would be number of rotations per second. So when I got to printing on the serial port I had the number of rotations and the number of milliseconds interval. I was surprised to see this number going negative. I could explain why but just to say that if I wasn't printing the numbers I would not have realised.
Once I had got the list of numbers coming up I included some code to run the motor at the desired interval for three seconds.
void loop {
mSecPulseInterval=mSecPulseInterval+10;
if (mSecPulseInterval>500) {mSecPulseInterval=0;}
Serial.print(mSecPulseInterval);
Serial.print("\n");
delay(500);do {
digitalWrite(pin9PULSE, HIGH);
delayMicroseconds(mSecPulseInterval);
digitalWrite(pin9PULSE, LOW);
delayMicroseconds(mSecPulseInterval)
} while (millis() < time +3000);
delay(500);
Running this I got some nasty noises when mSecPulseInterval was below 50 or above 280 (I think) otherwise it seemed to be working. But over another cup of tea.
I realised that the documentation with the driver said that the Pul was triggered from the falling edge and that LOW must be at least 500 nSec (ie .5 microseconds. So I changed the code again to:
void loop {
mSecPulseInterval=mSecPulseInterval+10;
if (mSecPulseInterval>300) {mSecPulseInterval=50;}
Serial.print(mSecPulseInterval);
Serial.print("\n");
delay(500);do {
digitalWrite(pin9PULSE, HIGH);
delayMicroseconds( 1 );
digitalWrite(pin9PULSE, LOW);
delayMicroseconds(mSecPulseInterval)
} while (millis() < time +3000);
delay(500);
It is now working smoothly and to a point where I can make sense of it.
Next steps: change direction (pulse is on rising edge).
change microsteps switches.
Correct maths for calculating rotation.
Change code to allow a timing loop rather than using delayMicroseconds.