PCA9685 Port Expander

The PCA9685 is a 16 channel, 12 bit PWM controller. It's commonly used for driving servo motors.

// Call at boot time
var i2c = new I2C();
i2c.setup({sda:D27,scl:D28}); // use the I2C pins you're using here
var pwm = require("PCA9685").connect(i2c,{addr:0b1011000, callback:function() {
  // it's now initialised
  pwm.setPWMFreq(60); // 60Hz frequency
  pwm.writeMs(0, 1.5); // write a 1.5ms pulse to the servo on channel 1
}});

Reference

// Write to I2C
PCA9685.prototype.w = function (r, d) { ... }

// Read from I2C
PCA9685.prototype.r = function (r) { ... }

// Reset the PCA9685
PCA9685.prototype.reset = function (callback) { ... }

// Send raw PWM values to the pin (values 0..4096)
PCA9685.prototype.setRAW = function (num, on, off) { ... }

// Write a PWM value 0..1 to the pin
PCA9685.prototype.write = function (num, val) { ... }

// Write to a pin such that PWM is produced with the given pulse length
PCA9685.prototype.writeMs = function (num, len) { ... }

// Set the PWM frequency in Hz
PCA9685.prototype.setPWMFreq = function (freq) { ... }

/* Create an instance of PCA9685. Supply an I2C device.
options = {
  addr : optional I2C address (default is 0x40)
  callback : optional callback when initialised
}
*/
exports.connect = function (i2c, options) { ... }

Using

(No tutorials are available yet)

Buying

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.