Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What type of L298 board are you using? #48

Open
dakoner opened this issue Dec 11, 2017 · 2 comments
Open

What type of L298 board are you using? #48

dakoner opened this issue Dec 11, 2017 · 2 comments

Comments

@dakoner
Copy link

dakoner commented Dec 11, 2017

I spent part of the weekend wondering why the ros_arduino_firmware wasn't doing speed control on my motors. I noticed that the code for the L298 looks like this:
https://github.com/hbrobotics/ros_arduino_bridge/blob/indigo-devel/ros_arduino_firmware/src/libraries/ROSArduinoBridge/motor_driver.ino#L76

Specifically, you're PWMing the motor direction pins:
if (i == LEFT) {
if (reverse == 0) { analogWrite(RIGHT_MOTOR_FORWARD, spd); analogWrite(RIGHT_MOTOR_BACKWARD, 0); }
else if (reverse == 1) { analogWrite(RIGHT_MOTOR_BACKWARD, spd); analogWrite(RIGHT_MOTOR_FORWARD, 0); }
}
else /if (i == RIGHT) //no need for condition/ {
if (reverse == 0) { analogWrite(LEFT_MOTOR_FORWARD, spd); analogWrite(LEFT_MOTOR_BACKWARD, 0); }
else if (reverse == 1) { analogWrite(LEFT_MOTOR_BACKWARD, spd); analogWrite(LEFT_MOTOR_FORWARD, 0); }
}

However, all the L298's that I have, for example this:
https://www.amazon.com/DROK-Controller-H-Bridge-Mega2560-Duemilanove/dp/B00CAG6GX2
the speed control is the enable pin, not the FORWARD/BACKWARD pins.

So I am curious what board you have. Otherwise, I think this code must be in error- you're supposed to PWM the enable pins, not the motor direction pins.

@YikeStone
Copy link

YikeStone commented Jan 10, 2018

The code is correct. to use this code you need 4 pwm pins not 2. some corrections are needed in like- LEFT condition is checked and RIGHT motor is manipulated and vice versa.
And it will work on any L298Ns.

@MSohan14
Copy link

MSohan14 commented Jul 9, 2024

Ik that it has been a long time but can you tell if you got it to work and if so how?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants