Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function shaft not working to change motor direction #23

Open
YannickRiouRobotics opened this issue Nov 10, 2018 · 5 comments
Open

Function shaft not working to change motor direction #23

YannickRiouRobotics opened this issue Nov 10, 2018 · 5 comments

Comments

@YannickRiouRobotics
Copy link

YannickRiouRobotics commented Nov 10, 2018

I develop on Wemos Lolin32 lite board and manage to drive the TMC2208 driver. I can communicate with the driver but I can't manage to make the shaft function work. It should make the motor change direction but it doesn't on my setup.

Here is the code that I use to make the direction change :

bool motDir = true;
// Main loop
void loop()
{
    for (int i = 0; i < 40; i++)
    {
      digitalWrite(STEP_PIN, HIGH);
      delayMicroseconds(300); 
      digitalWrite(STEP_PIN, LOW);
      delayMicroseconds(300); 
    }
    driver.shaft(motDir);
    motDir=!motDir;
  
  }
@wehibeg
Copy link

wehibeg commented Nov 26, 2018

I do have the same problem setting up on Atmega328p MCU

Hopefully someone will put together the solution

Thanks for posting

@wehibeg
Copy link

wehibeg commented Dec 1, 2018

Spent sometime trying to move a different direction and no luck. it seems not much support or resource available on TMC2208.

Too bad!

@teemuatlut
Copy link
Owner

Tried it and it works.

// Author Teemu Mäntykallio, 2017-04-07

// Define pins
#define EN_PIN    38  // LOW: Driver enabled. HIGH: Driver disabled
#define STEP_PIN  54  // Step on rising edge
#define RX_PIN    63  // SoftwareSerial pins
#define TX_PIN    40  //

#include <TMC2208Stepper.h>

// Create driver that uses SoftwareSerial for communication
TMC2208Stepper driver = TMC2208Stepper(RX_PIN, TX_PIN);

bool dir = true;

void setup() {
  Serial.begin(250000);
  while(!Serial);
  driver.beginSerial(115200);
  // Push at the start of setting up the driver resets the register to default
  driver.push();
  // Prepare pins
  pinMode(EN_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);

  driver.pdn_disable(true);     // Use PDN/UART pin for communication
  driver.I_scale_analog(false); // Use internal voltage reference
  driver.rms_current(500);      // Set driver current = 500mA, 0.5 multiplier for hold current and RSENSE = 0.11.
  driver.toff(2);               // Enable driver in software

  uint32_t drv_status;
  driver.DRV_STATUS(&drv_status);
  Serial.print("drv_status=");
  Serial.println(drv_status, HEX);

  switch (driver.test_connection()) {
    case 1: Serial.println("Connection error: F");
    case 2: Serial.println("Connection error: 0");
    default: Serial.println("Connection OK");
  }

  digitalWrite(EN_PIN, LOW);    // Enable driver in hardware
}

void loop() {
  digitalWrite(STEP_PIN, HIGH);
  delay(1);
  digitalWrite(STEP_PIN, LOW);
  delay(1);
  uint32_t ms = millis();
  static uint32_t last_time = 0;
  if ((ms - last_time) > 2000) {
    if (dir) {
      Serial.println("Dir -> 0");
      driver.shaft(0);
    } else {
      Serial.println("Dir -> 1");
      driver.shaft(1);
    }
    dir = !dir;
    last_time = ms;
  }
}

@wehibeg
Copy link

wehibeg commented Dec 1, 2018 via email

@aadityadengle
Copy link

I am also facing the same issue with MKS Monster 8 V2.0.3 and BigTreeTech TMC2208. I have placed the jumpers correctly on Monster, i.e. Second from the left, yet I am not being able to change the direction. And yes, I also have changed the Pins Definitions as per the Monster8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants