Difference between revisions of "DockerPi Motor Board(A) SKU: EP-0108"

From 52Pi Wiki
Jump to navigation Jump to search
(Official Compatibility Test)
(Official Compatibility Test)
 
Line 32: Line 32:
 
|Raspberry Pi All Platform|| √ ||Not Include CM Series & EOL Platform
 
|Raspberry Pi All Platform|| √ ||Not Include CM Series & EOL Platform
 
|-
 
|-
|Banana Pi M3 || √ || Python 3 & Modify DEVICE_BUS to 2
 
 
|}
 
|}
  

Latest revision as of 14:55, 11 September 2019

DockerPi Motor Board(A)

Description

DockerPi Motor Board(A)-6.jpg

DockerPi Motor Board(A) is a DockerPi series expansion board.It can control two 12V DC motors. It can be used in Raspberry Pi.You could communicate with it by opening I2C. it also can be stacked with other DockerPi expansion board. DockerPi Motor Board(A) has dozens of modes.You can develop it as you like. You could choose single motor,of course,you could control both of them at the same time. If you need to run for a long time ,we recommend that you use our DockerPi Power expansion board to provide more power.

Note: DockerPi Motor Board does not support hot plug.

Features

DockerPi Motor Board(A)-1.jpg
  • DockerPi Series
  • Programmable
  • Control directly(without programming)
  • Extend GPIO Pins
  • Two DC 12V motors
  • Selective control
  • Can stack with other stack board
  • Independent of the mainboard hardware (require I2C support)

Official Compatibility Test

Not only support the following development boards, other development boards can be compatible if they have I2C peripherals. (Note: some software changes may be required)

Platform DockerPi Motor Board Notes
Raspberry Pi All Platform Not Include CM Series & EOL Platform

Motor Board Details

DockerPi Motor Board(A)-10.jpg


Gallery

DockerPi Motor Board(A)-8.jpg
DockerPi Motor Board(A)-2.jpg
DockerPi Motor Board(A)-3.jpg
DockerPi Motor Board(A)-7.jpg
DockerPi Motor Board(A)-5.jpg
DockerPi Motor Board(A)-4.jpg

Package Includes

  • 1 x Motor Board
  • 2 x DC Motor
  • 2 x PH Connector
  • 1 x Instruction
  • 4 x M2.5*12 + 6 Copper stick
  • 4 x M2.5*6 Nut
  • 4 x M2.5*6 Half-round head screw
DockerPi Motor Board(A)-9.jpg


Register Map

Register Address Function Value
0x01 Set Motor A Speed or Set Motor A PWM Set Motor A Speed Low 8 bit or Set Motor A PWM Low 8 bit
0x02 Set Motor A Speed or Set Motor A PWM Set Motor A Speed High 7 bit or Set Motor A PWM High 7 bit
0x03 Set Motor B Speed or Set Motor B PWM Set Motor B Speed Low 8 bit or Set Motor B PWM Low 8 bit
0x04 Set Motor B Speed or Set Motor B PWM Set Motor B Speed High 7 bit or Set Motor B PWM High 7 bit
0x05 Set Motor A Count Set Motor A Count Low 8 bit
0x06 Set Motor A Count Set Motor A Count High 8 bit
0x07 Set Motor B Count Set Motor B Count Low 8 bit
0x08 Set Motor B Count Set Motor B Count High 8 bit
0x09 Set status of Direction Set Motor A and Motor B's Direction
0x0A Now Motor A Speed Now Motor A Speed Low 8 bit
0x0B Now Motor A Speed Now Motor A Speed High 8 bit
0x0C Now Motor B Speed Now Motor B Speed Low 8 bit
0x0D Now Motor B Speed Now Motor B Speed High 8 bit
0x0E Now Motor A Count Now Motor A Count Low 8 bit
0x0F Now Motor A Count Now Motor A Count High 8 bit
0x10 Now Motor B Count Now Motor B Count Low 8 bit
0x11 Now Motor B Count Now Motor B Count High 8 bit
0x12 Now status of Direction Current status of Direction
0x13 Enable Enable data write
0x14 Alignment Set the way to align
0x15 Loop MotorA Circle Low 8 bit
0x16 Loop MotorA Circle range from 8 to 15 bit
0x17 Loop MotorA Circle range from 16 to 23 bit
0x18 Loop MotorA Circle High 8 bit
0x19 Loop MotorB Circle Low 8 bit
0x1a Loop MotorB Circle ranges from 8 to 15 bit
0x1b Loop MotorB Circle ranges from 16 to 23 bit
0x1c Loop MotorB Circle High 8 bit
0x1d PWM MotorA PWM Low 8 bit
0x1e PWM MotorA PWM High 8 bit
0x1f PWM MotorB PWM Low 8 bit
0x20 PWM MotorB PWM High 8 bit
STATUS_REG 0x02
Default Value 0/1 0 0 0 0 0 0 0
Description PWM MODEL/SPEED MODEL SET VALUE
STATUS_REG 0x04
Default Value 0/1 0 0 0 0 0 0 0
Description PWM MODEL/SPEED MODEL SET VALUE
STATUS_REG 0x09
Default Value 0 0 0 0 0 0 0 0
Description Reserved Reserved Reserved Reserved Reserved Reserved CCW
STATUS_REG 0x12
Default Value 0 0 0 0 0 0 0 0
Description Reserved Reserved Reserved Reserved Reserved Reserved CCW
STATUS_REG 0x14
Default Value 0 0 0 0 0 0 0 0
Decription Reserved Reserved Reserved Reserved Reserved Reserved Reserved Motor2

