I am building a clock with a stepper motor running on a TMC2209 driver with a Sparkfun RV-8803 rtc on a Sparkfun Pro Micro.
I got the motor running finally, but I have hit a big wall with getting the RTC to play nice with it. Any time I uncomment the lines using the RTC such as
//Wire.begin();
//rtc.begin();
//or
//rtc.updateTime();
The motor stops running and makes some fun noises. Is this from some sort of conflict with I2C and my SW UART?
Thanks for looking at this.
//runs stepper motor
#include <TMCStepper.h> // TMCstepper - https://github.com/teemuatlut/TMCStepper
#include <SoftwareSerial.h> // Software serial for the UART to TMC2209 - https://www.arduino.cc/en/Reference/softwareSerial
#include <Streaming.h> // For serial debugging output - https://www.arduino.cc/reference/en/libraries/streaming/
#define EN_PIN 2 // Enable - PURPLE
#define DIR_PIN 3 // Direction - WHITE
#define STEP_PIN 4 // Step - ORANGE
#define SW_SCK 5 // Software Slave Clock (SCK) - BLUE
#define SW_TX 6 // SoftwareSerial receive pin - BROWN
#define SW_RX 7 // SoftwareSerial transmit pin - YELLOW
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f // SilentStepStick series use 0.11 ...and so does my fysetc TMC2209 (?)
SoftwareSerial SoftSerial(SW_RX, SW_TX); // Be sure to connect RX to TX and TX to RX between both devices
TMC2209Stepper TMCdriver(&SoftSerial, R_SENSE, DRIVER_ADDRESS); // Create TMC driver
#include <SparkFun_RV8803.h> //Get the library here:http://librarymanager/All#SparkFun_RV-8803
RV8803 rtc;
int accel;
long maxSpeed;
int speedChangeDelay;
bool dir = true;
int numTeethClock = 240;
int numTeethMotor = 30;
int lastHundred = 0;
int timeCheck = 0;
int mStepsPerRotation = 51200;
//== Setup ===============================================================================
void setup() {
Serial.begin(115200); // initialize hardware serial for debugging
SoftSerial.begin(115200); // initialize software serial for UART motor control
TMCdriver.beginSerial(115200); // Initialize UART
//115200
//9600
pinMode(EN_PIN, OUTPUT); // Set pinmodes
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW); // Enable TMC2209 board
TMCdriver.begin(); // UART: Init SW UART (if selected) with default 115200 baudrate
TMCdriver.toff(5); // Enables driver in software
TMCdriver.rms_current(500); // Set motor RMS current
TMCdriver.microsteps(256); // Set microsteps
TMCdriver.en_spreadCycle(false);
TMCdriver.pwm_autoscale(true); // Needed for stealthChop
TMCdriver.shaft(dir);
// rtc address: 0x64
//Wire.begin(); --------------------------NEEDED FOR RTC
//rtc.begin(); --------------------------NEEDED FOR RTC
//calculate delay between steps
}
//== Loop =================================================================================
void loop() {
//get time update
//rtc.updateTime(); --------------------------NEEDED FOR RTC
// timeCheck = rtc.getHundredths();
// if(timeCheck != lastHundred){
// lastHundred = timeCheck;
// }
// for (uint16_t i = 12800; i > 0; i--) { //microsteps
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(69); //70-69 too fast 70-70 too slow
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(70);
// }
//dir = !dir; // REVERSE DIRECTION
}