Hy there again. I done some investigation and also connected two modules to re-program them. However, I learned that it does not save the addresses as I mentioned before. The only way is to do the following: you need t connect its VCC to digital output pins and use the below code. The code will then assign the addresses on start-up by switching the modules on as it program then. Open serial.print to see what is programmed. Code–GPIO 4 → TMAG #1 VCC
GPIO 5 → TMAG #2 VCC
GPIO 6 → TMAG #3 VCC
GPIO 7 → TMAG #4 VCC
GPIO 15 → TMAG #5 VCC
GPIO 16 → TMAG #6 VCC
GPIO 17 → TMAG #7 VCC
GPIO 18 → TMAG #8 VCC
GPIO 19 → TMAG #9 VCC
GPIO 20 → TMAG #10 VCC#include <Arduino.h>
#include <Wire.h>
// ============================================================
// ESP32-S3 I2C PINS
// ============================================================
#define SDA_PIN 8
#define SCL_PIN 9
// ============================================================
// TMAG5273 SENSOR POWER PINS
// One GPIO controls each sensor’s power
// ============================================================
const int sensorPowerPins[10] =
{
4,
5,
6,
7,
15,
16,
17,
18,
19,
20
};
// ============================================================
// TMAG5273 ADDRESSES
// ============================================================
// Factory address for TMAG5273A1/A2
#define TMAG_FACTORY_ADDRESS 0x35
// New addresses for sensors 1-10
const uint8_t sensorAddress[10] =
{
0x30,
0x31,
0x32,
0x33,
0x34,
0x36,
0x37,
0x38,
0x39,
0x3A
};
// ============================================================
// TMAG5273 REGISTERS
// ============================================================
#define TMAG_I2C_ADDRESS_REGISTER 0x0C
// ============================================================
// WRITE ONE BYTE TO TMAG5273
// ============================================================
bool writeRegister(uint8_t address, uint8_t reg, uint8_t value)
{
Wire.beginTransmission(address);
Wire.write(reg);
Wire.write(value);
uint8_t result = Wire.endTransmission();
return (result == 0);
}
// ============================================================
// CHECK IF DEVICE EXISTS
// ============================================================
bool deviceExists(uint8_t address)
{
Wire.beginTransmission(address);
return (Wire.endTransmission() == 0);
}
// ============================================================
// CHANGE TMAG5273 ADDRESS
// ============================================================
bool changeTMAGAddress(uint8_t newAddress)
{
/*
Register 0x0C:
Bits 7:1 = new 7-bit I2C address
Bit 0 = enable address update
Therefore:
newAddress << 1
OR
1
*/
uint8_t registerValue =
(newAddress << 1) | 0x01;
return writeRegister(
TMAG_FACTORY_ADDRESS,
TMAG_I2C_ADDRESS_REGISTER,
registerValue
);
}
// ============================================================
// POWER OFF ALL SENSORS
// ============================================================
void powerOffAllSensors()
{
Serial.println();
Serial.println(“Powering OFF all TMAG5273 sensors…”);
for (int i = 0; i < 10; i++)
{
digitalWrite(sensorPowerPins[i], LOW);
}
delay(100);
}
// ============================================================
// ASSIGN ALL 10 ADDRESSES
// ============================================================
bool setupAllTMAGs()
{
Serial.println();
Serial.println(“======================================”);
Serial.println(" TMAG5273 ADDRESS SETUP");
Serial.println(“======================================”);
// --------------------------------------------------------
// Start with every sensor OFF
// --------------------------------------------------------
powerOffAllSensors();
// --------------------------------------------------------
// Do sensors one at a time
// --------------------------------------------------------
for (int i = 0; i < 10; i++)
{
Serial.println();
Serial.print("Sensor #");
Serial.print(i + 1);
Serial.println();
// ----------------------------------------------------
// Turn ON this sensor
// ----------------------------------------------------
digitalWrite(
sensorPowerPins[i],
HIGH
);
// Give TMAG5273 time to start
delay(20);
// ----------------------------------------------------
// Check factory address
// ----------------------------------------------------
Serial.print("Checking factory address 0x");
Serial.println(
TMAG_FACTORY_ADDRESS,
HEX
);
if (!deviceExists(TMAG_FACTORY_ADDRESS))
{
Serial.println(
"ERROR: TMAG5273 not found!"
);
Serial.println(
"Check power, SDA and SCL."
);
return false;
}
Serial.println(
"TMAG5273 found."
);
// ----------------------------------------------------
// Assign new address
// ----------------------------------------------------
Serial.print("Changing address to 0x");
if (sensorAddress[i] < 0x10)
Serial.print("0");
Serial.println(
sensorAddress[i],
HEX
);
if (!changeTMAGAddress(sensorAddress[i]))
{
Serial.println(
"ERROR: Address change failed!"
);
return false;
}
delay(5);
// ----------------------------------------------------
// Verify new address
// ----------------------------------------------------
if (deviceExists(sensorAddress[i]))
{
Serial.print(
"SUCCESS: Sensor #"
);
Serial.print(i + 1);
Serial.print(
" = 0x"
);
Serial.println(
sensorAddress[i],
HEX
);
}
else
{
Serial.println(
"ERROR: New address not responding!"
);
return false;
}
// ----------------------------------------------------
// IMPORTANT:
//
// Leave this sensor powered ON.
//
// Its new address prevents it from responding to
// the factory address when the next sensor starts.
// ----------------------------------------------------
}
Serial.println();
Serial.println(
"======================================"
);
Serial.println(
"ALL 10 TMAG5273 SENSORS CONFIGURED!"
);
Serial.println(
"======================================"
);
return true;
}
// ============================================================
// SHOW ALL SENSOR ADDRESSES
// ============================================================
void scanTMAGs()
{
Serial.println();
Serial.println(
“Checking all 10 sensors…”
);
for (int i = 0; i < 10; i++)
{
Serial.print("Sensor #");
Serial.print(i + 1);
Serial.print(" Address 0x");
Serial.print(
sensorAddress[i],
HEX
);
Serial.print(" : ");
if (deviceExists(sensorAddress[i]))
{
Serial.println("OK");
}
else
{
Serial.println("NOT FOUND");
}
}
}
// ============================================================
// SETUP
// ============================================================
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println();
Serial.println();
Serial.println(
"ESP32-S3 TMAG5273 STARTUP"
);
// --------------------------------------------------------
// Power GPIOs
// --------------------------------------------------------
for (int i = 0; i < 10; i++)
{
pinMode(
sensorPowerPins[i],
OUTPUT
);
digitalWrite(
sensorPowerPins[i],
LOW
);
}
// --------------------------------------------------------
// Start I2C
// --------------------------------------------------------
Wire.begin(
SDA_PIN,
SCL_PIN
);
Wire.setClock(400000);
delay(100);
// --------------------------------------------------------
// Assign addresses
// --------------------------------------------------------
if (setupAllTMAGs())
{
scanTMAGs();
}
else
{
Serial.println();
Serial.println(
"TMAG5273 STARTUP FAILED!"
);
}
}
// ============================================================
// LOOP
// ============================================================
void loop()
{
// Nothing yet.
//
// The next step will be reading the
// 10 sensors and controlling the
// 10 servos.
delay(1000);
}