Specification

Note:You need to notice the power supply is lower than 17V and higher than 12V.

  • Automatically turn on speed alignment mode in PWM mode.That is the PWM of MotorA follows the PWM of the MotorB.
 The value of PWM ranges from 0 to 1200.
 The value of speed ranges from 100 to 1300.
  • The register of 0x09 could set the MotorA and MotorB's status of direction.
 When the value is 0x00,the MotorA and MotorB are CCW.
 When the value is 0x01,the MotorA is CW,MotorB is CCW.
 When the value is 0x02,the MotorA is CCW,MotorB is CW.
 When the value is 0x03,the MotorA is CCW,MotorB is CCW.
  • The register of 0x13 is the enable bit
  • The register of 0x14 could set the Model of alignment

It won't automatically return to the default value, it will keep the last state when you start it.

 When the value is 0x00,the PWM of MotorA follows the PWM of the MotorB.
 When the value is 0x01,the PWM of MotorB follows the PWM of the MotorA.
  • The parameters of Motor
 Power supply voltage:VM = 15 V(MAX)
 Output current:Iout = 1.2 A(ave)/3.2 A(peak)
 Standby(power save)system
 CW/CCW/short break/stop function modes
  • We recommand you to buy our power board.So,you don't have to worry about the power.

Moreover,you need be careful to connect the Power Board.The Power Board is under the Motor Board.

  • When you set the value of register ,don't forget to set the value of 0x13.
  • If your motors are connected properly and the power is on properly,the red LED on the motor will light up.

Mechanical Drawing

DockerPi Motor Board(A).png


Configuring I2C(Raspberry Pi)

Run sudo raspi-config and follow the prompts to install i2c support for the ARM core and linux kernel
Go to Interfacing Options

Raspi-config-1.png

then I2C

Raspi-config-2.png

Enable!

Raspi-config-3.png

Done!

Raspi-config-4.png

Direct control wtihout programming(Raspberry Pi)

  • Please do not set the value of register 0x13 more than 254,otherwise,it dosen't work.
  • Set MotorA's speed of low 8 bits
i2cset -y 1 0x18 0x01 100
i2cset -y 1 0x18 0x13 100
  • Set MotorA's speed of high 8 bits
i2cset -y 1 0x18 0x02 100
i2cset -y 1 0x18 0x13 100
  • Set MotorA's count of low 8 bits
i2cset -y 1 0x18 0x05 100
i2cset -y 1 0x18 0x13 100
  • Set MotorA's count of high 8 bits
i2cset -y 1 0x18 0x06 100
i2cset -y 1 0x18 0x13 100
  • Set MotorA and MotorB's direction
i2cset -y 1 0x18 0x09 1
i2cset -y 1 0x18 0x13 100
  • Query current MotorA's speed of low 8 bits
i2cget -y 1 0x18 0x0a
  • Query current MotorA's speed of high 8 bits
