By looking at the datasheet, it work more similar to a 74HC595. Use shiftOut(dataPin, clock, LSBFIRST, data); Set the chip for 8 bits mode ... pin 4 of the chip set LOW / GND. ( page 4 ) You can connect in series a set of those chips, the first data will go to the first chip, and the last data to the last chip.( page 23 ) And you may need a "strobe" pulse ... after all the data is send. ( page 15 )
Try to do a test circuit on a breadboard using one chip, and see what the data from 0x00 to 0xFF do. And with two or more chips, do re-code that generated a strobe pulse from the clock signal.
Let call it ... A Hello World for this particular chip.
Anyway, test and see what happen. I dont have that chip at the moment, so I wont be able to test it myself.
PS : I look at your schematic, do not match the datasheet ( from page 20 )
You show the I2C lines with a series resistor in it, why is this?
Yes the I2C needs resistors attached to them, but these are pull up resistors, that is from the the I2C line to the supply voltage of the chips you are driving.
Look ok to me for the data signal as a strobe signal ( page 10 ) Before the for () function, do this
digitalWrite(clk, LOW); // put the clock signal low
digitalWrite(SIG_DI,LOW);
delayMicrosecond(12);
for (int i = 0; i <5; i++) // Produce 5 strobe signal as page 10 of the datasheet
{
digitalWrite(SIG_DI,HIGH);
delayMicroseconds(5);
digitalWrite(SIG_DI,LOW);
delayMicroseconds(5);
}
digitalWrite(clk, HIGH);
As for the lenght of the pulse, I am having a hard time to find that info on the datasheet. Some info is not well explain. ( Never mind ...Page 9)
If I got that chip at hand, I will do a test code, but I dont have it at hand.
As for testing, do the schematic at the bottom of page 21.
If I have that chip at hand, that will be my "Hello world" code. I will follow the schematic on page 21 of the datasheet.
byte data_pin = 10; // Any pins will do except 0,1 and 13
byte clock_pin = 8;
void setup()
{
pinMode(data_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
digitalWrite(data_pin, LOW);
digitalWrite(clk_pin, LOW);
}
void loop()
{
for (byte chip_data =0;chip_data<255,chip_data++)
{
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data);
// if two chip is series, data will be send to the first chip
// add lines per chip
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data);
// the strobe signal if 2 or more chip is use
digitalWrite(clk, LOW); // put the clock signal low
digitalWrite(data_pin,LOW);
delayMicrosecond(12);
for (int i = 0; i <5; i++) // Produce 5 strobe signal as page 10 of the datasheet
{
digitalWrite(data_pin,HIGH);
delayMicroseconds(5);
digitalWrite(data_pin,LOW);
delayMicroseconds(5);
}
digitalWrite(clk, HIGH);
}
}
Anyway, something like that. But I dont have the chip, so that code is not tested or compile.
According to the data sheet's AC characteristics table it is 100nS high and the same low for one chip, With an additional 1nS for each chip you have chained. So there is no way you can go too fast on an Arduino Uno.
@Grumpy_Mike
I don't understand what you're saying. Can you talk to me easily?
@sergetechone
Thank you very much for your interest.
According to the datasheet,
R(8bit PWM) G(8bit PWM) B(8bit PWM) + strobe signal
The stobe signal in your code makes sense.
By the way, is it correct that the expression of the three data for R, G, and B is reflected in the above source code?
To comply with the data sheet you do need 5 strobe pulses.
Normally a strobe pulse means just one pulse that is the output of a HIGH followed by the output of a LOW. If it is a negative strobe it is the other way round output a LOW followed by a HIGH.
Then there is the problem of how long the signal has to be in this first state before restoring the original state. The data sheet tells you this has to be a minimum of 100 nS (nano seconds or ten to the minus nine of a second. To ensure the pulse was long enough the original code added a 5uS (micro or ten to the minus six of a second) both before and after the pulse.
The Arduino only runs at 16MHz that is a clock time of 1 / 16x10^6 which is 62.5 nS.
Note the ^ symbol means "to the power of"
The clock time is how long the processor takes to execute one instruction.
In fact it takes about 4.5 uS to execute all the instructions you need to do a digital write.
So you will see this is many, many times slower than the minimum pulse width your chip needs. Therefore you will not require any extra delays so the code you require to produce this sequence of pulses, but you will need a delay before the chip is ready to receive the strobe pulses.
digitalWrite(clk, LOW);
delayMicroseconds(10); // because Twss time is 10uS per chip for two chips make this 20uS delay
for (int i = 0; i <5; i++) // Produce 5 strobe signal as page 10 of the data sheet
{
digitalWrite(data_pin,HIGH);
digitalWrite(data_pin,LOW);
}
digitalWrite(clk, HIGH);
}
Let me figure this out ... 0 mean 0 % and 255 mean 100 % duty cycle. OK got it.
So the code for two chip will be ...
byte data_pin = 10; // Any pins will do except 0,1 and 13
byte clock_pin = 8;
void setup()
{
pinMode(data_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
digitalWrite(data_pin, LOW);
digitalWrite(clk_pin, LOW);
}
void loop()
{
for (byte chip_data =0;chip_data<255,chip_data++)
{
// sending data to chip one
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data); // Red
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data); // Green
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data); // Blue
// Sending data to chip two
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data); // Red
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data); // Green
shiftOut(data_pin, clock_pin, MSBFIRST, chip_data); // Blue
// The strobe signal sequence
digitalWrite(clk, LOW); // put the clock signal low
digitalWrite(data_pin,LOW);
delayMicrosecond(12);
for (int i = 0; i <5; i++) // Produce 5 strobe signal as page 10 of the datasheet
{
digitalWrite(data_pin,HIGH);
delayMicroseconds(5);
digitalWrite(data_pin,LOW);
delayMicroseconds(5);
}
digitalWrite(clk, HIGH);
}
}
The order sequence for the RGB could be wrong. Again, I dont have the chip to test the code.
Anyway, the code should do .. going from 0 % to 255 % equaly for the Red, Green and Blue. color
Although I understand why 13 was added to the list, that was only for old Arduinos. This was because an LED was attached to the pin, and in some circumstances caused a bit of a voltage drop on that pin which occasional caused trouble with fast pulses.
But modern ones have a buffer before that pin and so there is no problem using it.