Advertise here

Adafruit PWM driver I2C and SAMD21 Xplained pro

Adafruit PWM driver I2C and SAMD21 Xplained pro




if you are looking to expand your I/O ports and control multi LED or Servo motor , so you need to use something similar to Adafruit PWM driver , based on PCA9685 I2C chip 




in this quick tutorial I will show you how to control this breakout using SAMD21 Xplained pro 

you need first to take a look at adafruit article about this part from here


connection : 




PA08 >>> SDA
PA09 >>> SCL
VCC  >>>  VCC
GND >>> GND


And you need to connect V+ to positive power supply "you need an external power supply"



code instruction : 


void PCA9685_begin();

to start I2C communication


void PCA9685_reset();


reset the chip registers.


void PCA9685_setPWMFreq(float freq);


set the PWM frequency where


freq :frequency in Hz ( 40 - 1600)

void PCA9685_setPWM(uint8_t num, uint16_t on, uint16_t off);

set the channel PWM value where :

num: channel number (0 - 15 )
on : high pulse value ( 0-4095 )
off : low pulse value ( 0-4095 )

void PCA9685_write(uint8_t addr, uint8_t data);

write I2C message to PCA9685 ,Where:

addr: adress of the register
data : from 0 - 255


uint8_t PCA9685_read(uint8_t addr);


read a byte from PCA9685 

I used atmel start to setup the I2C and serial port configuration for this project , I used Master synchronous driver for this project.



simple code :



set the channel 1 with duty cycle of 50% and frequency of 1000 Hz



open the serial monitor to see the result and set the buadrate on 115200



second code :

control 4 Servo motors , connected from Channel 0 - 3 and rotate each motor from 0 > 180 degree and then go back to 0




open the serial monitor to see the result and set the buadrate on 115200




and this video will show you the results





 High speed + I2C Mode 

this part can run using SCL up to 1MHz , so I tested it out and it works fine to me , if you are looking to use higher clk speed like that you can use this code, it must give you the same results.



3 comments:

Powered by Blogger.