Datasheet
Reading, Writing and Arithmetic
Reading and writing to the DS2413 is via the read() and write() functions of the Onewire
library:
myWire.read();
Read a byte.
myWire.write(num);
Write a byte.
These functions read and write a byte at a time. So you need to use a little binary arithmetic to
separate out the 2 bits corresponding to the 2 GPIO pins.
In the example code, the 2 LEDs are flashed by alternately writing 0x0 and 0x3.
Binary and Hexadecimal
The 0x3 in the example is the hexadecimal equivalent to the binary number B00000011. In
the DS2413, the low-order bit (the one to the far right) corresponds to IOA and the one next to
it corresponds to IOB. Writing 0x3 writes a binary '1' to both pins and turns them both on.
To turn on just IOA you could write 0x1 (B00000001). And to turn on just IOB, you could write
0x2 (B00000010).
If you substitute the following code, the LEDs will flash alternately:
Or, if you prefer, you can use the binary representation instead:
/* Write */
bool ok = false;
ok = write(0x3);
if (!ok) Serial.println(F("Wire failed"));
delay(1000);
ok = write(0x0);
if (!ok) Serial.println(F("Wire failed"));
delay(1000);
/* Write */
bool ok = false;
ok = write(0x1);
if (!ok) Serial.println(F("Wire failed"));
delay(1000);
ok = write(0x2);
if (!ok) Serial.println(F("Wire failed"));
delay(1000);
© Adafruit Industries http://learn.adafruit.com/adafruit-1-wire-gpio-breakout-ds2413 Page 16 of 19