[SOLVED] Hex index

I am using this code to get the addresses of the sensors.

// Programa : Scan DS18B20
// Alterações : Arduino e Cia
// Este programa procura pelos sensores no circuito e mostra o valor 
// do endereço físico de cada sensor no Serial Monitor

#include <OneWire.h>

// Conecte o pino central dos sensores ao pino 10 do Arduino
OneWire  ds(2);  

void setup(void) 
{
  Serial.begin(9600);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) 
{
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  Serial.print("Procurando dispositivos DS18B20...\n\r");

  while(ds.search(addr)) 
  {
    Serial.print("\n\rEncontrado sensor \'DS18B20\' com endereco:\n\r");
    for( i = 0; i < 8; i++) 
    {
      Serial.print("0x");
       if (addr[i] < 16) 
       {
        Serial.print('0');

       }
      Serial.print(addr[i], HEX);

       if (i < 7) 
       {
        Serial.print(", ");
       }

    }

    if ( OneWire::crc8( addr, 7) != addr[7]) 
    {
        Serial.print("CRC nao e valido!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rFinal da verificacao.\r\n");
  ds.reset_search();
  return;
}

void loop(void) 
{
  // Loop Vazio
}

This is the return.

Encontrado sensor 'DS18B20' com endereco:

0x28, 0xAC, 0x0A, 0x38, 0x05, 0x00, 0x00, 0xE3

Encontrado sensor 'DS18B20' com endereco:

0x28, 0x5D, 0x67, 0x38, 0x05, 0x00, 0x00, 0x5B

Encontrado sensor 'DS18B20' com endereco:

0x28, 0xFD, 0xF5, 0x2D, 0x07, 0x00, 0x00, 0xC5

Encontrado sensor 'DS18B20' com endereco:

0x28, 0x33, 0x6B, 0x38, 0x05, 0x00, 0x00, 0xAA

Encontrado sensor 'DS18B20' com endereco:

0x28, 0xFF, 0x7C, 0x61, 0x92, 0x15, 0x01, 0x31

Encontrado sensor 'DS18B20' com endereco:

0x28, 0xFF, 0x65, 0xA1, 0x92, 0x15, 0x01, 0x87

Encontrado sensor 'DS18B20' com endereco:

0x28, 0xFF, 0x55, 0x65, 0x92, 0x15, 0x01, 0x34

Encontrado sensor 'DS18B20' com endereco:

0x28, 0xFF, 0xD5, 0x64, 0x92, 0x15, 0x01, 0x70

Encontrado sensor 'DS18B20' com endereco:

0x28, 0xFF, 0xB5, 0x6E, 0x92, 0x15, 0x01, 0x7A

My question...
That determines sequence is used? Hex determines the sequence?
Even if I change the place of sensor, the sequence remains the same.

Thanks for all.

eduardodallmann:
Even if I change the place of sensor, the sequence remains the same.

Why would you think that changing the physical location of the sensor would change its internally programmed address?

I don't understand your question. What sequence are you talking about? Those are addresses of your sensors, you use these addresses to select which device you want to communicate with.

I recommend you use this library: GitHub - milesburton/Arduino-Temperature-Control-Library: Arduino Temperature Library

The DS18B20 ROM addresses are found in numerical order but the bit sequence is found starting in the low order bit of each byte. I explain this in message #1 of DS1822: How does the program assign the sensor's index? - Programming Questions - Arduino Forum
The physical order of the devices on the bus doesn't alter their rom address, so the scan will always print them in the same order.

Pete

el_supremo:
The DS18B20 ROM addresses are found in numerical order but the bit sequence is found starting in the low order bit of each byte. I explain this in message #1 of DS1822: How does the program assign the sensor's index? - Programming Questions - Arduino Forum
The physical order of the devices on the bus doesn't alter their rom address, so the scan will always print them in the same order.

Pete

I understand your explanation. But note the sequence of my arduino and my calculations. Unless I failed conversions.

28 AC A 38 5 0 0 E3
28 5D 67 38 5 0 0 5B
28 FD F5 2D 7 0 0 C5
28 33 6B 38 5 0 0 AA
28 FF 7C 61 92 15 1 31
28 FF 65 A1 92 15 1 87


   normal    reversed 
AC=10101100  00110101=35
5D=1011101   1011101 =5D
FD=11111101  10111111=BF
33=110011    110011  =33   //// This should be the first?

I wrote a sketch which uses your 9 addresses. It prints them normally and then the bit reversed version. It prints this:

28 AC 0A 38 05 00 00 E3  -> 14 35 50 1C A0 00 00 C7 
28 5D 67 38 05 00 00 5B  -> 14 BA E6 1C A0 00 00 DA 
28 FD F5 2D 07 00 00 C5  -> 14 BF AF B4 E0 00 00 A3 
28 33 6B 38 05 00 00 AA  -> 14 CC D6 1C A0 00 00 55 
28 FF 7C 61 92 15 01 31  -> 14 FF 3E 86 49 A8 80 8C 
28 FF 65 A1 92 15 01 87  -> 14 FF A6 85 49 A8 80 E1 
28 FF 55 65 92 15 01 34  -> 14 FF AA A6 49 A8 80 2C 
28 FF D5 64 92 15 01 70  -> 14 FF AB 26 49 A8 80 0E 
28 FF B5 6E 92 15 01 7A  -> 14 FF AD 76 49 A8 80 5E

You can see that the bit reversed addresses are in numerical order.

Here's the code:

// See http://forum.arduino.cc/index.php?topic=401711.0
// Print a list of DS18B20 ROM addresses in bit-reversed order

unsigned char rom_addresses[9][8] = {
  {0x28, 0xAC, 0x0A, 0x38, 0x05, 0x00, 0x00, 0xE3},
  {0x28, 0x5D, 0x67, 0x38, 0x05, 0x00, 0x00, 0x5B},
  {0x28, 0xFD, 0xF5, 0x2D, 0x07, 0x00, 0x00, 0xC5},
  {0x28, 0x33, 0x6B, 0x38, 0x05, 0x00, 0x00, 0xAA},
  {0x28, 0xFF, 0x7C, 0x61, 0x92, 0x15, 0x01, 0x31},
  {0x28, 0xFF, 0x65, 0xA1, 0x92, 0x15, 0x01, 0x87},
  {0x28, 0xFF, 0x55, 0x65, 0x92, 0x15, 0x01, 0x34},
  {0x28, 0xFF, 0xD5, 0x64, 0x92, 0x15, 0x01, 0x70},
  {0x28, 0xFF, 0xB5, 0x6E, 0x92, 0x15, 0x01, 0x7A},
};

void print_hex_byte(unsigned char c)
{
  if(c < 16)Serial.print("0");
  Serial.print(c,HEX);
  Serial.print(" ");
}

unsigned char bit_reverse(unsigned char c)
{
  unsigned char out = 0;
  for(int i = 0;i < 8;i++) {
    out >>= 1;
    if(c & 0x80)out |= 0x80;
    c <<= 1;
  }
  return out;
}

void setup()
{
  Serial.begin(9600);
  while(!Serial);
  delay(1000);

  for(int i = 0;i < 9;i++) {
    for(int j = 0;j < 8;j++) {
      print_hex_byte(rom_addresses[i][j]);
    }
    Serial.print(" -> ");
    for(int j = 0;j < 8;j++) {
      print_hex_byte(bit_reverse(rom_addresses[i][j]));
    }
    Serial.println();
  }
}

void loop()
{

}

Pete

Thanks, that helps me alot, you can mark as resolved.

eduardodallmann:
Thanks, that helps me alot, you can mark as resolved.

Actually, you do that, by editing the subject title.