Go Down

Topic: 1Wire Onewire scanner (Read 2923 times) previous topic - next topic

Artouste

Dec 20, 2012, 01:41 pm Last Edit: Aug 25, 2014, 02:03 pm by Artouste Reason: 1
bonjour à tous
ça ne casse pas trois pattes à un canard  :smiley-mr-green:
mais ça peut etre utile à certains avec un bus 1W onewire
testé avec ce que j'avais rapidement dispo sous la main
l'ajout éventuel  de code famille est facile

Code: [Select]
#include <OneWire.h>
// Onewire lib is here http://www.pjrc.com/teensy/td_libs_OneWire.html

OneWire  ds(8);  // on pin 8 here, don't forget 4.7K resistor between +5V and DQ pin
void setup(void) {
  Serial.begin(9600);
}

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

  if ( !ds.search(addr)) {
    Serial.println("--------------");
    Serial.println(".");
    Serial.println(".");
    Serial.println("END OF SCAN.");


    Serial.println(".");
    Serial.println();

    ds.reset_search();
    delay(2500);
    return;
  }

  Serial.println("--------------");



  Serial.print(" ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    if ( addr[i]<16) {
      Serial.print("0");
    }
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
    Serial.println("CRC is not valid!");
    return;
  }
  Serial.println();


  Serial.print("CHIP FAMILY ");
  Serial.print(addr[0],HEX);
  // the first ROM byte indicates which chip
  Serial.print(" =  ");
  switch (addr[0]) {

  case 0x01:
    Serial.println(" DS1990 DS2401");  //
    break;
  case 0x02:
    Serial.println(" DS1991");  //
    break;
  case 0x04:
    Serial.println(" DS1994");  //
    break;
  case 0x05:
    Serial.println(" DS2405");  //
    break;
  case 0x06:
    Serial.println(" DS1992");  //
    break;
  case 0x08:
    Serial.println(" DS1993");  //
    break;
  case 0x0B:
    Serial.println(" DS1985"); 
    break;
  case 0x10:
    Serial.println(" DS1820 DS18S20 DS1920"); 
    break;
  case 0x12:
    Serial.println(" DS2406"); 
    break;
  case 0x21:
    Serial.println(" DS1921");
    break;
  case 0x22:
    Serial.println(" DS1822");
    break;
  case 0x24:
    Serial.println(" DS1904");
    break;
  case 0x28:
    Serial.println(" DS18B20");
    break;
  case 0x29:
    Serial.println(" DS2408"); 
    break;
  case 0x36:
    Serial.println(" DS2740"); 
    break;
  case 0x3B:
    Serial.println(" DS1825"); 
    break;
  case 0x41:
    Serial.println(" DS1923"); 
    break;

  default:
    Serial.println(" is not listed.");

    return;
  }

}




Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy