I have four LED I2C boards daisy chained. They are custom I2C boards created by the engineer at my work. They use the PCA9532 LED dimmer. Each board has 12 LED's and I have been given an Arduino Mega 2560 to use as the master.
I have written a GUI to control these LED's manually and also with preset colours and this is all working fine.
The problem I have now is connecting to each slave at the same time. Most of what I have learned regarding I2C has been from this link from Nick..
My four slaves addresses are..
0x60
0x61
0x62
0x63
Connecting to each individually works fine and also I can connect to them all using a for loop.
The code below connects and turns on all slaves. However, the LED's seem to flicker when they are on, especially at the last slave the code gets to, slave 4. I think this is a timing thing and because the code is not getting to all slaves at once. When I test the code on each slave individually there is no problem.
For example:
void transmitToSlaves(byte PWM0_REGISTER, int PWM0_DATA, byte LS1_REGISTER, int rgGlobal, byte LS2_REGISTER, int bGlobal)
{
for(int i = 0; i < 4; i++)
{
//PWM0
Wire.beginTransmission(slaveArray[i]);
Wire.write(PWM0_REGISTER);
Wire.write(PWM0_DATA);
Wire.endTransmission();
//PWM1
Wire.beginTransmission(slaveArray[i]);
Wire.write(PWM1_REGISTER);
Wire.write(PWM1_DATA);
Wire.endTransmission();
//Red & Green & LS1
Wire.beginTransmission(slaveArray[i]);
Wire.write(LS1_REGISTER);
Wire.write(rgGlobal);
Wire.endTransmission();
//Blue
Wire.beginTransmission(slaveArray[i]);
Wire.write(LS2_REGISTER);
Wire.write(bGlobal);
Wire.endTransmission();
//LS0 selector
Wire.beginTransmission(slaveArray[i]);
Wire.write(0x06);
Wire.write(0x55);
Wire.endTransmission();
//LS3
Wire.beginTransmission(slaveArray[i]);
Wire.write(0x09);
Wire.write(0x15);
Wire.endTransmission();
}
}
I am trying to broadcast as mentioned in the link. As broadcasting is turned off by default and I am using the PCA9532 I am unsure how or even if its possible to turn this on using this.
So basically, I want to connect to all slaves at the same time but I don't know how to enable broadcasting on a PCA9532 using a Mega 2560 as the master.
Riva:
A quick look at the datasheet and I cannot see where the chip has the ability to receive broadcast instructions.
Yeah I don't think it is possible to do unfortunately.
I think for most things this wouldn't be a problem receiving the data one at a time but due to it being LED's it seems to interfere and cause the flickering of the lights.
Do you need all those being/end transactions? It might work if you just send everything in one batch.
I am trying to broadcast as mentioned in the link. As broadcasting is turned off by default and I am using the PCA9532 I am unsure how or even if its possible to turn this on using this.
Did you try broadcasting? If so please post your code.
You've ignored my suggestion to get rid of the multiple begin/end transactions. Does this work?
void transmitToSlaves(byte PWM0_REGISTER, int PWM0_DATA, byte LS1_REGISTER, int rgGlobal, byte LS2_REGISTER, int bGlobal)
{
for(int i = 0; i < 4; i++)
{
//PWM0
Wire.beginTransmission(slaveArray[i]); //Connects to one slave at a time.
Wire.write(PWM0_REGISTER); //Trying to see if I can enable broadcasting on slaves
Wire.write(PWM0_DATA); //to send code to all them at once.
//PWM1
Wire.write(PWM1_REGISTER);
Wire.write(PWM1_DATA);
//Red & Green & LS1
Wire.write(LS1_REGISTER);
Wire.write(rgGlobal);
//Blue
Wire.write(LS2_REGISTER);
Wire.write(bGlobal);
//LS0 selector
Wire.write(0x06);
Wire.write(0x55);
//LS3
Wire.write(0x09);
Wire.write(0x15);
Wire.endTransmission();
}
}
I don't see you attempting broadcasting in your code.