|
| 1 | + |
| 2 | +[](https://github.com/marketplace/actions/arduino_ci) |
| 3 | +[](https://github.com/RobTillaart/DS2401/actions/workflows/arduino-lint.yml) |
| 4 | +[](https://github.com/RobTillaart/DS2401/actions/workflows/jsoncheck.yml) |
| 5 | +[](https://github.com/RobTillaart/DS2401/issues) |
| 6 | + |
| 7 | +[](https://github.com/RobTillaart/DS2401/blob/master/LICENSE) |
| 8 | +[](https://github.com/RobTillaart/DS2401/releases) |
| 9 | +[](https://registry.platformio.org/libraries/robtillaart/DS2401) |
| 10 | + |
| 11 | + |
| 12 | +# DS2401 |
| 13 | + |
| 14 | +Library for the DS2401 1-wire unique identification chip. |
| 15 | + |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +The DS2401 is an ID chip that uses the oneWire (1-Wire) protocol. |
| 20 | +In fact it just returns its address as these are (quite) unique. |
| 21 | + |
| 22 | +Every oneWire device has a unique 48 bit number which together with |
| 23 | +the device family byte and an 8 bits CRC forms 8 byte unique code. |
| 24 | +The family byte adds to the uniqueness however the CRC does not. |
| 25 | +Although the CRC does not add to the uniqueness, it is taken into |
| 26 | +the UID as it allows to check the other 7 bytes for integrity. |
| 27 | + |
| 28 | +As there are at least 8 device types / families known, there are |
| 29 | +thus at least 51 bits of uniqueness. |
| 30 | +This gives in total more than 10^15 bit patterns, which should be |
| 31 | +sufficient for most applications. |
| 32 | + |
| 33 | +The library is meant for DS2401 chips but allows all oneWire devices |
| 34 | +to be used as an unique ID (UID). This implies that functionality |
| 35 | +like e.g. temperature sensing is not available with this library. |
| 36 | + |
| 37 | +Known family bytes, there are many other 1-Wire devices with unknown family. |
| 38 | + |
| 39 | +| byte | device | description | |
| 40 | +|:------:|:----------:|:--------------| |
| 41 | +| 0x01 | DS2401 | UID device |
| 42 | +| 0x26 | DS2438 | Battery monitor |
| 43 | +| 0x2D | DS2807 | EEPROM |
| 44 | +| 0x22 | DS1822 | thermometer |
| 45 | +| 0x3B | DS1825 | thermometer |
| 46 | +| 0x28 | DS18B20 | thermometer |
| 47 | +| 0x10 | DS18S20 | thermometer |
| 48 | +| 0x42 | DS28EA00 | thermometer |
| 49 | + |
| 50 | + |
| 51 | +#### Related |
| 52 | + |
| 53 | +- https://github.com/RobTillaart/DS2401 |
| 54 | +- https://github.com/RobTillaart/DS28CM00 (I2C) |
| 55 | +- https://github.com/RobTillaart/UUID |
| 56 | +- https://github.com/RobTillaart/DS18B20_INT |
| 57 | +- https://github.com/RobTillaart/DS18B20_RT |
| 58 | +- https://github.com/milesburton/Arduino-Temperature-Control-Library |
| 59 | + |
| 60 | + |
| 61 | +## Interface |
| 62 | + |
| 63 | +```cpp |
| 64 | +#include "DS2401.h" |
| 65 | +``` |
| 66 | + |
| 67 | +#### Core |
| 68 | + |
| 69 | +This DS2401 library supports only one device per pin, and no parasite mode. |
| 70 | +The class supports getting an UID and compare an UID. |
| 71 | + |
| 72 | +- **DS2401(OneWire \* ow)** constructor needs a reference to OneWire object. |
| 73 | +- **bool begin()** resets oneWire and search fot the address. |
| 74 | +Returns true if address / UID of the device is found. |
| 75 | +- **void getUID(uint8_t \* buffer)** copies the found UID in **begin()** to buffer. |
| 76 | +- **bool compareUID(uint8_t \* buffer)** compares the buffer with the internal UID. |
| 77 | +Returns true if they are identical. |
| 78 | + |
| 79 | + |
| 80 | +## Operation |
| 81 | + |
| 82 | +This library supports only one DS2401 per Arduino / MCU pin. |
| 83 | + |
| 84 | +``` |
| 85 | + // BOTTOM VIEW |
| 86 | + // |
| 87 | + // PIN MEANING |
| 88 | + // /---+ |
| 89 | + // / o | 1 GND |
| 90 | + // | o | 2 DATA |
| 91 | + // \ o | 3 VCC |
| 92 | + // \---+ |
| 93 | +``` |
| 94 | +(always check datasheet) |
| 95 | + |
| 96 | +Connect a pull-up resistor 4.7 KΩ between pin3 and pin2. |
| 97 | +When the wires are longer this resistor needs to be smaller. |
| 98 | + |
| 99 | + |
| 100 | +## Future |
| 101 | + |
| 102 | +#### Must |
| 103 | + |
| 104 | +- Improve documentation. |
| 105 | + |
| 106 | +#### Should |
| 107 | + |
| 108 | +- example of compare function. |
| 109 | +- test with different hardware. |
| 110 | + |
| 111 | +#### Could |
| 112 | + |
| 113 | +- performance test. (mainly fetching) |
| 114 | +- use only 48 unique bits instead of all 64? |
| 115 | + - add **getUID48()** and **compareUID48()** |
| 116 | + |
| 117 | +#### Wont |
| 118 | + |
| 119 | +- get any subset of the 8 bytes? => user can do this. |
| 120 | + |
| 121 | + |
| 122 | +## Support |
| 123 | + |
| 124 | +If you appreciate my libraries, you can support the development and maintenance. |
| 125 | +Improve the quality of the libraries by providing issues and Pull Requests, or |
| 126 | +donate through PayPal or GitHub sponsors. |
| 127 | + |
| 128 | +Thank you, |
| 129 | + |
0 commit comments