Before plunging into code, it's worth setting up the Arduino so we can see if it's working. Not necessary to connect it to a driver, motor and power supply at this stage, building them can be left until later. All we need do is test the signals output on pins A0, A1 and A2 are as planned.
The outputs can be tested with a multimeter, or an oscilloscope, but LEDs and a few resistors on a solderless breadboard will do the same job. These provide lines of connector strips into which components can be plugged to make temporary circuits.
All that's needed to test the Arduino program (or 'Sketch' in their jargon), is three small LEDs, with resistors arranged to drop 5V output by the Arduino to roughly1.5V on the LED. Any value between 220 ohms and 1000ohms should do the job. Boards and resistors available from ebay / amazon etc. Don't mess about sourcing three resistors – buy a selection box. Other values may be useful later. Ditto LEDs, get a small selection.
Plugged into the board and connected to the Arduino:
Not very clear in the photo but the Black jumper goes to a socket on the Uno marked GND, and the Yellow jumper goes to A0.
The pink LED connected to A0 (ie ENA+) is lit. This was achieved with these instructions:
Lines starting // are comments. Not used by the Arduino but helpful reminders for the programmer.
I could have used A0 in the raw, but instead "#define ENABLE_PIN A0" creates a meaningful alias. Not necessary In a small obvious program but a useful trick for complicated code, especially if you wrote it 5 years ago and can't remember how it works. It's easier to remember what ENABLE_PIN is than what A0 is connected to.
In setup() the program starts with a pin_mode() command that declares ENABLE_PIN (that is A0) to be an OUTPUT to be used later. This happens in the next statement: digitalWrite() is set HIGH, and 5V appears on the socket marked A0. It causes the LED to light, and it would enable a stepper motor controller when one's connected later.
Next, motor direction is set by adding similar instructions for pin A1:
I used #define to create meaningful aliases for CLOCKWISE and ANTICLOCKWISE rather than remember HIGH means clockwise. And if I get these the wrong way round and the motor runs in reverse, the problem is fixed at the #define – I wouldn't have to check every HIGH scattered throughout the code to see if was setting direction or doing something else.
As expected compiling and installing this causes the red LED to come on as well.
Coming next, the instructions needed to output pulses on A2, aka PULSE_PIN, and eventually to be wired to PUL+ on the stepper driver.
Dave
Edited By SillyOldDuffer on 18/02/2019 17:48:30