Hi, I have an issue where I have a makerverse motor driver hooked up to 4 motors on my Rover robot. The front and back motors are wired together so that the left side moves together as does the right. I am using N20 motors. The issue is that I cannot seem to drive the sides at different speeds. Here is some example code that I am using. Both sides run at the same speed. If I drive each side separately I can change their speeds so everything seems hooked up properly. Here is the code:
#define MOTOR_LEFT_PIN 9
#define MOTOR_RIGHT_PIN 3
#define DIR_LEFT_PIN 2
#define DIR_RIGHT_PIN 4
void setup() {
pinMode(MOTOR_LEFT_PIN, OUTPUT);
pinMode(MOTOR_RIGHT_PIN, OUTPUT);
pinMode(DIR_LEFT_PIN, OUTPUT);
pinMode(DIR_RIGHT_PIN, OUTPUT);
// Set both motors to forward direction
digitalWrite(DIR_LEFT_PIN, HIGH);
digitalWrite(DIR_RIGHT_PIN, HIGH);
}
void loop() {
// Set different motor speeds
analogWrite(MOTOR_LEFT_PIN, 100); // Left motor slower
analogWrite(MOTOR_RIGHT_PIN, 255); // Right motor faster
delay(2000); // Let the motors run for 2 seconds
}
Your code seems to be driving each motor separately: there should be no connection between the two separate analogWrite commands. Do you mean that you can control the speed when you are driving only one motor at a time? I suspect the important bit might be the connection from the MCU to the motor driver. Which Makerverse motor driver are you using and how is it wired in?
When you run both motors, is it always the same one that controls the speed, and which one is it? Or do both motors run at the higher (or lower) speed setting, regardless of which motor that is?
A slight update. It seems that they do drive at different speeds (the left and right sides). However, it seems that the faster side forces the wheels on the slower side to speed up until they are both travelling at the same speed. Almost like the motors ‘give in’ to the friction or something.
Here is the code I was just testing with. If you hold the robot in the air, you can see the different speeds on each side. When you put it down, it starts to turn but then quickly straightens out.
#define MOTOR_LEFT_PIN 3
#define MOTOR_RIGHT_PIN 5
#define DIR_LEFT_PIN 2
#define DIR_RIGHT_PIN 4
void setup() {
// Set motor pins as output
pinMode(MOTOR_LEFT_PIN, OUTPUT);
pinMode(MOTOR_RIGHT_PIN, OUTPUT);
pinMode(DIR_LEFT_PIN, OUTPUT);
pinMode(DIR_RIGHT_PIN, OUTPUT);
// Set both motors to drive forward
digitalWrite(DIR_LEFT_PIN, HIGH); // Set direction for left motor
digitalWrite(DIR_RIGHT_PIN, HIGH); // Set direction for right motor
}
void loop() {
int speedLeft = 35; // Speed for left motor (0-255)
int speedRight = 255; // Speed for right motor (0-255)
// Set motor speeds
analogWrite(MOTOR_LEFT_PIN, speedLeft);
delay(2000);
analogWrite(MOTOR_RIGHT_PIN, speedRight);
// Keep running the motors at set speed
delay(1000); // Adjust delay as needed
}
Another update. It seems, it does make a difference which motors are running. I tested with 200, 300 and 500rpm. With 200 it seems like I can get it to work after a fashion. I changed the code to do this (using my library which amounts to the same thing as before):
If I set one side to 0, it is turning. The forward method parameter 1 and 2 set the speed on left and right sides as a percentage. The 3rd parameter sets the duration of the forward movement.