Hi Everyone,
Please find the reference to my previous topic here.
I have a stepper motor connected to a motor driver CL57T which expects a 5V signal from a controller like Arduino.
The Dir+ and Pulse+ pins are connected to the GPIO2 and GPIO3 pins respectively and the Dir- and Pulse- are connected to the ground on the mid carrier.
When I run the attached sketch, I am not able to make the motor run. I understand and based on my tests using a multimeter both the portenta h7 and mid carrier outputs a 3.3V signal.
#include <AccelStepper.h>
// Pin Definitions
#define dirPin PD_5 // Direction pin for the DM542
#define pulsePin PD_4 // Pulse pin for the DM542
long newPosition = -1;
long final_slack = 0;
long currentPosition = -1; // Current position in steps (-1 indicates uncalibrated)
long targetPosition = 0; // Target position in steps
float max_speed = 1000.0;
float acceleration = 700.0;
// Motor and screw parameters
const float screwPitch = 1.27; //1.5875; // Ball screw pitch in mm/revolution
const int stepsPerRevolution = 200; // Motor steps per revolution
const int microstepping = 1; // Microstepping factor
const float stepsPerMM = (stepsPerRevolution * microstepping) / screwPitch;
const int incrementDistance = 5; // Distance for each smaller movement (mm to steps)
// Define constants based on encoder and motor specs
//#define ENCODER_CPR 400 // Counts per revolution (from encoder datasheet)
// Motor control parameters
const unsigned long holdTime = 15000; // Time to hold at target position in ms
const unsigned long HomeHoldTime = 2000; // Time to hold at home position in ms
// Create an instance of AccelStepper
AccelStepper stepper(AccelStepper::DRIVER, pulsePin, dirPin);
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
Serial.println("Stepper Motor with Calibration and Position Control Initialized.");
// Configure the stepper motors
stepper.setMinPulseWidth(20);
stepper.setMaxSpeed(max_speed); // Set maximum speed (adjust as needed)
stepper.setAcceleration(acceleration); // Set acceleration (adjust as needed)
Serial.println("stepsPerMM: " + String(stepsPerMM));
//delay(HomeHoldTime);
//calibrateToHome2();
//delay(HomeHoldTime);
}
void loop() {
moveToTargetPosition(88);
//stepper.stop();t
Serial.println("Moved to 88 mm");
delay(HomeHoldTime);
moveToTargetPosition(0);
Serial.println("Moved to home");
delay(HomeHoldTime);
}
// Function to move to a specific target position in steps
void moveToTargetPosition(float positionInMM) {
// Convert target position to steps
targetPosition = positionInMM * stepsPerMM + final_slack; //* stepsPerMM;
Serial.print("positionInMM: " + String(positionInMM) + " Target Position: " + String(targetPosition));
Serial.print("\n");
// Set the target position in steps
stepper.moveTo(targetPosition);
// Move the motor to the target position
while (stepper.distanceToGo() != 0) {
//Serial.println("Sending Pulse");
stepper.run();
}
// Update the current position
currentPosition = targetPosition;
Serial.print("Moved to position (mm): ");
Serial.println(currentPosition / stepsPerMM); // This is how you will get current position in MM.
}
However, surprisingly when I remove the Portenta H7 from the mid carrier and connect the Dir+ and Pulse+ pins to D3 and D5 along with the Dir- and Pulse- to the Ground pin of the Portenta H7 and run the sketch after updating the pins it all works. I can see the motor running as expected. Thus, I am not able to figure out why doesn’t it work when I use a MidCarrier??
I even tried connecting them to the PWM pins, however I see the same behaviour where the motor does not run when connected to the Mid carrier.
Find attached picture and the link to a video for the Portenta H7 motor run. I look forward to hearing back from you.
Thanks in advance.
