1

Topic: How to change a code written for L298N motor driver to another driver

http://remotexy.com/en/examples/car/

Above I have mentioned the link of an example provided by RemoteXY. This example shows us that how could we create a Bluetooth Based, Smartphone Controlled Robot (Car). In this example/tutorial, we have used L298N motor driver. I don't want to use that motor driver on my project because I need to use L293D Motor Driver Shield in my project due to some reasons. But, I am unable to manipulate this code from code for L298N Motor Driver to that for L293D Motor Shield.

I know how to work with L293D Motor Driver Shield to control DC Motors, Stepper Motors and Servo Motors but, I know doing it by including Adafruit's Library "AFmotor.h".

In this case, we defined separate pin numbers for separate motors and two different pins for ENA and ENB, in order to maintain speed control via Virtual Joystick. But, when we use L293D Motor Driver Shield then, we don't know the exact pins which are controlling different parts of our robot, so this example didn't just help me in this case.

This https://m.banggood.in/Motor-Drive-Shiel … rehouse=CN is the exact L293D Motor Driver Shield for Arduino UNO, that I was talking about.

I am posting the code provided in example, here also, just to be specific:

/////////////////////////////////////////////  
//        RemoteXY include library         //  
/////////////////////////////////////////////  

/* RemoteXY select connection mode and include library */  
#define REMOTEXY_MODE__SOFTWARESERIAL  
#include <SoftwareSerial.h>  
#include <RemoteXY.h>  

/* RemoteXY connection settings */ 
#define REMOTEXY_SERIAL_RX 2  
#define REMOTEXY_SERIAL_TX 3  
#define REMOTEXY_SERIAL_SPEED 9600  

/* RemoteXY configurate  */   
unsigned char RemoteXY_CONF[] =  
  { 3,0,23,0,1,5,5,15,41,11 
  ,43,43,1,2,0,6,5,27,11,5 
  ,79,78,0,79,70,70,0 };  
    
/* this structure defines all the variables of your control interface */   
struct {  

    /* input variable */ 
  signed char joystick_1_x; /* =-100..100 x-coordinate joystick position */ 
  signed char joystick_1_y; /* =-100..100 y-coordinate joystick position */ 
  unsigned char switch_1; /* =1 if switch ON and =0 if OFF */ 

    /* other variable */ 
  unsigned char connect_flag;  /* =1 if wire connected, else =0 */ 

} RemoteXY;  

/////////////////////////////////////////////  
//           END RemoteXY include          //  
/////////////////////////////////////////////  
/* defined the right motor control pins */ 
#define PIN_MOTOR_RIGHT_UP 7 
#define PIN_MOTOR_RIGHT_DN 6 
#define PIN_MOTOR_RIGHT_SPEED 10 

/* defined the left motor control pins */ 
#define PIN_MOTOR_LEFT_UP 5 
#define PIN_MOTOR_LEFT_DN 4 
#define PIN_MOTOR_LEFT_SPEED 9 

/* defined the LED pin */ 
#define PIN_LED 13 


/* defined two arrays with a list of pins for each motor */ 
unsigned char RightMotor[3] =  
  {PIN_MOTOR_RIGHT_UP, PIN_MOTOR_RIGHT_DN, PIN_MOTOR_RIGHT_SPEED}; 
unsigned char LeftMotor[3] =  
  {PIN_MOTOR_LEFT_UP, PIN_MOTOR_LEFT_DN, PIN_MOTOR_LEFT_SPEED}; 

/* 
   speed control of the motor 
   motor - pointer to an array of pins 
   v - motor speed can be set from -100 to 100 
*/ 
void Wheel (unsigned char * motor, int v) 
{ 
  if (v>100) v=100; 
  if (v<-100) v=-100; 
  if (v>0) { 
    digitalWrite(motor[0], HIGH); 
    digitalWrite(motor[1], LOW); 
    analogWrite(motor[2], v*2.55); 
  } 
  else if (v<0) { 
    digitalWrite(motor[0], LOW); 
    digitalWrite(motor[1], HIGH); 
    analogWrite(motor[2], (-v)*2.55); 
  } 
  else { 
    digitalWrite(motor[0], LOW); 
    digitalWrite(motor[1], LOW); 
    analogWrite(motor[2], 0); 
  } 
} 

