I have five identical DS2401 unique ID chips attached to an Arduino, and I wish to read the serial number from each consecutively into RAM so that I can send the data over serial.
I have each one initialised separately, so that I can call the code to retrieve the serial number with ds24_0.getSerialNumber(), ds24_1.getSerialNumber() etc.
If I were to build these into a for loop, how do I get the code to call ds24_i, where i is the loop iteration number? Am I going about this the wrong way?
OneWire oneWire_0(10);
DS2401 ds24_0(&oneWire_0);
OneWire oneWire_1(A0);
DS2401 ds24_1(&oneWire_1);
OneWire oneWire_2(A1);
DS2401 ds24_2(&oneWire_2);
OneWire oneWire_3(A2);
DS2401 ds24_3(&oneWire_3);
OneWire oneWire_4(A3);
DS2401 ds24_4(&oneWire_4);
//snip
void idRequest()
{
uint8_t serialNumber[5][6];
uint8_t result[5];
result[0] = ds24_0.init(); //how do I loop this
result[1] = ds24_1.init();
result[2] = ds24_2.init();
result[3] = ds24_3.init();
result[4] = ds24_4.init();
if(result[0] == DS2401_SUCCESS)
{
ds24_0.getSerialNumber(serialNumber[0]); //how do I loop this also?
}
else if(result[0] == DS2401_CRC_FAIL || DS2401_NOT_DS2401 || DS2401_NO_WIRE)
{
for (uint8_t i = 0; i < 6; i++)
{
serialNumber[0][i] = 0;
}
}
//assemble packet here
}
Thanks!
ds24_0and so on? Where are they defined?