Hey guys!
I am building a rather odd wall clock. It uses 4 stepper motors to control two scara arms as the minute and hour hands.
Hardware used:
Arduino Uno Rev3
CNC shield V3 (CNC Shield V3)
4 random DRV8825 - no idea where they come from..
4 Fysetc TMC2209 (Fysetc 2209 - Bought through their ALI store)
4 Small stepper motors (OMC-StepperOnline: 11HS12-0674S)
The cnc shield and arduino both runs on 12V
Hall sensors are used to detect the position of the arms - I am not counting steps.
The issue:
The drv8825 works perfectyl! But, they are LOUD...
So I bought 4 TMC2209 from Fysetc () hoping for a drop-in replacement to reduce noise. I thought they could run with simple STEP/DIR/EN signals in stealthchop mode and 1/16th microstepping by setting the MS1 and MS2 to 5V. Without using any fancy TX/RX/SPI signals.
However, when I run the exact same program that works perfectly with the DRV8825 the motors does not move but just makes a easily audible whining noise. They are energized (do not spin freely). If I switch back to the 8825, then it works as it should.
I measured all the pins on the driver when the program is running and I get what I would expect.
The Code:
The following is a simple version of the code. This is how I controlled the 8825 drivers without issues. I tried using values between 0 to 10, 100 microseconds and even up to 1 second for the "MinDelay". No succes.. (I left out a bunch of variable definitions for the MB, HA and HB motors in the beginning just to make it more readable).
//Including libaries
#include <Wire.h> //Libary used for I2C communication.
#include <RTClib.h> //Libary used to integrate the RTC.
RTC_DS3231 rtc; //Defining the type of RTC used.
//Defining general variabes:
int OldMinute = 0; //Int used to store the old minute value.
int MinDelay = 0; //Int used to control the speed of the motors. When set to 0 mtors run at max speed limited by the code.
//General variables defined.
//Defining varables related to the MA Motor:
//Coresponding Minute: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, Center.
int MA_Target_Array[] = {515, 300, 308, 317, 325, 335, 316, 297, 278, 259, 240, 228, 216, 204, 192, 180, 178, 176, 174, 172, 170, 176, 182, 188, 194, 200, 210, 220, 230, 240, 250, 275, 300, 325, 350, 375, 431, 487, 543, 599, 655, 696, 737, 787, 819, 860, 851, 842, 833, 824, 815, 790, 765, 740, 715, 690, 655, 620, 585, 550, 505};
int MA_Read = 0; //Analog read value from MA encoder.
int MA_Max = 1000; //The encoder value at maximum mechanical travel - Closest to motor = 898 for MA.
int MA_Min = 0; //The encoder value at minimum mechanical travel - Closest to center rod = 106 for MA.
int MA_Range_Upper = 0; //The upper encoder limit for the current move.
int MA_Range_Lower = 0; //The lower encoder limit for the current move.
int MA_Target = 0; //The encoder target for the current move. Based on the values in MA_Target_Array.
bool MA_Dir; //Direction specification. True = Encoder value is larger than target = Motor moves in.
boolean MoveMA = false; //Specifies if the motor should move.
//MA variables defined.
//Defining varables related to the MB Motor:
//MB variables defined.
//Defining varables related to the HA Motor:
//HA variables defined.
//Defining varables related to the HB Motor:
//HB variables defined.
//Defining shield pins:
# define EN 8 //Enable control for all steppers. Steppers are active when pin is low.
# define MA_DIR 6 //MA stepper direction control - X label on CNC Shield.
# define MA_STP 3 //MA stepper control - X label on CNC Shield.
# define MB_DIR 5 //MB stepper direction control - Y label on CNC Shield.
# define MB_STP 2 //MB stepper control - Y label on CNC Shield.
# define HA_DIR 13 //HA stepper direction control - Z label on CNC Shield.
# define HA_STP 12 //HA stepper control - Z label on CNC Shield.
# define HB_DIR 7 //HB stepper direction control - A label on CNC Shield.
# define HB_STP 4 //HB stepper control - A label on CNC Shield.
# define motorInterfaceType 1 // Accel lib - must be 1 when using a stepper driver.
//Shield PINS defined.
//Defining encoder pins:
#define MA A2 //Analog pin used for the MA encoder.
#define MB A1 //Analog pin used for the MB encoder.
#define HA A3 //Analog pin used for the HA encoder.
#define HB A0 //Analog pin used for the HB encoder.
//Encoder pins defined.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MoveArms (int MinDelay)
{
digitalWrite (EN, LOW); // Setting Enable pin low to enable steppers
Serial.println("Motors enabled and movement begun");
while(MoveMA == true || MoveMB == true || MoveHA == true || MoveHB == true){
//Encoders are read
MA_Read = analogRead(MA);
MB_Read = analogRead(MB);
HA_Read = analogRead(HA);
HB_Read = analogRead(HB);
if(MA_Read < MA_Range_Upper && MA_Read > MA_Range_Lower && MoveMA == true){ //If statement checks if the encoder is within range and the motor is supposed to move
digitalWrite(MA_STP, HIGH);
}else{
MoveMA = false; //The motor is turned off, if the encoder is not within range (when the arm have reached target position).
}
if(MB_Read < MB_Range_Upper && MB_Read > MB_Range_Lower && MoveMB == true){
digitalWrite(MB_STP, HIGH);
}else{
MoveMB = false;
}
if(HA_Read < HA_Range_Upper && HA_Read > HA_Range_Lower && MoveHA == true){
digitalWrite(HA_STP, HIGH);
}else{
MoveHA = false;
}
if(HB_Read < HB_Range_Upper && HB_Read > HB_Range_Lower && MoveHB == true){
digitalWrite(HB_STP, HIGH);
}else{
MoveHB = false;
}
delayMicroseconds(MinDelay);
digitalWrite(MA_STP, LOW);
digitalWrite(MB_STP, LOW);
digitalWrite(HA_STP, LOW);
digitalWrite(HB_STP, LOW);
delayMicroseconds(MinDelay);
}
} //End of: MoveArms.
//___________________________________________________________________________________________________________________________________________________________________________________________________________________________
void setup ()//The setup function is run 1 time on power on. It initializes the Seral communication and RTC. It defines pin types and sets stepper speeds.
{
//Serial setup:
Serial.begin(9600); //Starts the serial connection with a baud rate of 9600.
delay(500); //Delay ensures that serial communication is running before continuing.
//End of: Serial setup.
//RTC Setup:
if (! rtc.begin()) { //If command chechs if RTC is communicating properly.
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power");
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Sets the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0)); // Sets the RTC with an explicit date & time of: January 27 2017 at 12:56.
}
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Currently 5s behind on 12:30 01. aug.
// End of: RTC Setup.
//Pin Setup:
//Hall Pins
pinMode(MA, INPUT);
pinMode(MB, INPUT);
pinMode(HA, INPUT);
pinMode(HB, INPUT);
//CNC Shield Pins
pinMode (EN, OUTPUT); // Setting Enable pin as output type
//End of: Pin setup.
} // End of: Viod Setup.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop () //Main Loop begins.
{
DateTime now = rtc.now(); // Sets the current time to that of the RTC.
if(OldMinute != now.minute()){ //This loops activates every time the minute has changed.
MoveMA = true;
MoveMB = true;
if(now.minute() == 0 || now.minute() == 12 || now.minute() == 24 || now.minute() == 36 || now.minute() == 48){
MoveHA = true;
MoveHB = true;
}
MoveArms(10);
OldMinute = now.minute(); //Old minute is updated.
} // End of: Minute action.
delay(1000); // Delay controls loop time.
} // End of: Void Loop.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I have looked everywhere especially on this forum and youtube, and from what I can see it should just work, but it does not..
I hope some of you guys have had luck using the 2209 drivers in the simple STEP/DIR/EN application like mine and know what I am not doing corectly!
THANKS!