i2cget -y 1 0x18 0x0b
  • Query current MotorA's count of low 8 bits
i2cget -y 1 0x18 0x0e
  • Query current MotorA's count of high 8 bits
i2cget -y 1 0x18 0x0f
  • Query current MotorA and MotorB's direction
i2cget -y 1 0x18 0x12

Simple Test

  • Create a file and name it test.py,paste following codes and running.The phenomenon you see is that the motor accelerates to the maximum value first, then decelerates to the minimum value.
import smbus
import sys
import time

MOTOR_DRIVER_ADDRESS = 0x18
MOTOR_DRIVER_BUS = 1
MOTOR_DRIVER_SPEED_A_L = 0x01
MOTOR_DRIVER_SPEED_A_H = 0x02
MOTOR_DRIVER_ENABLE = 0x13

bus = smbus.SMBus(MOTOR_DRIVER_BUS)

print("Please set the value range from 100 to 1300")
MOTOR_DRIVER_SPEED_SET_A = (int)(input("Set the speed of MOTOR_DRIVER_A:"))
while(MOTOR_DRIVER_SPEED_SET_A < 1300):
	MOTOR_DRIVER_SPEED_SET_A += 1
	time.sleep(0.01)
	bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_A_H,(MOTOR_DRIVER_SPEED_SET_A >> 8))  
	bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_A_L,(MOTOR_DRIVER_SPEED_SET_A & 0xff))
	bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_ENABLE,0x10)

if(MOTOR_DRIVER_SPEED_SET_A == 1300):
	print("The speed is max")
time.sleep(1)

while(MOTOR_DRIVER_SPEED_SET_A > 0):
	MOTOR_DRIVER_SPEED_SET_A -= 1
	time.sleep(0.01)
	bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_A_H,(MOTOR_DRIVER_SPEED_SET_A >> 8))  
	bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_A_L,(MOTOR_DRIVER_SPEED_SET_A & 0xff))
	bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_ENABLE,0x10)

if(MOTOR_DRIVER_SPEED_SET_A == 0):
	bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_A_L,0)		
	print("The speed is min")

Program in language C(Raspberrry Pi)

  • Create a new file named:Motor.c and paste following codes:
#include <stdio.h>
#include <stdint.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>

//MOTOR_DRIVER Address
#define DEVICE_ARRD 0x18

//Set the speed value of MOTOR_DRIVER
#define MOTOR_DRIVER_SPEED_SET_A 500
#define MOTOR_DRIVER_SPEED_SET_B 1000

//Set the status of MOTOR_DRIVER
#define MOTOR_DRIVER_DIRECTION_STATUS 0x01

//The functions of MOTOR_DRIVER
#define MOTOR_DRIVER_SPEED_A_L 0x01
#define MOTOR_DRIVER_SPEED_A_H 0x02
#define MOTOR_DRIVER_SPEED_B_L 0x03
#define MOTOR_DRIVER_SPEED_B_H 0x04
#define MOTOR_DRIVER_COUNT_A_L 0x05
#define MOTOR_DRIVER_COUNT_A_H 0x06
#define MOTOR_DRIVER_COUNT_B_L 0x07
#define MOTOR_DRIVER_COUNT_B_H 0x08
#define MOTOR_DRIVER_DIRECTION 0x09
#define MOTOR_DRIVER_SPEED_NOW_A_L 0x0a
#define MOTOR_DRIVER_SPEED_NOW_A_H 0x0b
#define MOTOR_DRIVER_SPEED_NOW_B_L 0x0c
#define MOTOR_DRIVER_SPEED_NOW_B_H 0x0d
#define MOTOR_DRIVER_COUNT_NOW_A_L 0x0e	
#define MOTOR_DRIVER_COUNT_NOW_A_H 0x0f
#define MOTOR_DRIVER_COUNT_NOW_B_L 0x10
#define MOTOR_DRIVER_COUNT_NOW_B_H 0x11
#define MOTOR_DRIVER_DIRECTION_NOW 0x12
#define MOTOR_DRIVER_ENABLE 0x13

