I am trying to change the I2C address on a qwiic relay, SparkFun Qwiic Single Relay COM-15093 using the example program Example6_Change_I2C_Address.ino. Here is the console output which says it changed but when I call the i2c scanner it still shows the default address of 0x18. I am using the qwiic relay library v 1.2.0 w arduino ide 1.8.10
18:15:43.091 → Scanning…
18:15:43.091 → I2C device found at address 0x18 !
18:15:43.091 → done
18:15:43.091 →
18:15:43.091 → Ready to flip some switches.
18:15:43.138 → Address changed successfully.
18:15:45.132 → Scanning…
18:15:45.132 → I2C device found at address 0x18 !
18:15:45.132 → done
18:15:45.132 →
/*
This example code demonstrates how to change the address of the Single or
Quad Qwiic Relay to one of your choosing. There is a set range of available
addresses from 0x07 to 0x78, so make sure your chosen address falls within
this range. The next thing to note is that when you change the address you'll
need to call an instance of the Qwiic_Relay class that includes your new
address: "Qwiic_Relay relay(YOUR_NEW_ADDRESS_HERE);" so that the new address
is fed to all the available functions. Finally if for some reason you've
forgotten your new address. No big deal, load up the I2C scanner example code
and find out where your product's address is at.
By: Elias Santistevan
SparkFun Electronics
Date: July 2019
License: This code is public domain but you buy me a beer if you use
this and we meet someday (Beerware license).
*/
#include <Wire.h>
#include "SparkFun_Qwiic_Relay.h"
// All available product addresses labeled below. Close the onboard jumpers if
// you want to access the alternate addresses.
#define SINGLE_DEFAULT_ADDR 0x18 // Alternate jumper address 0x19
//#define QUAD_DEFAULT_ADDR 0x6D // Alternate jumper address 0x6C
#define NEW_ADDR 0x19
// After changing the address you'll need to apply that address to a new
// instance of the Qwiic_Relay class: "Qwiic_Relay relay(YOUR_NEW_ADDRESS_HERE)".
Qwiic_Relay relay(SINGLE_DEFAULT_ADDR); // Change to Single Relay Address if using Quad Relay
void setup()
{
Wire.begin();
Serial.begin(115200);
I2Cscanner();
// Let's see.....
if(relay.begin())
Serial.println("Ready to flip some switches.");
else
Serial.println("Check connections to Qwiic Relay.");
// There is a not so limited but still limited range of
// addresses that are available to you 0x07 -> 0x78.
if(relay.changeAddress(NEW_ADDR)) // Put the address you want here.
Serial.println("Address changed successfully.");
else
Serial.println("Address change failed...");
delay(2000);
I2Cscanner();
}
void loop()
{
}
void I2Cscanner()
{
byte error, address;
byte nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
}