Go Down

Topic: 1-Wire scanner for e.g. DS18B20 (Read 4127 times) previous topic - next topic

robtillaart

Jul 04, 2015, 11:27 am Last Edit: Jul 12, 2015, 07:31 pm by robtillaart
inspired by http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html -
I wrote a small sketch that scans all pins for 1 Wire devices.

The generator writes a small code snippet that can be used in other sketches.
Code: [Select]
//
//    FILE: oneWireSearch.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.04
// PURPOSE: scan for 1-Wire devices + code snippet generator
//    DATE: 2015-june-30
//     URL: http://forum.arduino.cc/index.php?topic=333923
//
// inspired by http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
//
// Released to the public domain
//
// 0.1.00 initial version
// 0.1.01 first published version
// 0.1.02 small output changes
// 0.1.03 added more explicit range
// 0.1.04 added CRC check

// UNO 2..20
// MEGA and others have different range
const int startPin = 2;
const int endPin = 20;

#include <OneWire.h>

void setup()
{
  Serial.begin(115200);
  Serial.println("//\n// Start oneWireSearch.ino \n//");

  for (uint8_t pin = startPin; pin < endPin; pin++)
  {
    findDevices(pin);
  }
  Serial.println("\n//\n// End oneWireSearch.ino \n//");
}

void loop()
{
}

uint8_t findDevices(int pin)
{
  OneWire ow(pin);

  uint8_t address[8];
  uint8_t count = 0;


  if (ow.search(address))
  {
    Serial.print("\nuint8_t pin");
    Serial.print(pin, DEC);
    Serial.println("[][8] = {");
    {
      count++;
      Serial.println("  {");
      for (uint8_t i = 0; i < 8; i++)
      {
        Serial.print("0x");
        if (address[i] < 0x10) Serial.print("0");
        Serial.print(address[i], HEX);
        if (i < 7) Serial.print(", ");
      }
      Serial.print("  },");
      // CHECK CRC
      if (ow.crc8(address, 7) == address[7])
      {
        Serial.println("\t\t// CRC OK");
      }
      else
      {
        Serial.println("\t\t// CRC FAILED");
      }
    } while (ow.search(address));

    Serial.println("};");
    Serial.print("// nr devices found: ");
    Serial.println(count);
  }

  return count;
}


As always remarks, improvements etc are welcome
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

latest version now on github - https://github.com/RobTillaart/Arduino/tree/master/sketches/oneWireSearch

0.1.02 : some small changes in output format
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

latest version now on github - https://github.com/RobTillaart/Arduino/tree/master/sketches/oneWireSearch

0.1.03 added more explicit range
0.1.04 added CRC check

updated code in first post to latest version
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

HarvdL

Why is my DS18B20 smoking with every Sketch
It will be in fire when i let it go!


robtillaart

Why is my DS18B20 smoking with every Sketch
It will be in fire when i let it go!
Often a sign of wrong connection (swapped pin 1 & 3)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

HarvdL

checked over and over but will just turn it on the board.
see if they get damaged after they have been used wrong!

Turned and now it works fine.

The misleading ( human ) is the "half round "    , looking at the screen .ws "bottom view "
 

Have seem simular reading on the tpm35 that wiring at "some devices " should be the other way :)


Thanks

Harry

robtillaart

Good part is that these DS18's are tough, even after getting so hot it still works.

There is also some magic in it, connected in one way it takes the heat in (measure it)
connected the other way it puts heat out (although not controllable over 1 wire ;)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

bricoleurs

Hello please help,

I can`t load the sketch into my ESP-WROOM.
failure info says "Please define I/O register types here"

what canI do?

Thanks

PaulS

Quote
I can`t load the sketch
"the" sketch? Silly to assume that there is only ONE Arduino sketch that you could possibly be talking about.

Quote
into my ESP-WROOM.
Your what?

Quote
failure info says "Please define I/O register types here"
Let's see. The process of getting a program onto the Arduino (or wanna-be) involves an editor, and IDE doing some magic, a compiler, a linker, and avrdude. No "failure" in that list. So, you need to be very specific when doing all that hand-waving.

Quote
what canI do?
Panic.
The art of getting good answers lies in asking good questions.

Jardal

Hi, this scanner have some problem - it does not show more than 8 devices on the bus.

Configuration

Master - ESP8266/160MHz
Slave1 - DS18B20
Slave2 - Arduino NANO 328 with OneWireHub example DS18B20_asinterface extended to 9 devices (OneWireHubTest show 8 devices too)

But 8 devices are listed as maximum.

Quote
--- hold RESET on the Slave NANO board

// Start oneWireSearch.ino
//

uint8_t pin5[][8] = {
  {
0x28, 0x0F, 0x03, 0x77, 0x91, 0x01, 0xC2, 0x6B  }, // CRC OK
};
// nr devices found: 1

//
// End oneWireSearch.ino
//


---- after booting NANO board


// Start oneWireSearch.ino
//

uint8_t pin5[][8] = {
  {
0x28, 0x00, 0x55, 0x44, 0x33, 0x22, 0x11, 0x1E  }, // CRC OK
  {
0x28, 0x04, 0x55, 0x44, 0x33, 0x22, 0x11, 0xC2  }, // CRC OK
  {
0x28, 0x02, 0x55, 0x44, 0x33, 0x22, 0x11, 0x70  }, // CRC OK
  {
0x28, 0x06, 0x55, 0x44, 0x33, 0x22, 0x11, 0xAC  }, // CRC OK
  {
0x28, 0x01, 0x55, 0x44, 0x33, 0x22, 0x11, 0x29  }, // CRC OK
  {
0x28, 0x05, 0x55, 0x44, 0x33, 0x22, 0x11, 0xF5  }, // CRC OK
  {
0x28, 0x03, 0x55, 0x44, 0x33, 0x22, 0x11, 0x47  }, // CRC OK
  {
0x28, 0x07, 0x55, 0x44, 0x33, 0x22, 0x11, 0x9B  }, // CRC OK
};
// nr devices found: 8

//
// End oneWireSearch.ino
//
Devices are listed only from Slave2, another problem could be in the code of the OneWireHub library (maybe unwanted last_device flag on the 1W bus - but bus not analyzed).

Go Up