void setup() 
{ 
  /* initialization pins */ 
  pinMode (PIN_MOTOR_RIGHT_UP, OUTPUT); 
  pinMode (PIN_MOTOR_RIGHT_DN, OUTPUT); 
  pinMode (PIN_MOTOR_LEFT_UP, OUTPUT); 
  pinMode (PIN_MOTOR_LEFT_DN, OUTPUT); 
  pinMode (PIN_LED, OUTPUT); 

  /* initialization module RemoteXY */ 
  RemoteXY_Init (); 

} 

void loop() 
{ 
  /* event handler module RemoteXY */ 
  RemoteXY_Handler (); 

  /* manage LED pin */ 
  digitalWrite (PIN_LED, (RemoteXY.switch_1==0)?LOW:HIGH); 

  /* manage the right motor */ 
  Wheel (RightMotor, RemoteXY.joystick_1_y - RemoteXY.joystick_1_x); 
  /* manage the left motor */ 
  Wheel (LeftMotor, RemoteXY.joystick_1_y + RemoteXY.joystick_1_x); 
} 



Everything can be same just I want to convert this code for L293D Motor Driver Shield instead of L298N driver.

I searched on internet if I could get any idea for that, but everywhere people were just using "AFMotor.h" library and it will be very difficult to use that library's given functions in our robot, if we want to control our Robot using RemoteXY's joystick. So, I finally came here for help from you experts.

Please help me in this issue.

P.S.:- It would be very great, kind and pleasant if you, yourself edit the example's code in order to use it for L293D Motor Driver Shield while explaining me that how its done.

Thank You So Much in Advance. ❤️❤️❤️

2

Re: How to change a code written for L298N motor driver to another driver

naved.the.sheikh wrote:

http://remotexy.com/en/examples/car/

Above I have mentioned the link of an example provided by RemoteXY. This example shows us that how could we create a Bluetooth Based, Smartphone Controlled Robot (Car). In this example/tutorial, we have used L298N motor driver. I don't want to use that motor driver on my project because I need to use L293D Motor Driver Shield in my project due to some reasons. But, I am unable to manipulate this code from code for L298N Motor Driver to that for L293D Motor Shield.

I know how to work with L293D Motor Driver Shield to control DC Motors, Stepper Motors and Servo Motors but, I know doing it by including Adafruit's Library "AFmotor.h".

In this case, we defined separate pin numbers for separate motors and two different pins for ENA and ENB, in order to maintain speed control via Virtual Joystick. But, when we use L293D Motor Driver Shield then, we don't know the exact pins which are controlling different parts of our robot, so this example didn't just help me in this case.

This https://m.banggood.in/Motor-Drive-Shiel … rehouse=CN is the exact L293D Motor Driver Shield for Arduino UNO, that I was talking about.

I am posting the code provided in example, here also, just to be specific:

/////////////////////////////////////////////  
//        RemoteXY include library         //  
/////////////////////////////////////////////  

/* RemoteXY select connection mode and include library */  
#define REMOTEXY_MODE__SOFTWARESERIAL  
#include <SoftwareSerial.h>  
#include <RemoteXY.h>  

/* RemoteXY connection settings */ 
#define REMOTEXY_SERIAL_RX 2  
#define REMOTEXY_SERIAL_TX 3  
#define REMOTEXY_SERIAL_SPEED 9600  

/* RemoteXY configurate  */   
unsigned char RemoteXY_CONF[] =  
  { 3,0,23,0,1,5,5,15,41,11 
  ,43,43,1,2,0,6,5,27,11,5 
  ,79,78,0,79,70,70,0 };  
    
/* this structure defines all the variables of your control interface */   
struct {  