int main(void)
{
	int device_addr;
	int i = 0;
	device_addr = wiringPiI2CSetup(DEVICE_ARRD);
	
	if (device_addr < 0)
		printf("Extend board Can not be initialized, please enable I2C and try again!\n", device_addr);
	
	if (MOTOR_DRIVER_SPEED_SET_A <= 255)
		printf("Now the speed of MOTOR_DRIVER_A is: %d\n" ,(int)(wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_SPEED_A_L)));
	else
		printf("Now the speed of MOTOR_DRIVER_A is: %d\n" ,(int)((wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_SPEED_NOW_A_H) << 8 | wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_SPEED_A_L))));
	if (MOTOR_DRIVER_SPEED_SET_B <= 255)
		printf("Now the speed of MOTOR_DRIVER_B is: %d\n" ,(int)(wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_SPEED_B_L)));
	else
		printf("Now the speed of MOTOR_DRIVER_B is: %d\n" ,(int)((wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_SPEED_NOW_B_H) << 8 | wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_SPEED_B_L))));
	
	if (((wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_DIRECTION_NOW) & 0x01) == 0x01))
		printf("Now the direction of MOTOR_DRIVER_A is:CW\n");
	else
		printf("Now the direction of MOTOR_DRIVER_A is:CCW\n");
	
	if (((wiringPiI2CReadReg8(device_addr,MOTOR_DRIVER_DIRECTION_NOW) & 0x02) == 0x02))
		printf("Now the direction of MOTOR_DRIVER_B is:CW\n");
	else
		printf("Now the direction of MOTOR_DRIVER_B is:CCW\n");

	wiringPiI2CWriteReg8(device_addr,MOTOR_DRIVER_SPEED_A_L,(MOTOR_DRIVER_SPEED_SET_A & 0xff));
	wiringPiI2CWriteReg8(device_addr,MOTOR_DRIVER_SPEED_A_H,(MOTOR_DRIVER_SPEED_SET_A >> 8));
	wiringPiI2CWriteReg8(device_addr,MOTOR_DRIVER_SPEED_B_L,(MOTOR_DRIVER_SPEED_SET_B & 0xff));
	wiringPiI2CWriteReg8(device_addr,MOTOR_DRIVER_SPEED_B_H,(MOTOR_DRIVER_SPEED_SET_B >> 8));
	wiringPiI2CWriteReg8(device_addr,MOTOR_DRIVER_ENABLE,DEVICE_ARRD);	
}

Compile!

gcc Motor.c -lwiringPi -o Motor

Exec It!

./Motor

Progarm in language Python(Raspberry Pi)

  • Create a new file named:Motor.py and paste following codes:
import time as t
import smbus
import sys

#MOTOR_DRIVER Address

MOTOR_DRIVER_ADDRESS = 0x18
MOTOR_DRIVER_BUS = 1

#Set the speed value of MOTOR_DRIVER
MOTOR_DRIVER_SPEED_SET_A = (int)(input("Set the speed of MOTOR_DRIVER_A:"))
MOTOR_DRIVER_SPEED_SET_B = (int)(input("Set the speed of MOTOR_DRIVER_B:"))

MOTOR_DRIVER_SPEED_A_L = 0x01
MOTOR_DRIVER_SPEED_A_H = 0x02
MOTOR_DRIVER_SPEED_B_L = 0x03
MOTOR_DRIVER_SPEED_B_H = 0x04
MOTOR_DRIVER_COUNT_A_L = 0x05
MOTOR_DRIVER_COUNT_A_H = 0x06
MOTOR_DRIVER_COUNT_B_L = 0x07
MOTOR_DRIVER_COUNT_B_H = 0x08
MOTOR_DRIVER_DIRECTION = 0x09
MOTOR_DRIVER_SPEED_NOW_A_L = 0x0a
MOTOR_DRIVER_SPEED_NOW_A_H = 0x0b
MOTOR_DRIVER_SPEED_NOW_B_L = 0x0c
MOTOR_DRIVER_SPEED_NOW_B_H = 0x0d
MOTOR_DRIVER_COUNT_NOW_A_L = 0x0e
MOTOR_DRIVER_COUNT_NOW_A_H = 0x0f
MOTOR_DRIVER_COUNT_NOW_B_L = 0x10
MOTOR_DRIVER_COUNT_NOW_B_H = 0x11
MOTOR_DRIVER_DIRECTION_NOW = 0x12
MOTOR_DRIVER_ENABLE = 0x13

