Hey guys,
I want to Drive led connected to ch0 of PCA9955B (LED driver) with 100% brightness or at least turn ON LED.I'm trying to use PCA9955B LED Driver with an I2C interface.I can't convince any meaningful output.
Connections made between led driver IC and the PI are:
LED driver Raspberry pi
SDA(27) SDA(GPIO 2)
SCL(26) SCL(GPIO 3)
VDD(28) 3.3V(GPIO 1)
GND(10,19,24) GND(GPIO39)
OE pin(5) with 10K resistor to GND(GPIO39)
RESET(25) with 10K resistor to 3.3V(GPIO 1)
REXT(1) GND
LED0(6) LED-
LED+(3.3V)
AD0,AD1,AD2 connected to GND So i am getting I2C address 70.
i am using following code but led not get ON
"use strict";
// PCA9955 test
const PCA9955 = require("../hardware/led_driver_pca9955b.js");
const I2C_CHANNEL = 1; // SDA1 & SCL1
const I2C_ADDR_PCA9955B = 0x70;
const ledDriver = new PCA9955(I2C_CHANNEL, I2C_ADDR_PCA9955B);
ledDriver.start(); // Initialize I2C communication
ledDriver.selectChannel(0);
ledDriver.setDuty(1.0); // 100% drive
Here is "../hardware/led_driver_pca9955b.js")
// PCA9955B (16ch I2C LED driver)
"use strict";
const rpio = require('rpio');
const raspi = require('raspi');
const i2c = require('i2c-bus');
const DEFAULT_BUS_NUMBER = 1;
const REG_ADDR_LEDOUT0 = 0x02;
const REG_ADDR_LEDOUT1 = 0x03;
const REG_ADDR_LEDOUT2 = 0x04;
const REG_ADDR_LEDOUT3 = 0x05;
const LED_COUNT = 16;
class PCA9955B {
/**
*
* <li-user uid="197964" login="Param"></li-user> {(number|i2c-bus)} i2c Number of I2C bus or i2c-bus object
* <li-user uid="197964" login="Param"></li-user> {!number} address Device address
*/
constructor (i2c, address) {
if (typeof(i2c)=="number") {
console.log("ADC channel is specified by bus number.");
if ( !(i2c == 1 || i2c == 2)) {
throw new Error("i2cBusNumber should be 1 or 2.");
}
this.i2cBusNumber = i2c;
} else if (i2c != null) {
this.i2c = i2c;
} else {
this.i2cBusNumber = DEFAULT_BUS_NUMBER;
}
this.leds = [];
for (let i=0; i<LED_COUNT; i++) {
this.leds.push(false)
}
this.address = address;
}
start () {
if (this.i2c == null) {
console.log("ADC channel opening: %d", this.i2cBusNumber);
this.i2c = i2c.openSync(this.i2cBusNumber); //i2c1 or i2c2
console.log("ADC channel opened: %d", this.i2cBusNumber);
}
}
// Call this to get ready for blank control (by OD pin)
setBlankControlMode () {
// Enable auto increment
this.i2c.i2cWriteSync(this.address, 2, Buffer.from([0x00, 0b10001001]));
this._writeRegisterSeqSameValues(0x18, 0xFF, 16); // Current value
}
/**
* On single channel
* <li-user uid="197964" login="Param"></li-user> {!number} ch Channel index
*/
selectChannel (ch) {
for (let i=0; i<LED_COUNT; i++) {
this.leds[i] = (ch == i);
}
this._applyLEDSelection();
}
/**
* On multiple channels
* <li-user uid="197964" login="Param"></li-user> {!number[]} chs Array of activated channels
*/
selectChannels (chs) {
for (let i=0; i<LED_COUNT; i++) {
this.leds[i] = false;
}
chs.forEach((ch)=>{
this.leds[ch] = true;
});
this._applyLEDSelection();
}
/**
* Set output gain control value for specified channel
* <li-user uid="197964" login="Param"></li-user> {!number} ch Traget channel (0 - 15)
* <li-user uid="197964" login="Param"></li-user> {!number} iref IREFn value (0 - 255)
*/
setIREF (ch, iref) {
if (ch < 0 || ch > 15) {
throw "Parameter ch should be within 0-15";
}
if (iref < 0 || iref > 255) {
throw "Parameter iref should be within 0-255";
}
const registerAddress = ch + 0x18;
this._writeRegisterSingle (registerAddress, iref);
}
/**
* On all channels
*/
onAll () {
for (let i=0; i<LED_COUNT; i++) {
this.leds[i] = true;
}
this._applyLEDSelection();
}
/**
* Off all channels
*/
offAll () {
for (let i=0; i<LED_COUNT; i++) {
this.leds[i] = false;
}
this._applyLEDSelection();
}
/**
* Set PWM duty
* <li-user uid="197964" login="Param"></li-user> {!number} val
*/
setDuty (val) {
if (this.useBlankPWM) {
this.blank.write(val);
}
}
off () {
this.offAll();
}
_writeRegisterSingle (regAddr, value) {
this.i2c.i2cWriteSync(this.address, 2, Buffer.from([regAddr, value]));
}
_writeRegisterSeq (startAddr, values) {
const firstVal = startAddr | (0b01 << 7);
let regValues = [firstVal].concat(values); // Auto-increment + First reg address
this.i2c.i2cWriteSync(this.address, regValues.length, Buffer.from(regValues));
}
_writeRegisterSeqSameValues (startAddr, value, count) {
const firstVal = startAddr | (0b01 << 7);
let regValues = [firstVal];
for (let i=0; i<count; i++) {
regValues.push(value);
}
this.i2c.i2cWriteSync(this.address, regValues.length, Buffer.from(regValues));
}
_applyLEDSelection () {
let regValues = [];
for (let groupIndex = 0; groupIndex < LED_COUNT/4; groupIndex++) {
let regVal = 0b00000000;
for (let i=0; i<4; i++) {
let modeVal = (this.leds[groupIndex * 4 + i]) ? 0b01 : 0b00;
regVal = regVal | (modeVal << (i*2));
}
regValues.push(regVal);
}
this._writeRegisterSeq(REG_ADDR_LEDOUT0, regValues);
}
}
module.exports = PCA9955B;
After running code i am not get any output.
Thanks