PCA9685 for Speed Direction Motors

Introduction

The Speed Direction driver for the PCA9685 is used in conjunction with an H-bridge IC (integrated circuit) and some inversion logic, or just a breakout board featuring the control, like the Sunfounder motor driver. A speed channel of the PCA regulates the speed of the motor and whether it is operating at all while the direction channel is controlling the polarity of the motor. The direction channel is handled digitally, that means it always has a direction determined, so the only way to make the motor stand still is to set the speed to 0.


Driver Parameters

The PCA9685 driver for speed direction motor control has three parameters that need to be configured:

I2C Address

This is the address the device is being referenced by on the I2C bus. The base I2C address is

  • Binary: 1000000

  • Hex: 0x40

The last 6 bits are altered by the address A0-A5 pins:

A5 A4 A3 A2 A1 A0

1 0 0 0 0 0 0

So as an example if we set all pins to 1 we have

  • Binary: 1111111

  • Hex: 0x7f

The device has a “can all“ address, which is 0x70, so the I2C scan is going to report two addresses usually: the one selected with the A pins and 0x70.

More information about addressing can be found in the datasheet

Also for translation help see the Binary to Hex converter here

Speed Channel

The speed channel is driving the speed with a pulse width modulated signal. It is either connected to the enable signal of an H-Bridge or the dedicated pin of a breakout board.

Direction Channel

The direction channel is controlling the polarity of the motor. It is either connected to one in pin of an H-Bridge with an inverted signal connected to the other in pin or to a dedicated pin on a breakout board.


Wiring

Attached are the pinout of the PCA9685 IC and of a generic H-Bridge.

The PCA9685 can be found in either a DIP socket adapter or in popular development boards as shown below

Development Board

 

Chip Pinout

We can use the two widely used H-Bridge ICs like the L293D from multiple suppliers and the SN754410 from Texas Instruments and some inversion logic, like a not gate. Their pinout can be seen below:

L293D

Some important facts about the H-Bridge:

  • all 0V (GND) pins should be connected, since they also dissipate the heat from the chip

  • pin 16 (+V) should be at 5V to provide proper functionality while pin 8 (+Vmotor) can be anything between 3.5V and 12V

 

Or we can use a board that already features the inversion and just offers the speed direction pins broken out to us, like the Sunfounder motor driver.

Example

The PCA9685 is connected to 5V and GND from the circuit and to the Builder Base via I2C with the SDA pins connected to each other and the SCL pins connected to each other. Two output channels of the PCA9685 are connected to an H-Bridge to control the speed and direction of the motor connected to the H-Bridge. The speed pin is connected to the enable signal while the direction channel and its inversion are connected to the in pins. We see that there is a switch, that can either switch our motor voltage to the 5V output of the Builder Base or to anything we want to supply with the barrel jack (3.5V - 12V).

Breadboard 

Schematic

Used Pins

Used Pins

Description

Used Pins

Description

 5V

The voltage level for the assembly

GND

The ground potential for the assembly

SDA

The I2C data line

SCL

The I2C clock line


How to write an App

Navigate to the App Builder and create a new application. You can find the “Motor” code object under the “Hardware” Tab in the object drop down menu on the left, or you can also use the search bar.

 

 

 

 

 

Drag the “Motor” object onto the grid.

 

Next, under the interface tab, locate the switch, slider percent, and slider analog interface objects. Next, drag two of the switch objects, a slider percent object, and slider analog object onto the grid.

 

 

 

 

 

Finally, connect a switch object to each the clockwise and counter clockwise ports on the motor object, connect the slider percent object to the speed port, and the Slider Analog to the Joystick Axle. For the sake of organization, label each of the interface objects, and save your application.

 


How to create a firmware

Navigate to the Firmware Builder and create a new firmware file.

Click the “+ Add Hardware” button and listed under the “Actuators” tab find the “Motor” hardware option.

Give your device a name, and click “Add Device”

 

 

 

Next, select the “PCA-9685 Speed Dir” under the driver dropdown menu.

 

 

For this example we select:

  • I2C Address: 0x40

  • DC 1 Pin: 1

  • DC 2 Pin: 2

You may now save your firmware file and upload it to one of your clients.

 

 

 


Supported Hardware

  • PCA-9685

  • Motors

  • Servos

  • Other Actuators


Downloads

Apps

Firmware

Assets