Using Arduino UNO to read out the serial number from a DS-2401

Hi there,

I am trying to read out the serial number from the ds2401 using my arduino UNO. Only i'm not getting any results. I tried searching for answers on the internet but found nothing. I tried the following code i found online.

#include <OneWire.h>
OneWire ds(6);                    // OneWire bus on digital pin 6
void setup()
{
  Serial.begin (9600);
  delay(250);
}
void loop()
{
  byte i;           // This is for the for loops
  boolean present;  // device present varj
  byte data[8];     // container for the data from device
  byte crc_calc;    //calculated CRC
  byte crc_byte;    //actual CRC as sent by DS2401
  //1-Wire bus reset, needed to start operation on the bus,
  //returns a 1/TRUE if presence pulse detected
  present = ds.reset();
  if (present == TRUE)
  {
    Serial.println("---------- Device present ----------");
    ds.write(0x33);  //Send Read data command
    data[0] = ds.read();
    Serial.print("Family code: 0x");
    PrintTwoDigitHex (data[0], 1);
    Serial.print("Hex ROM data: ");
    for (i = 1; i <= 6; i++)
    {
      data[i] = ds.read(); //store each byte in different position in array
      PrintTwoDigitHex (data[i], 0);
      Serial.print(" ");
    }
    Serial.println();
    crc_byte = ds.read(); //read CRC, this is the last byte
    crc_calc = OneWire::crc8(data, 7); //calculate CRC of the data
    Serial.print("Calculated CRC: 0x");
    PrintTwoDigitHex (crc_calc, 1);
    Serial.print("Actual CRC: 0x");
    PrintTwoDigitHex (crc_byte, 1);
  }
  else //Nothing is connected in the bus
  {
    Serial.println("xxxxx Nothing connected xxxxx");
  }
  delay(3000);
}
void PrintTwoDigitHex (byte b, boolean newline)
{
  Serial.print(b/16, HEX);
  Serial.print(b%16, HEX);
  if (newline) Serial.println();
}

I connected the ds2401 to my arduino uno this way:
Picture how i connected it. (for some reason the img tags dont work with this type of url)

I hope someone can help me figure this out. :slight_smile:

Regards,

This reference says you need a pullup resistor on the data wire that's not shown on your diagram.

http://playground.arduino.cc/Learning/OneWire

DS18B20s require 4.7 k ohm pullups.

GypsumFantastic:
This reference says you need a pullup resistor on the data wire that's not shown on your diagram.

Arduino Playground - HomePage

raschemmel:
DS18B20s reqhure 4.7 k ohm pullups.

Thanks a lot guys! got it working now :slight_smile:

DS18B20s reqhure 4.7 k ohm pullups.

To be slightly more pedantic... all 1-wire devices need a communications bus where the signal lines have pullup resistors on them.

pwillard:
To be slightly more pedantic... all 1-wire devices need a communications bus where the signal lines have pullup resistors on them.

Ooh like that, Alright thanks a lot!

got it working thanks! :slight_smile:

To be slightly more pedantic... all 1-wire devices need a communications bus where the signal lines have pullup resistors on them.

That was the inference....

Hi, it seems to be nice to use this sketch for identifying where your arduino uno board will be.

I would like to use this sketch for that. But...

Can you help me to get or download a onewire.h library that works only with this sketch ????

I saw this library, and has alot more; so It will consume almost all memory of the arduino uno.

Thank you.

Google Search: Dallas Semiconductors