    /* input variable */ 
  signed char joystick_1_x; /* =-100..100 x-coordinate joystick position */ 
  signed char joystick_1_y; /* =-100..100 y-coordinate joystick position */ 
  unsigned char switch_1; /* =1 if switch ON and =0 if OFF */ 

    /* other variable */ 
  unsigned char connect_flag;  /* =1 if wire connected, else =0 */ 

} RemoteXY;  

/////////////////////////////////////////////  
//           END RemoteXY include          //  
/////////////////////////////////////////////  
/* defined the right motor control pins */ 
#define PIN_MOTOR_RIGHT_UP 7 
#define PIN_MOTOR_RIGHT_DN 6 
#define PIN_MOTOR_RIGHT_SPEED 10 

/* defined the left motor control pins */ 
#define PIN_MOTOR_LEFT_UP 5 
#define PIN_MOTOR_LEFT_DN 4 
#define PIN_MOTOR_LEFT_SPEED 9 

/* defined the LED pin */ 
#define PIN_LED 13 


/* defined two arrays with a list of pins for each motor */ 
unsigned char RightMotor[3] =  
  {PIN_MOTOR_RIGHT_UP, PIN_MOTOR_RIGHT_DN, PIN_MOTOR_RIGHT_SPEED}; 
unsigned char LeftMotor[3] =  
  {PIN_MOTOR_LEFT_UP, PIN_MOTOR_LEFT_DN, PIN_MOTOR_LEFT_SPEED}; 

/* 
   speed control of the motor 
   motor - pointer to an array of pins 
   v - motor speed can be set from -100 to 100 
*/ 
void Wheel (unsigned char * motor, int v) 
{ 
  if (v>100) v=100; 
  if (v<-100) v=-100; 
  if (v>0) { 
    digitalWrite(motor[0], HIGH); 
    digitalWrite(motor[1], LOW); 
    analogWrite(motor[2], v*2.55); 
  } 
  else if (v<0) { 
    digitalWrite(motor[0], LOW); 
    digitalWrite(motor[1], HIGH); 
    analogWrite(motor[2], (-v)*2.55); 
  } 
  else { 
    digitalWrite(motor[0], LOW); 
    digitalWrite(motor[1], LOW); 
    analogWrite(motor[2], 0); 
  } 
} 

void setup() 
{ 
  /* initialization pins */ 
  pinMode (PIN_MOTOR_RIGHT_UP, OUTPUT); 
  pinMode (PIN_MOTOR_RIGHT_DN, OUTPUT); 
  pinMode (PIN_MOTOR_LEFT_UP, OUTPUT); 
  pinMode (PIN_MOTOR_LEFT_DN, OUTPUT); 
  pinMode (PIN_LED, OUTPUT); 

  /* initialization module RemoteXY */ 
  RemoteXY_Init (); 

} 

void loop() 
{ 
  /* event handler module RemoteXY */ 
  RemoteXY_Handler (); 

  /* manage LED pin */ 
  digitalWrite (PIN_LED, (RemoteXY.switch_1==0)?LOW:HIGH); 

  /* manage the right motor */ 
  Wheel (RightMotor, RemoteXY.joystick_1_y - RemoteXY.joystick_1_x); 
  /* manage the left motor */ 
  Wheel (LeftMotor, RemoteXY.joystick_1_y + RemoteXY.joystick_1_x); 
} 



Everything can be same just I want to convert this code for L293D Motor Driver Shield instead of L298N driver.

I searched on internet if I could get any idea for that, but everywhere people were just using "AFMotor.h" library and it will be very difficult to use that library's given functions in our robot, if we want to control our Robot using RemoteXY's joystick. So, I finally came here for help from you experts.

Please help me in this issue.

P.S.:- It would be very great, kind and pleasant if you, yourself edit the example's code in order to use it for L293D Motor Driver Shield while explaining me that how its done.

Thank You So Much in Advance. ❤️❤️❤️



Update:  I have found my own around, myself.
Thank You So Much for coming here.