A little bit of work stemming from from the soil temperature monitoring project; this is an aside on DS18B20 temperature sensing device address discovery with the Arduino. Being that I am going to have a handful of sensors in the ground and therefore not easily accessible for identification I need to find a way of easily finding out all the device addresses in one fell swoop.

Arduino - Device Address Discovery

As already discussed in Soil Temperature Monitoring - Part One connecting the DS18B20 to an Arduino is trivial; ground, positive and data are all that is required, with data to the Arduino digital pin 3. Pull up is achieved with a 4K7.

DS18B20 Basic Circuit

Simple circuit employed for address discovery

Below is a sample of the code I used to discover the sensor addresses.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 #include <OneWire.h>
 #define ONE_WIRE_BUS 3

 OneWire  oneWire(ONE_WIRE_BUS);

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

 void loop() {}

 void discover(void) {
   byte i;
   byte data[12];
   byte addr[8];

   Serial.print("Starting...\n\r");
   while(oneWire.search(addr)) {
     Serial.print("\n\r\n\rDevice has address:\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 is not valid!\n\r");
       return;
     }
   }
   Serial.println();
   Serial.print("Done");
   oneWire.reset_search();
   return;
 }

This is what it looked like with five sensors attached:

Starting...

Device has address: 0x28, 0xC8, 0xCC, 0xBF, 0x04, 0x00, 0x00, 0xB6
Device has address: 0x28, 0xBA, 0x17, 0xD0, 0x04, 0x00, 0x00, 0x64
Device has address: 0x28, 0xF5, 0xE4, 0x83, 0x05, 0x00, 0x00, 0x26
Device has address: 0x28, 0xE3, 0x67, 0xCE, 0x04, 0x00, 0x00, 0x9C
Device has address: 0x28, 0xE7, 0x17, 0x11, 0x05, 0x00, 0x00, 0x1D

Done

Now it will just be a process of elimination to find out which sensor matches which address.


Comments

comments powered by Disqus