MDD10aA with digital joystick

LINIX Brushless, VEXTA Brushless, RC Servo, DC Geared, Linear, Stepper, Tamiya.....

MDD10aA with digital joystick

Postby mscholl » Sat Sep 09, 2017 9:21 pm

I am new to the forum. I am trying to drive 2 motors with a digital joystick, and use a separate PWM to control the speed. I bought the MDD10A, but this hooks up differently than the L298N motor driver that I mocked up first. (I need the MDD10A to handle the amps needed).
Below is the code I wrote for the L298N, which works fine. How do I adjust the code to work for the MDD10A, as I only have DIR1 and DIR2, instead of EN1, IN1, IN2, IN3, IN4, En2?
Also, is there a way to power the arduino thru the motor driver (I don't see a 5v connection)?

CODE: SELECT_ALL_CODE
int sw1=10;
int sw2=11;
int sw3=12;

int sw4=6;
int state1;
int state2;
int state3;
int state4;

//MOTOR A
int enA = 9;
int in1 = 8;
int in2 = 7;

// Motor B
int enB = 3;
int in3 = 5;
int in4 = 4;

void setup() {
  pinMode(sw1,INPUT_PULLUP);
  pinMode(sw2,INPUT_PULLUP);
  pinMode(sw3,INPUT_PULLUP);
  pinMode(sw4,INPUT_PULLUP);

  Serial.begin(9600);

  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}

void loop() {
  state1 = digitalRead(sw1);
  state2 = digitalRead(sw2);
  state3 = digitalRead(sw3);
  state4 = digitalRead(sw4);

  if (state1 == 0) { //Make a Right turn
    analogWrite(enB, 50);
    analogWrite(enA, 0);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
  }
  else if (state2 == 0) { //Forward Movement
    analogWrite(enA, 250);
    analogWrite(enB, 250);
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
  }
  else if (state3 == 0) { //Take a left turn
    analogWrite(enA, 50);
    analogWrite(enB,0);
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, LOW);
  }
  else if (state4 == 0) { //Backward Movement
    analogWrite(enA, 50);
    analogWrite(enB, 50);
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
  }
  else {
    analogWrite(enA, 0);
    analogWrite(enB, 0);
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, 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);
}
mscholl
Newbie
 
Posts: 10
Joined: Sat Sep 09, 2017 8:55 pm

Re: MDD10aA with digital joystick

Postby Idris » Mon Sep 11, 2017 6:03 pm

Hi mscholl,

mscholl WROTE:I am new to the forum. I am trying to drive 2 motors with a digital joystick, and use a separate PWM to control the speed. I bought the MDD10A, but this hooks up differently than the L298N motor driver that I mocked up first. (I need the MDD10A to handle the amps needed).
Below is the code I wrote for the L298N, which works fine. How do I adjust the code to work for the MDD10A, as I only have DIR1 and DIR2, instead of EN1, IN1, IN2, IN3, IN4, En2?

For EN pin, it is same as PWM pin.
For DIR pin, instead of using 2 pins (IN1, IN2) to control direction, you just need 1 pin in MDD10A, for example:
DIR = 1, equal to IN1 = 1, IN2 = 0.
DIR = 0, equal to IN1 = 0, IN2 = 1.
If you want to stop the motor, just set PWM pin = 0.

mscholl WROTE:Also, is there a way to power the arduino thru the motor driver (I don't see a 5v connection)?

Yes, there is no 5V pin at MDD10A. However you still can use a single battery to supply both. If you are using 12V to supply the motor driver, you can use the same 12V to supply Arduino by connecting it to Vin pin.

Hope this helps. Thanks.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 384
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: MDD10aA with digital joystick

Postby mscholl » Tue Sep 12, 2017 3:52 am

I got it to work but would like to add a potentiometer- how do I do this? My current code is this?
int sw1=10;
int sw2=11;
int sw3=12;

int sw4=7;
int state1;
int state2;
int state3;
int state4;

//MOTOR A
int pwm1 = 9;
int dir1 = 8;


// Motor B
int pwm2 = 3;
int dir2 = 5;


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

if (state1 == 0) { //Make a Right turn
analogWrite(pwm2, 50);
analogWrite(pwm1, 0);
digitalWrite(dir2, HIGH);
digitalWrite(dir1, LOW);
}
else if (state2 == 0) { //Forward Movement
analogWrite(pwm1, 100);
analogWrite(pwm2, 100);
digitalWrite(dir1, HIGH);
digitalWrite(dir2, HIGH);
}
else if (state3 == 0) { //Take a left turn
analogWrite(pwm1, 50);
analogWrite(pwm2,0);
digitalWrite(dir1, HIGH);
digitalWrite(dir2, LOW);
}
else if (state4 == 0) { //Backward Movement
analogWrite(pwm1, 100);
analogWrite(pwm2, 100);
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);
}
mscholl
Newbie
 
Posts: 10
Joined: Sat Sep 09, 2017 8:55 pm

Re: MDD10aA with digital joystick

Postby ober » Tue Sep 12, 2017 10:36 am

I think you can just try it out, it is faster. Others do not have your setup and it is not possible for us to setup every projects in forum to test our the code.
Let us know where it is not working.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1441
Joined: Wed Apr 15, 2009 1:03 pm


Return to DC Motor

Who is online

Users browsing this forum: No registered users and 12 guests

cron