0

I'm trying to control DC motors with L298N motor driver. I'm using Raspberry Pi 3B and java GUI called Processing. I can't find PWM libraries for software control or use hardware PWM because I need two PWM pins but Raspberry Pi has only one.

Any suggestions for libraries... or anything else?

2 Answers 2

2

The Pi has two hardware PWM channels.

Channel 0 may be fed to GPIO 12 and/or 18.

Channel 1 may be fed to GPIO 13 and/or 19.

GPIO 12/13/18/19 are brought out to all Pis with the 40-pin expansion header.

My pigpio library supports use of the hardware PWM pins as well as providing hardware timed PWM on all the GPIO (equally suitable for motor speed control).

I have no idea how easy it would be to integrate pigpio into your environment.

You mention Java. There is a Java library called Pi4J which might be suitable.

0

If you need more than the available 2 channels, or even more generally if you need to interface to any kind of hardware (e.g. GPS, thermometer, accelerometer, etc.), you can just use an external controller board connected to RPi through I2C. You can connect many boards to the same I2C pins by giving them unique addresses.

For example, you get 16 channels of PWM using this board: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685

And you can connect 62 of these boards to the same I2C pins, and effectively have nearly a thousand PWM channels. And they don't use up your RPi's CPU cycles, so you can really control 1000 different motors with just one RPi. To learn about I2C on RPi here is a reference: Configuring I2C.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.