bus = smbus.SMBus(MOTOR_DRIVER_BUS)

if MOTOR_DRIVER_SPEED_SET_A <= 255 :
    print("Now the speed of MOTOR_DRIVER_A is:" ,bus.read_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_NOW_A_L))
else :
    print("Now the speed of MOTOR_DRIVER_A is:" ,((bus.read_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_NOW_A_H)) << 8) | bus.read_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_NOW_A_L))
    
if MOTOR_DRIVER_SPEED_SET_B <= 255 :
    print("Now the speed of MOTOR_DRIVER_B is:" ,bus.read_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_NOW_B_L))
else :
    print("Now the speed of MOTOR_DRIVER_B is:" ,((bus.read_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_NOW_B_H)) << 8) | bus.read_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_NOW_B_L))

bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_A_H,(MOTOR_DRIVER_SPEED_SET_A >> 8))  
bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_A_L,(MOTOR_DRIVER_SPEED_SET_A & 0xff))
bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_B_L,(MOTOR_DRIVER_SPEED_SET_B & 0xff))
bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_SPEED_B_H,(MOTOR_DRIVER_SPEED_SET_B >> 8))
bus.write_byte_data(MOTOR_DRIVER_ADDRESS,MOTOR_DRIVER_ENABLE,0x10)

Execute it !

python3 Motor.py

Progarm in language java(Raspberry Pi)

  • Create a new file named:Motor.java and paste following codes:
import java.io.IOException;
import java.util.Arrays;

import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException;
import com.pi4j.platform.PlatformAlreadyAssignedException;
import com.pi4j.util.Console;

public class Motor {
	
	//MOTOR_DRIVER Address
	public static final int DOCKERPI_MOTORDRIVER_BOARD = 0x18;
	
	public static final byte MOTOR_DRIVER_DIRECTION_STATUS_1 = (byte) 0x00;
	public static final byte MOTOR_DRIVER_DIRECTION_STATUS_2 = (byte) 0x01;
	public static final byte MOTOR_DRIVER_DIRECTION_STATUS_3 = (byte) 0x02;
	public static final byte MOTOR_DRIVER_DIRECTION_STATUS_4 = (byte) 0x04;
	
	//Set the speed value of MOTOR_DRIVER
	public static final int MOTOR_DRIVER_SPEED_SET_A = 500;
	public static final int MOTOR_DRIVER_SPEED_SET_B = 1000;
	//Set the status of MOTOR_DRIVER_DIRECTION
	public static final byte MOTOR_DRIVER_DIRECTION_STATUS = (byte) 0x01;
	
	//Set the count value of MOTOR_DRIVER
	public static final int MOTOR_DRIVER_COUNT_SET_A = 500;
	public static final int MOTOR_DRIVER_COUNT_SET_B = 1000;
	
	//Motordriver functions
	public static final byte MOTOR_DRIVER_SPEED_A_L = (byte) 0x01;
	public static final byte MOTOR_DRIVER_SPEED_A_H = (byte) 0x02;
	public static final byte MOTOR_DRIVER_SPEED_B_L = (byte) 0x03;
	public static final byte MOTOR_DRIVER_SPEED_B_H = (byte) 0x04;
	public static final byte MOTOR_DRIVER_COUNT_A_L = (byte) 0x05;
	public static final byte MOTOR_DRIVER_COUNT_A_H = (byte) 0x06;
	public static final byte MOTOR_DRIVER_COUNT_B_L = (byte) 0x07;
	public static final byte MOTOR_DRIVER_COUNT_B_H = (byte) 0x08;
	
	public static final byte MOTOR_DRIVER_DIRECTION = (byte) 0x09;
	
	public static final byte MOTOR_DRIVER_SPEED_NOW_A_L = (byte) 0x0a;
	public static final byte MOTOR_DRIVER_SPEED_NOW_A_H = (byte) 0x0b;
	public static final byte MOTOR_DRIVER_SPEED_NOW_B_L = (byte) 0x0c;
	public static final byte MOTOR_DRIVER_SPEED_NOW_B_H = (byte) 0x0d;
	
