Hello everyone!
I hope I am posting this in the right place. I'm happy to move it if not! I'm looking for some advice on using an Arduino for controlling an equatorial platform for a telescope.
A few months ago I built a 'barn door' equatorial tracker and used the following code found online.
#define DELAY 1993
// Setting the variables
const int motor_dir = 8; // Output pin for DIR control of the driver
const int motor_step = 9; // Output pin for STEP control of the driver
const int motor_enable = 10; // Output pin for ENABLE control of the driver
const int led = 13; // Output pin for the LED
int ledState = LOW; // Will store the current ON/OFF state of the LED
unsigned long previousMillis = 0; // used for timing
const long interval = 500; // interval for the blinking LED
int tracking=1; // Tracking ON/OFF state
const int btn_up = 2; // Input pin for the UP/FORWARD push button
const int btn_down = 3; // Input pin for the DOWN/REWIND push button
int btnreadup=0; // Will store the UP button status
int btnreaddown=0; // Will store the DOWN button status
int fastratio=1; // variable containing the ratio that will be applied to the delay between motor pulses
// the setup routine runs once when you press reset:
void setup() {
pinMode(motor_step, OUTPUT); // The 3 motor control line are set as OUTPUT
pinMode(motor_dir, OUTPUT);
pinMode(motor_enable, OUTPUT);
pinMode(led, OUTPUT); // The LED pin is also an OUTPUT...
pinMode(btn_up, INPUT_PULLUP); // Push button input are set as INPUT with PULLUP enable (+5V is applied with an internal resistor)
pinMode(btn_down, INPUT_PULLUP);// And the switches will have an inverted logic = ACTIVE_LOW (the button will apply the ground to the inputs)
}
// the loop routine runs over and over again forever:
void loop() {
if(tracking==0) { // If tracking is disabled...
digitalWrite(motor_enable,HIGH); // disable the motor (inverted logic on the driver)
while(digitalRead(btn_up)+digitalRead(btn_down)==2) {delay(50); // wait until a button is pressed
toggle_led();} // and blink fast
tracking=1;
}
else // IF tracking is not disabled
{
digitalWrite(motor_enable,LOW); // enable the motor (inverted logic on the driver)
unsigned long currentMillis = millis(); // read current timer
if(currentMillis - previousMillis >= interval) { // if time has passed more than the specified interval
// save the last time you blinked the LED
previousMillis = currentMillis; // store the current timer
toggle_led(); // call the toggle_led() function, that will invert the LED output
}
btnreadup=digitalRead(btn_up); // read the button UP status, will return 0 if pressed and 1 if not (inverted logic)
btnreaddown=digitalRead(btn_down); // read the button DOWN status, will return 0 if presses, and 1 if not (inverted logic)
if(btnreadup+btnreaddown==0) {tracking=0; delay(2000);} // if both the buttons are pressed (0+0=0), stop the tracking and wait for 2 sec
if(btnreadup+btnreaddown==2) {fastratio=1;} // if no button is pressed (1+1=2), set the ratio to 1
else {fastratio=800;} // if any button was pressed, set the ratio to 800
if(btnreaddown==1) {digitalWrite(motor_dir,LOW);} // if the button DOWN was pressed, invert the motor DIRECTION
else {digitalWrite(motor_dir,HIGH);} // else setp the motor to the FORWARD direction
digitalWrite(motor_step, LOW); // pulse the motor ouput LOW
digitalWrite(motor_step, HIGH); // set the motor ouput HIGH again
delayMicroseconds(DELAY/fastratio); // pause the defined time, with ratio applied
} //else
}
void toggle_led() // function that inverts the LED status
{
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) // logic that reads and invert the LED status variable
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led, ledState); // actual toggle of the LED ouput
}
This project used a NEMA 17, Arduino UNO, DRV8825, and a generic expansion board. I made minor edits to the sketch to correct some math and tried to understand how it all works. If I understand correctly, it uses 'DelayMicroseconds' to control timing. Two buttons can start, stop, or speed it up for testing. All went together well and worked fine.
Well, now I want to build a big equatorial platform. In theory I could use the same code, but I'd like to use some TMC2130 drivers I have leftover from an OnStep project and up the microsteps to 256. I've done the math and the engineering for the platform, I know what figure to use for 'DelayMicroseconds'. I have two problems though:
I have no idea how to amend the Sketch to make use of the TMC2130 driver instead of the DRV8825. I know I need to read about integrating the 2130 libraries though.
The leftover TMC2130s I have are designated 'SPI', and I'm not sure how to connect them to the Arduino. I've seen schematics for connecting them like the barn door tracker's DRV8825 (step/dir/en), but not for SPI. I don't think I need an expansion board since I only need one driver - right? Also I'm not sure how to get them into 256 microstep mode without the expansion board's DIP switches.
Could anyone point me in the right direction? Thank you!