Question about send() from wire library. (and delay())


I have a question about why something doesn't work in a way. (other ways do work)

What I want to do is to control 8 leds with an I²C-bus (PCF8574). But to do some animations, I want to use the delay function.

when I write something like this:


Wire.send(12); //lights up these two leds: 0 0 X X 0 0 0 0 delay(1000); Wire.send(3); // lights up first two leds: X X 0 0 0 0 0 0 delay(1000);


Now the purpose is that the leds flicker with a period of 1000 ms. But the following is observed:

the first two leds light up (X X 0 0 0 0 0 0 ) and with a period of two seconds, the two other leds (0 0 X X 0 0 0 0) flash vaguely and very short.

Originally, I wanted to do something with a while loop and that didn't work, and I reduced the problem to this piece of code. And when I don't write those delays, all four leds ligt up and are thus flashing very fast (which is good) the delays are causing the problem I think.

Yet, it works perfectly fine if I write this:

Wire.beginTransmission(0x38); Wire.send(12); Wire.endTransmission(); Wire.beginTransmission(0x38); Wire.send(3); Wire.endTransmission();

But it feels so wrong and useless to write for every bite that begin condition, adress, end condition,....

Anyone got an Idea?

(also I wrote (dirty programming) a library of my own before I knew the purpose of the Wire library in which I use normal digital outputs as clock and data lines and with that, the delays are no problem. Only with the Wire library, but I guess the Wire library is the best since it was made for serial things, so I should learn to use that one.)

Thank you very much!

The device you are talking to doesn't know that you are done talking to it until you use the endTransmission() method to tell it that you are. So, the device doesn't properly process the data.

If it makes you feel better, put the beginTransmission(), send(), and endTransmission() calls in a function. Call that function whenever you need to send a byte to the device.