HI!
I recently attempted to upgrade from Cytron’s MDDS10 to MDDS30. I use it to driver 2 motors with a digital joystick for steering, and a single potentiometer for speed. I was assuming this would be a simple switch, but it has not been. While the driver recognizes the input for the motors, it is not recognizing the PWM input. I have been back and forth with Cytron, who state:
But, it is Chinese New Year, and they are out of the office for the next couple of days, and my project is time sensitive. I have never done serial simplified or packetized before, but would be willing to try, as I really need to get this done. I have download their examples, but this doesn’t really show me how to add my joystick or the pot to control speed. I have very basic coding knowledge. My code for the MDDS30 run in PWM mode is posted below- can someone PLEASE help me adjust it so it will run in one of the other modes?Thanks!
int sw1=10;
int sw2=11;
int sw3=12;
int sw4=6;
int state1;
int state2;
int state3;
int state4;
//MOTOR A
int pwm1 = 9;
int dir1 = 8;
// Motor B
int pwm2 = 3;
int dir2 = 5;
// Speed control potentiometers
int SpeedControll = A0;
// Motor Speed Values - Start at zero
int MotorSpeed1 = 0;
void setup() {
pinMode(sw1,INPUT_PULLUP);
pinMode(sw2,INPUT_PULLUP);
pinMode(sw3,INPUT_PULLUP);
pinMode(sw4,INPUT_PULLUP);
Serial.begin(9600);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(dir2, OUTPUT);
}
void loop() {
state1 = digitalRead(sw1);
state2 = digitalRead(sw2);
state3 = digitalRead(sw3);
state4 = digitalRead(sw4);
// Read the values from the potentiometers
MotorSpeed1 = analogRead (SpeedControll);
// Convert to range of 0-255
MotorSpeed1 = map(MotorSpeed1, 0, 1023, 0, 255);
if (state1 == 0) { //Make a Right turn
analogWrite(pwm2, MotorSpeed1);
analogWrite(pwm1, MotorSpeed1);
digitalWrite(dir2, HIGH);
digitalWrite(dir1, LOW);
}
else if (state2 == 0) { //Forward Movement
analogWrite(pwm1, MotorSpeed1);
analogWrite(pwm2, MotorSpeed1);
digitalWrite(dir1, HIGH);
digitalWrite(dir2, HIGH);
}
else if (state3 == 0) { //Take a left turn
analogWrite(pwm1, MotorSpeed1);
analogWrite(pwm2,MotorSpeed1);
digitalWrite(dir1, HIGH);
digitalWrite(dir2, LOW);
}
else if (state4 == 0) { //Backward Movement
analogWrite(pwm1, MotorSpeed1);
analogWrite(pwm2, MotorSpeed1);
digitalWrite(dir1, LOW);
digitalWrite(dir2, LOW);
}
else {
analogWrite(pwm1, 0);
analogWrite(pwm2, 0);
digitalWrite(dir1, LOW);
digitalWrite(dir2, LOW);
}
Serial.print("1-");
Serial.print(state1);
Serial.print(" 2-");
Serial.print(state2);
Serial.print(" 3-");
Serial.print(state3);
Serial.print(" 4-");
Serial.println(state4);
delay(250);
}