2-Channel Signal Relay Coding not making sense

Hi guys and girls,
I’m running a photon connected to your 2CH relay I2C board.
I’ve managed to get the libraries going as well as the basics of the code.
There seems to be an issue though with individual relay addressing.
Firstly you have to address the Port Register which makes no sense as there really is only one 0x01 based on the following code in your libraries as I’m using the output:

class I2CBZ{
    bool initialize(int directionReg);
    void buzzer(int command);
    int address = 0x41;
    int inputPortReg = 0x00;
    int outputPortReg = 0x01;
    int polarityInversionReg = 0x02;
    int gpioConfigReg = 0x03;

So Wire.write(0x01) – Supposed to address all outputs
writing Wire.write(0x01) again triggers relay 1 to HIGH
writing Wire.write(0x02) triggers relay 2 to HIGH (using either 0x01 or 0x02 as the port register)
So to this point I’m addressing each relay to turn on, no problem.
When following the rule, using 0x01 with 0x00 to turn relay back to LOW, both relays fall to LOW.
When using 0x02 with 0x00, nothing happens.
As a matter of interest I used 0x03 and all relays turn to HIGH,
how do I switch individual relays off one, at a time?

Thank you

The command to set the relay state controls all channels at once, if you break the byte into bits you can see what is happening by viewing the two lowest bits:

(both relays off) 0x00 - 00000000
(relay 1 on, 2 off) 0x01 - 00000001
(relay 2 on, 1 off) 0x02 - 00000010
(both relays on) 0x03 - 00000011

You cannot set the state of one relay at a time, so generally you would read the current status first and then adjust the value accordingly before setting it again.

The 0x02 register is the polarity inversion register, that is to say that it acts as a mask to reverse the bit control (or readout) of particular channels. Typically a set bit will turn the relay on, so when you write 0x01 the last two bits are 01, based on the normal polarity settings this means relay 1 is on, writing a 2 to the polarity register says you’d like to invert the second lowest bit, so now that bit will turn on the associated relay when it is cleared rather than set. If you wrote 0x03 to the polarity register, then sending 0x00 to register 0x01 would actually turn on both relays.

Hope this helps!