MDDS30

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);
}

Hi,

Well, that is quite unfortunate about the buggy input for PWM signal. That being said, using simple serial or packet serial modes are certainly good alternatives.
You can find the library from Cyton here (and download it as a ZIP here). See this article from Arduino on how to import the library in the Arduino IDE directly.

You may also want to refer to the user manual found on the product page under Useful Links. Here is a direct link to it.

The first thing you’ll want to do is set the MDDS30 to simple serial (or packet serial) mode by changing the DIP switches. Make sure to turn off all power before making any changes the DIP switch or the wiring.
See page 13 of the user manual (chapter 8 ) for the DIP switch overview, pages 20-22 (chapter 8.3) for simple serial and pages 23-25 (chapter 8.4) for packet serial.

We strongly recommend going for simple serial since it should easily provide all that you need. With this mode, you can easily control each motor channel (left / right) and set which direction it turns (clockwise (CW)/counter-clockwise (CCW) and the speed, from complete stop (0) to full speed (63), which gives you 64 different speed levels (typically enough for most applications).

Once you have the library installed, open up the example titled MDDSSerialSimpleTest. You can use this as reference on how to initialize the Cytron Smart Drive Duo in simple serial mode (lines 33-37) and how to send a command to it (line 99).

You can simply add lines 33-37 to your code (outside/above Setup(), as in the Cytron example) and then use the code on line 99 in your sketch to control the motors (instead of your digital & PWM outputs). As you can see from the example, the control(speedLeft, speedRight) function takes two parameters. The speed values are in the range of -100, 100] (these represent a % of full speed), with negative and positive values being in opposite direction and 0 meaning full stop.

Also, wiring-wise, do not forgot to change wires to match the new configuration, which should only consist of two wires:`

]A common GND (ground) wire between the MDDS30 and your Arduino board./:m]
]The serial TX wire from the Arduino to the MDDS30 input. In the Cytron example, the pin used on the Arduino is 4, but this can be changed to pretty much any other digital pin./:m]
You can see the board layout and connection details on pages 8-9 (chapter 4). If we are not mistaken, you should be using IN1 (found at point “O”).
We hope this helps get you going with your project. Feel free to post here again if you have any other questions!

Sincerely,

P.-S.: We fixed your original post a bit for readability, hope you don’t mind much… :wink:

P.-S.#2: When adding code snippets, try to keep them to a few lines at most (for readability). If you need to refer to the whole thing, we recommend to either use a link to code sharing site (such at GitHub, BitBucket, etc.) or to attach it as a .ZIP to your post (you can do so in Full editor mode by clicking the Attachments bar (below the post editing window & buttons).

Can you please give me an example of what you are talking about with line 99? For example, what would my forward direction now look like?
Thanks!

Hi,

As mentioned above (and as seen in the example), the control(leftSpeed, leftSpeed) of the Cytron_SmartDriveDuo object is used to set the speed value of both channels simultaneously.

Therefore, to go forward at full speed, you would use:

[Cytron_SmartDriveDuo object name].control(100, 100); In the case of the example from Cytron, they create the object as smartDriveDuo30 on line 37.
Therefore, in that case, you would use:

smartDriveDuo30.control(100, 100); Of course, it would be best to use variables (as they do in the example) so you can easily change the speed in your code and update it every loop.
Sincerely,