Adafruit 1-Wire GPIO Breakout - DS2413 Created by Bill Earl Last updated on 2014-03-28 12:00:21 PM EDT
Guide Contents Guide Contents 2 Overview 3 Assembly & Wiring 5 Headers 5 Position the Header 5 And Solder! 6 Wiring 6 Basic Wiring: 6 Wiring Multiple DS2413 Breakouts 7 Use it! 9 OneWire Library 10 Download and Install 10 Library Documentation 10 DS2413 Example Sketch 11 Open Drain GPIO 12 Running the Example Code 14 Download the example sketch from our Github repository (http://adafru.it/deQ): 14 Wiring: 14 Reading, Writing and Arithmetic 16 myWire.read(); 16 myWire.
Overview Pins are precious in the microcontroller world. How many times have you needed just one more pin? Sure, you could step up to a Mega and get a whole bunch more, but what if you really just need one or two? The DS2413 breakout board is the perfect solution. Each DS2413 breakout has 2 open drain GPIO pins and a 1-Wire interface. Just one of these boards will give you 2 pins for the price of one. But you can keep expanding from there.
© Adafruit Industries http://learn.adafruit.
Assembly & Wiring The board comes pre-assembled and tested from our factory. We include optional headers for breadboard use. Or you can wire the board directly into your project. Headers Installing the optional headers is a simple process and takes just a few minutes: Position the Header Cut the header strip to length if necessary and place it in the breadboard (long pins down!). Position the breakout board over the header. © Adafruit Industries http://learn.adafruit.
And Solder! Solder each pin to assure a good electrical connection. If you are new to soldering, check out the Adafruit Guide to Excellent Soldering. (http://adafru.it/aTk) Wiring Wiring to the Arduino is simple as well. Just power, ground and a signal wire: Basic Wiring: GND -> Arduino GND IO -> Arduino GPIO pin (The example co de uses pin 8) Then connect a 4.7K ohm pullup resistor (included) from IO to 5v. © Adafruit Industries http://learn.adafruit.
Wiring Multiple DS2413 Breakouts To add more breakouts, just connect more to the same GND and IO pin. Additional pullup resistors are not required. © Adafruit Industries http://learn.adafruit.
© Adafruit Industries http://learn.adafruit.
Use it! Once connected to the onewire bus, the GPIO pins can be used for either input or output. The following pages will show you how to control these pins via the onwire library. We will also show you how to connect things to the open drain outputs of the GPIO pins. © Adafruit Industries http://learn.adafruit.
OneWire Library Download and Install The DS2413 uses the Maxim/Dallas OneWire protocol. You can download the OneWire library from the PJRC site via this link: http://www.pjrc.com/teensy/td_libs_OneWire.html (http://adafru.it/das) (http: //adafru.it/das) OneWire Library Download http://adafru.it/deN Once downloaded, you must install the library. This guide describes how and where to install an Arduino Library: All About Arduino Libraries http://adafru.
http://adafru.it/das DS2413 Example Sketch We have an example sketch that shows how to use the OneWire library to talk to the DS2413 GPIO pins here at GitHub: https://github.com/adafruit/Adafruit_DS2413 DS2413 Example Sketch Download http://adafru.it/deO © Adafruit Industries http://learn.adafruit.
Open Drain GPIO The DS2413 outputs are "Open Drain". What that means is that the output is the "Drain" of an Nchannel FET: Internally, the "Source" of the FET is connected to Ground. But the Drain is left open. When switched on, the FET provides a path for current to flow from the output pin to ground. Since there is no internal connection to VCC, the open drain output does not put out a voltage like an Arduino GPIO pin. You have to provide your own external pullup.
For more information, refer to the DS2413 data sheet: DS2413 Data Sheet http://adafru.it/deP © Adafruit Industries http://learn.adafruit.
Running the Example Code Download the example sketch from our Github repository (http://adafru.it/deQ) : Download Example Code http://adafru.it/deO Wiring: Connect a LED to IOA and IOB as follows: Catho de (short leg) of LED connected to the GPIO pin. Ano de (long leg) of LED connected to one end of a resisto r*. Other end of the resisto r connected to 5v. * A 1K resistor is shown here as a 'safe' value.
© Adafruit Industries http://learn.adafruit.
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. /* Write */ bool ok = false; ok = write(0x3); if (!ok) Serial.
/* Write */ bool ok = false; ok = write(B00000001); if (!ok) Serial.println(F("Wire failed")); delay(1000); ok = write(B00000010); if (!ok) Serial.println(F("Wire failed")); delay(1000); For more on integer constants in the different number bases, see the Arduino Integer Constants (http://adafru.it/deR)page. Reading GPIO Pins Reading is a little trickier: You need to separate the individual pin values from the byte that is returned from the read().
© Adafruit Industries http://learn.adafruit.
Downloads Datasheet for the DS2413 (http://adafru.it/deT) Product page for the DS2413 (http://adafru.it/deU) One-Wire overview (http://adafru.