Page 1 of 1

Control motors with Pololu DRV8835 Dual Motor Driver

Posted: Sun Jun 28, 2015 10:23 am
by mpatronska
Hi,

I'm trying to make 2 motors move using Pololu DRV8835 Dual Motor Driver and Java, but it seems that I'm not setting correctly the pins, and it does not lead to movement of the wheels.

When using Pololu driver, GPIO 12 and 5 are used to control the speed and direction, respectively, of motor 1, and GPIO 13 and 6 control the speed and direction of motor 2.

This is the program:

Code: Select all

public class MovingRobot {

	public static void main(String[] args) {
		System.out.println("Started");
		
		Gpio.wiringPiSetup();
		
		GpioController gpio = GpioFactory.getInstance();
		GpioPinDigitalOutput output1 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05);
		GpioPinDigitalOutput output2 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06);
		
		SoftPwm.softPwmCreate(12, 0, 100);
		SoftPwm.softPwmCreate(13, 0, 100);
		
		SoftPwm.softPwmWrite(12, 25);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SoftPwm.softPwmWrite(13, 25);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SoftPwm.softPwmWrite(12, 50);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SoftPwm.softPwmWrite(13, 50);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SoftPwm.softPwmWrite(12, 100);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SoftPwm.softPwmWrite(13, 100);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SoftPwm.softPwmWrite(12, 0);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		SoftPwm.softPwmWrite(13, 0);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	
		System.out.println("Finished");
		
	}
}
I'm referring to https://github.com/pololu/drv8835-motor ... 835_rpi.py written in Python and http://javatutorial.net/raspberry-pi-co ... otor-speed

Does anyone see what is wrong with the code above?

Thanks.

Re: Control motors with Pololu DRV8835 Dual Motor Driver

Posted: Mon Jun 29, 2015 6:50 am
by mpatronska
Ok, I was not able to move the motors on Java using Pololu.
But I was able to move them using SN754410 motor driver.

This is the diagram: http://computers.tutsplus.com/tutorials ... -cms-20051

moves forwards for 1 second
stops for 1 second
moves backwards for 1 second
stops

Corresponding pins: http://pi4j.com/pins/model-2b-rev1.html

Program:

Code: Select all

public class Test {

	public static void main(String[] args) {
		System.out.println("starts");

		GpioController gpio = GpioFactory.getInstance();

		// left motor moves forwards
		GpioPinDigitalOutput gpio1 = gpio.provisionDigitalOutputPin(
				RaspiPin.GPIO_04, PinState.HIGH);
		GpioPinDigitalOutput gpio2 = gpio.provisionDigitalOutputPin(
				RaspiPin.GPIO_05, PinState.LOW);
		GpioPinDigitalOutput gpio3 = gpio.provisionDigitalOutputPin(
				RaspiPin.GPIO_06, PinState.HIGH);

		// right motor moves forwards
		GpioPinDigitalOutput gpio4 = gpio.provisionDigitalOutputPin(
				RaspiPin.GPIO_12, PinState.LOW);
		GpioPinDigitalOutput gpio5 = gpio.provisionDigitalOutputPin(
				RaspiPin.GPIO_13, PinState.HIGH);
		GpioPinDigitalOutput gpio6 = gpio.provisionDigitalOutputPin(
				RaspiPin.GPIO_14, PinState.HIGH);

		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		// stops
		gpio1.setState(PinState.LOW);
		gpio2.setState(PinState.LOW);
		gpio3.setState(PinState.LOW);
		gpio4.setState(PinState.LOW);
		gpio5.setState(PinState.LOW);
		gpio6.setState(PinState.LOW);
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		// left motor moves backwards
		gpio1.setState(PinState.LOW);
		gpio2.setState(PinState.HIGH);
		gpio3.setState(PinState.HIGH);
		
		// right motor moves backwards
		gpio4.setState(PinState.HIGH);
		gpio5.setState(PinState.LOW);
		gpio6.setState(PinState.HIGH);
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		// stops
		gpio1.setState(PinState.LOW);
		gpio2.setState(PinState.LOW);
		gpio3.setState(PinState.LOW);
		gpio4.setState(PinState.LOW);
		gpio5.setState(PinState.LOW);
		gpio6.setState(PinState.LOW);

		System.out.println("stops");
	}
}