	public static final byte MOTOR_DRIVER_COUNT_NOW_A_L = (byte) 0x0e;
	
	public static final byte MOTOR_DRIVER_COUNT_NOW_A_H = (byte) 0x0f;
	public static final byte MOTOR_DRIVER_COUNT_NOW_B_L = (byte) 0x10;
	public static final byte MOTOR_DRIVER_COUNT_NOW_B_H = (byte) 0x11;
	public static final byte MOTOR_DRIVER_DIRECTION_NOW = (byte) 0x12;
	public static final byte MOTOR_DRIVER_ENABLE = (byte) 0x13;
	
	
	public static void main(String[] args)
			throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException {
			

				final Console console = new Console();
				
				I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1);
				I2CDevice device = i2c.getDevice(DOCKERPI_MOTORDRIVER_BOARD);	
				
				if (MOTOR_DRIVER_SPEED_SET_A <= 255)
					console.println("Now the speed of MOTOR_DRIVER_A is:" + (device.read(MOTOR_DRIVER_SPEED_NOW_A_L)));
				else
					console.println("Now the speed of MOTOR_DRIVER_A is:" + (device.read(MOTOR_DRIVER_SPEED_NOW_A_L) | (device.read(MOTOR_DRIVER_SPEED_NOW_A_H) << 8)));
				
				//device.write(MOTOR_DRIVER_DIRECTION,(byte)0x01);
				
				//device.write(MOTOR_DRIVER_COUNT_A_L,(byte)((MOTOR_DRIVER_COUNT_SET_A_L) & 0xff));
				//device.write(MOTOR_DRIVER_COUNT_A_H,(byte)(MOTOR_DRIVER_COUNT_SET_A_H >> 8));
				
				if (MOTOR_DRIVER_SPEED_SET_B <= 255)
					console.println("Now the speed of MOTOR_DRIVER_B is:" + device.read(MOTOR_DRIVER_SPEED_NOW_B_L));
				else
					console.println("Now the speed of MOTOR_DRIVER_B is:" + (device.read(MOTOR_DRIVER_SPEED_NOW_B_L) | (device.read(MOTOR_DRIVER_SPEED_NOW_B_H) << 8)));
				
				if ((device.read(MOTOR_DRIVER_DIRECTION_NOW) & 0x01) == 0x01)
					console.println("Now the direction of MOTOR_DRIVER_A is:CW");
				else
					console.println("Now the direction of MOTOR_DRIVER_A is:CCW");
				
				if ((device.read(MOTOR_DRIVER_DIRECTION_NOW) & 0x02) == 0x02)
					console.println("Now the direction of MOTOR_DRIVER_B is:CW");
				else
					console.println("Now the direction of MOTOR_DRIVER_B is:CCW");                                                                                                                                                                                                                                                                                                                             
				
				device.write(MOTOR_DRIVER_DIRECTION,MOTOR_DRIVER_DIRECTION_STATUS);
				device.write(MOTOR_DRIVER_SPEED_B_L,(byte)((MOTOR_DRIVER_SPEED_SET_B) & 0xff));
				device.write(MOTOR_DRIVER_SPEED_B_H,(byte)(MOTOR_DRIVER_SPEED_SET_B >> 8));
				
				device.write(MOTOR_DRIVER_SPEED_A_L,(byte)((MOTOR_DRIVER_SPEED_SET_A) & 0xff));
				device.write(MOTOR_DRIVER_SPEED_A_H,(byte)(MOTOR_DRIVER_SPEED_SET_A >> 8));

				device.write(MOTOR_DRIVER_ENABLE,(byte)0x02);
			}
}
  • Compile it and running:
javac Motor.java -classpath .:classes:/opt/pi4j/lib/'*' 
sudo java -classpath .:classes:/opt/pi4j/lib/'*' Motor

FAQ

  • Q: If i set some value of register address,but the Motor has no response,what can i do for it?
 A: Firstly,please check the power supply port.
    Secondly,you need to check whether you open I2C.
    Thirdly,you may not set the value of register address :"0x13" and "0x09"


  • Q: If i directly control it without programming,when i finish setting the value,but the motor doesn't work.
 A: Please try to set the value of register 0x13 again.

Typical Application

Keywords

Motor,DockerPi,Hat,Stack