Pages: [1]   Go Down
Author Topic: 1Wire Onewire scanner  (Read 2242 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Faraday Member
**
Karma: 33
Posts: 4957
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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(' ');
    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;
  }

}


Logged

Pages: [1]   Go Up
Jump to: