Hello Everybody,
I’m new on this forum, but it’s been few months that i use Arduino and multiple products of Seeed but i always use simple things on projects. I’m an electrician and i love to work with Arduino, because we can create an own PCB and use Seeed products to connect it.
Till now, i searched and learned by myself without asking help, i made a pretty projects with arduino uno, mega and nano, but now i’m trying since 4-5 hours to find a solutions but i didn’t found it .
I bought 2x this products: Grove - 4-Channel SPDT Relay
You can check the picture:
Now i’ll try to tell you my problem, auso when i use the code given by the wiki to try 1x 4 relay with I²C it’s working and i tried to make with 2 x 4 Relay and it’s making working both together, but i want to make work indenpendly by giving them differents address, now on the wiki page below it’s giving us a code for changing the adress of 1x4Relay.
Now it’s what i tried step by step:
the first 4 Relay i will can A and the second one B
- I connected only A and not B
- Write this code give by wiki:
Multi_Channel_Relay relay;
void setup()
{
Serial.begin(9600);
while(!Serial);
/* Scan I2C device detect device address */
uint8_t old_address = relay.scanI2CDevice();
if((0x00 == old_address) || (0xff == old_address)) {
while(1);
}
Serial.println("Start write address");
relay.changeI2CAddress(old_address,0x2F); /* Set I2C address as 0x2f and save it to the EEPRom */
Serial.println("End write address");
/* Read firmware version */
Serial.print("firmware version: ");
Serial.print("0x");
Serial.print(relay.getFirmwareVersion(), HEX);
Serial.println();
}
void loop() {}
- Execute the code
- Disconnect the A and remove the USB
- I connected the B and i execute the code with different adress
- I disconnected the B
- Now i tried to connect both and write this code:
#include <multi_channel_relay.h>
Multi_Channel_Relay relay;
Multi_Channel_Relay relay2;
void setup()
{
Serial.begin(9600);
while(!Serial);
uint8_t old_address = relay.scanI2CDevice();
uint8_t old_address2 = relay2.scanI2CDevice();
if((0x00 == old_address) || (0xff == old_address) || (0x00 == old_address2) || (0xff == old_address2)) {
while(1);
}
Serial.println("Start write address");
relay.changeI2CAddress(old_address, 0x2F); /* Set I2C address and save to Flash */
relay.changeI2CAddress(old_address, 0x2D); /* Set I2C address and save to Flash */
Serial.println("End write address");
/* Read firmware version */
Serial.print("firmware version: ");
Serial.print("0x");
Serial.print(relay.getFirmwareVersion(), HEX);
Serial.println();
}
void loop()
{
Serial.println("Relay A / Channel 1 on");
relay.turn_on_channel(1);
delay(500);
Serial.println("Relay B / Channel 1 on");
relay.turn_off_channel(1);
relay2.turn_on_channel(1);
delay(500);
}
But since now it’s not working, maybe i learned something wrong or i made mistake and i would like to know if it’s possible to do like i said or i should use I²C multiplexer?
If you have question, i’m here to answer it.
I hope you understand me.
Thanks
Burak