Need help with 2 L298Ns on a single Nano to control 3 motors

I need some assistance adding a second L298N on my nano. All will be controlled by RC transmitter and Receiver.

Can you point me in the direction of some resources or example code for two(2) L298Ns controlling 3 or more motors.

The 1st L298N will run 2 motors with tank steering

the 3rd will rotate the dome of the robot.

I successfully programmed the drive and tank steering, using a base code i found from a blog.
Using the same method, I added the lines for the second L298n, but the 2nd L298N is just not responding to the code.

/*
L298N Motor Control with Flysky6

*/

// Motor A Drive

int enA = 11;
int in1 = 10;
int in2 = 9;

// Motor B Drive

int enB = 6;
int in3 = 8;
int in4 = 7;

// Motor C Dome

int enC = 5;
int in5 = 4;
int in6 = 3;

// Joystick Input

int joyDriveA = A0; // Vertical
int joyDriveB = A1; // Horizontal
int joyDome = A2; // DOME

// Motor Speed Values - Start at zero

int MotorSpeed1 = 0;
int MotorSpeed2 = 0;
int MotorSpeed3 = 0;

// Joystick Values - Start at 512 (middle position)

int joyposVert = 512;
int joyposHorz = 512;
int joyposDome = 512;

void setup()

{

// Set all the motor control pins to outputs

pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(enC, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(in5, OUTPUT);
pinMode(in6, OUTPUT);

// Start with motors disabled and direction forward

// Motor A

digitalWrite(enA, LOW);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Motor B

digitalWrite(enB, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

// Motor C Dome

digitalWrite(enC, LOW);
digitalWrite(in5, HIGH);
digitalWrite(in6, LOW);
}

void loop() {

// Read the Joystick X and Y positions

joyposVert = analogRead(joyDriveA); 
joyposHorz = analogRead(joyDriveB);
joyposDome = analogRead(joyDome);

// Determine if this is a forward or backward motion
// Do this by reading the Verticle Value
// Apply results to MotorSpeed and to Direction

if (joyposVert < 460)
{
	// This is Backward

	// Set Motor A backward

	digitalWrite(in1, LOW);
	digitalWrite(in2, HIGH);

	// Set Motor B backward

	digitalWrite(in3, LOW);
	digitalWrite(in4, HIGH);

	//Determine Motor Speeds

	// As we are going backwards we need to reverse readings

	joyposVert = joyposVert - 460; // This produces a negative number
	joyposVert = joyposVert * -1;  // Make the number positive

	MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);
	MotorSpeed2 = map(joyposVert, 0, 460, 0, 255);

}
else if (joyposVert > 564)
{
	// This is Forward

	// Set Motor A forward

	digitalWrite(in1, HIGH);
	digitalWrite(in2, LOW);

	// Set Motor B forward

	digitalWrite(in3, HIGH);
	digitalWrite(in4, LOW);

	//Determine Motor Speeds

	MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);
	MotorSpeed2 = map(joyposVert, 564, 1023, 0, 255); 

}
else
{
	// This is Stopped

	MotorSpeed1 = 0;
	MotorSpeed2 = 0; 

}

// Now do the steering
// The Horizontal position will "weigh" the motor speed
// Values for each motor

if (joyposHorz < 460)
{
	// Move Left

	// As we are going left we need to reverse readings

	joyposHorz = joyposHorz - 460; // This produces a negative number
	joyposHorz = joyposHorz * -1;  // Make the number positive

	// Map the number to a value of 255 maximum

	joyposHorz = map(joyposHorz, 0, 460, 0, 255);
		  

	MotorSpeed1 = MotorSpeed1 - joyposHorz;
	MotorSpeed2 = MotorSpeed2 + joyposHorz;

	// Don't exceed range of 0-255 for motor speeds

	if (MotorSpeed1 < 0)MotorSpeed1 = 0;
	if (MotorSpeed2 > 255)MotorSpeed2 = 255;

}
else if (joyposHorz > 564)
{
	// Move Right

	// Map the number to a value of 255 maximum

	joyposHorz = map(joyposHorz, 564, 1023, 0, 255);
		  

	MotorSpeed1 = MotorSpeed1 + joyposHorz;
	MotorSpeed2 = MotorSpeed2 - joyposHorz;

	// Don't exceed range of 0-255 for motor speeds

	if (MotorSpeed1 > 255)MotorSpeed1 = 255;
	if (MotorSpeed2 < 0)MotorSpeed2 = 0;		  

}
// Now do the Dome 
// The Chan3 position will "control the dome Clockwise and counter Clockwise 
// Values for each motor

if (joyposDome < 460)
{
	// This is CounterClock

	// Set Dome CounterClock

	digitalWrite(in5, LOW);
	digitalWrite(in6, HIGH);


	//Determine Motor Speeds

	// As we are going CouterClock we need to reverse readings

	joyposDome = joyposDome - 460; // This produces a negative number
	joyposDome = joyposDome * -1;  // Make the number positive

	MotorSpeed3 = map(joyposDome, 0, 460, 0, 70);
	 
}
else if joyposDome > 564)
{
	// This is Clockwise 

	// Set Dome Clockwise

	digitalWrite(in5, HIGH);
	digitalWrite(in6, LOW);


	//Determine Motor Speeds

	MotorSpeed3 = map(joyposDome, 564, 1023, 0, 70);


}
else
{
	// This is Stopped

	MotorSpeed3 = 0;
	 
}


// Adjust to prevent "buzzing" at very low speed

if (MotorSpeed1 < 8)MotorSpeed1 = 0;
if (MotorSpeed2 < 8)MotorSpeed2 = 0;
if (MotorSpeed3 < 8)MotorSpeed3 = 0;

// Set the motor speeds

analogWrite(enA, MotorSpeed1);
analogWrite(enB, MotorSpeed2);
analogWrite(enC, MotorSpeed3);

}

@rblas , your topic has been moved to a more suitable location of the forum to give it a better exposure.

Can you please edit reply #2, select all code and click the < / > button above the edit textbox; next save your post. This will prevent a number of oddities and makesit easier to copy.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.