TMC2130 SPI for an equatorial platform

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!

Your last link TMC2130s seems broken ?

This seems to be helpful for you

Have to admit I don't have any of those drivers here as I find the other drivers more suitable for my applications. but "STANDALONE" seems to be what you are looking for.

Note to constant reference to torque in the video.

Also are you sure you don't need both azimuth and elevation ?

ballscrewbob:
Your last link TMC2130s seems broken ?

This seems to be helpful for you

Have to admit I don't have any of those drivers here as I find the other drivers more suitable for my applications. but "STANDALONE" seems to be what you are looking for.

Note to constant reference to torque in the video.

Also are you sure you don't need both azimuth and elevation ?

Hello Bob and thank you for your reply! I did some digging based on what you've said and yes I believe you're correct about needing to ensure they are in STANDALONE mode. It looks like depending upon the TMC2130s I have, I may need to bridge a small connection with solder to accomplish this. I have fixed the broken link above - thank you for pointing that out!
Regarding azimuth and altitude - I would need both of those for a different mount like the dobsonian I built. This equatorial platform though works like a fork or German equatorial mount that uses right ascension and declination axes to better track the motion of the stars (or in reality, cancel out the motion of the Earth). An equatorial platform is just half the equation though and only compensates for right ascension for about an hour. This allows for placing an altitutde/azimuth telescope (a dobsonian, in this case) on top of one and facilitates taking longer exposure images. A barn door tracker accomplishes the same thing, but is much smaller and usually just has a DSLR mounted on it with a ball head.
Thanks again for your advice - I very much appreciate it!

Am more used to seeing AZ/EL with LEO tracking to maintain a strong signal for a pass.
Your astro usage is a little foreign to me but I am aware of it as the topics do seem to intermingle occasionally.

Yeah the astro usage is a bit more 'out there' - most people aren't using a poncet/equatorial platform with a dobsonian for imaging. I'd love to build a more traditional GEM setup with OnStep and have RA and DEC axes, but the precision required there is a bit out of my price range for the moment. I'm hoping the platform and dob combination produce some 'pretty images' so I can get the wife on board with putting a bit more money into the astro hobby :slight_smile:

Thank you again for your information. I've done some more digging and it appears that for this particular project I will need to ensure the 2130 driver is in 'standalone' mode and then set my microsteps via the CFG pins. I'm not using any of the more 'fancy' features from the 2130, so SPI shouldn't be necessary. I think this means the code will be even more simple, though at the cost of efficiency and having a louder motor. I've still got a lot of reading to do but I'm glad to have been pointed in the right direction.