multi sensore 18b20

Hello,
I am working to create a code that can read the temperature of several sensors 18b20 connected on different pins.
This is the code:

#include <OneWire.h>
//----------n sensori---indirizzo---zona------
byte IndirizzoSensori[3][8][3]; //qui memorizzo fino a 10 indirizzi in massimo 5 rone diverse
byte numeroSensoriInRete; // variabile usata per tenere traccia del numero di sensori riconosciuti in totale sui vari pin
OneWire pinBusSensori[] = {26, 27,28}; // inizializza il bus onewire sulla porta n°8 (se avete collegato i sensori su un'altro pin dovete modificare qui)

float GetTemp(OneWire *, byte *);
void PrintAddress(byte *);
void lookUpSensors();
int CheckSensor(byte *);

byte memoria[(sizeof(pinBusSensori)/8)+1];

void setup(void) {
  Serial.begin(9600);// inizializza la porta seriale a 9600
  numeroSensoriInRete = 0;    // imposta a 0 il numero di sensori attualmente riconosciuti
  lookUpSensors(); // avvia la ricerca delle sonde di temperatura
}

void lookUpSensors() {
  byte sensorAddress[8]; // questo array conterrà l'indirizzo locale dei sensori
  for (int i = 0; i < sizeof(pinBusSensori)/12; i++) {
    while (pinBusSensori[i].search(sensorAddress)) {
      if (sensorAddress[0] == 0x10 || sensorAddress[0] == 0x28) {
        if (CheckSensor(sensorAddress) == 1) { //crc ok
          PrintAddress(sensorAddress);
          for (int aa = 0; aa < 8; aa++) IndirizzoSensori[numeroSensoriInRete][aa][i] = sensorAddress[aa]; // copia l'indirizzo
          numeroSensoriInRete++;
        }
      }
    }//end while
    memoria[i]=numeroSensoriInRete;
    Serial.println("");
    numeroSensoriInRete=0;
  }
}


void loop() {
  float temperatura; // uso questa variabile per tenere la lettura della temperatura
for (int z = 0; z < sizeof(pinBusSensori)/12; z++) {
  for (int x = 0; x < memoria[z]; x++) {
    temperatura=GetTemp(&IndirizzoSensori[x][0][z], z); // lego la temperatura
    Serial.print(" -> ");
    Serial.println(temperatura);      
  }
}
  delay(10000); // aspetto 5 secondi prima di fare una nuova misurazione
}



float GetTemp(byte * addr, byte indice)
{
 
  Serial.print("addr = ");
  Serial.print(addr[0],HEX);
  Serial.print("-");
  Serial.print(addr[1],HEX);
  Serial.print("-");
  Serial.print(addr[2],HEX);
  Serial.print("-");
  Serial.print(addr[3],HEX);
  Serial.print("-");
  Serial.print(addr[4],HEX);
  Serial.print("-");
  Serial.print(addr[5],HEX);
  Serial.print("-");
  Serial.print(addr[6],HEX);
  Serial.print("-");
  Serial.println(addr[7],HEX);
  
  
  
  byte present = 0;
  byte data[12];
  byte address[8];
  for (byte i = 0; i < 8; i++) address[i] = *(addr + i); //copia l'indirizzo nella stringa locale
  pinBusSensori[indice].reset();
  pinBusSensori[indice].select(addr);
  pinBusSensori[indice].write(0x44, 1);        // start conversion, with parasite power on at the end
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  present = pinBusSensori[indice].reset();
  pinBusSensori[indice].select(addr);
  pinBusSensori[indice].write(0xBE);         // Read Scratchpad

  for (byte i = 0; i < 9; i++) data[i] = pinBusSensori[indice].read();// we need 9 bytes //Serial.print(data[i], HEX);

  int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;

  double result;

  LowByte = data[0];
  HighByte = data[1];

  TReading = (HighByte << 8) + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit

  if (SignBit) TReading = (TReading ^ 0xffff) + 1; // 2's comp // negative

  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  Whole = Tc_100 / 100;  // separate off the whole and fractional portions
  Fract = Tc_100 % 100;

  result = Whole;
  result += ((double)Fract / 100);

  if (SignBit) result *= -1;

  return result;

}



int CheckSensor(byte * address)
{
  if (OneWire::crc8(address, 7) != *(address + 7)) return (-1); // faccio il controllo del CRC8, se fallito ritorno -1
  else return (1); // cr8 OK, ritorno 1
}



void PrintAddress(byte * address)
{
  int i;
  for (i = 0; i < 8; i++)
  {
    if (address[i] < 9) Serial.print("0");
    Serial.print(address[i], HEX);
    if (i < 7) Serial.print("-");
  }
}

When the code is started checks every pin, if find a sensor, stores the address in the array "IndirizzoSensori [3] [8] [3]."
The array in three dimensions stored in the first index number of sensor, in the second index the address of the sensor and finally in the third index is stored the pin. I checked and the storage procedure is successful.
My problem is this: in the "getTemp" I have to copy the address of the sensor to control the temperature, but when I point the address to control takes a error.
This is what I get from the monitor. I have 3 sensors on three different pin:

28-A3-1E-FF-05-00-00-1B
28-D5-F2-FD-05-00-00-CD
28-79-A-FF-05-00-00-73

addr = 28-28-28-A3-D5-79-1E-F2

addr = 28-28-A3-D5-79-1E-F2-A

addr = 28-A3-D5-79-1E-F2-A-FF

The first three addresses are the real ones of the sensors. They are stored correctly, other addresses are what reads the function.

Someone can help me solve this problem?

adamo:
I am working to create a code that can read the temperature of several sensors 18b20 connected on different pins.

It sounds like a futile attempt at re-inventing the wheel at the expense of ignoring one of the best assets the device offers - the ability to work on one wire.

It is even futile as just an intellectual exercise, as it has been done before. You might find some help here

I can't remember what the rationale is for doing it this way but I did use it for a while, as a result of making some stupid mistake with the standard one-wire system. As I recall it, you have to tell the programme where to look for the sensors, but the sensor addresses aren't needed.

Thank You.
I'll start studying from this link.
Anyway if anyone has any ideas, I accept it with a smile.