Skip to content

Commit b3543da

Browse files
committed
0.1.0 DS2401
1 parent 41cc694 commit b3543da

File tree

15 files changed

+572
-0
lines changed

15 files changed

+572
-0
lines changed

libraries/DS2401/.arduino-ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
- m4
24+
# - esp32 // pretty strict compiler
25+
- esp8266
26+
# - mega2560
27+
- rpipico
28+
# Declaring Dependent Arduino Libraries (to be installed via the Arduino Library Manager)
29+
libraries:
30+
- "OneWire"
31+
32+
unittest:
33+
# These dependent libraries will be installed
34+
libraries:
35+
- "OneWire"
36+
- "util/crc16"

libraries/DS2401/.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
runTest:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/DS2401/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Change Log DS2401
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2023-12-31
10+
- initial version
11+
12+
13+

libraries/DS2401/DS2401.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
//
3+
// FILE: DS2401.h
4+
// AUTHOR: Rob Tillaart
5+
// PURPOSE: Library for the DS2401 1-wire unique identification chip.
6+
// VERSION: 0.1.0
7+
// URL: https://github.com/RobTillaart/DS2401
8+
9+
10+
#include "Arduino.h"
11+
#include "OneWire.h"
12+
13+
14+
#define DS2401_LIB_VERSION (F("0.1.0"))
15+
16+
17+
class DS2401
18+
{
19+
public:
20+
explicit DS2401(OneWire * ow)
21+
{
22+
_oneWire = ow;
23+
}
24+
25+
bool begin()
26+
{
27+
// reset address
28+
for (int i = 0; i < 8; i++)
29+
{
30+
_address[i] = 0x00;
31+
}
32+
33+
_oneWire->reset();
34+
_oneWire->reset_search();
35+
_oneWire->search(_address);
36+
// ds2401 has an family ID of 0x01 but this way
37+
// all one-wire devices can be used as UID.
38+
return (_address[0] != 0x00) && (_oneWire->crc8(_address, 7) == _address[7]);
39+
}
40+
41+
void getUID(uint8_t * buffer)
42+
{
43+
memcpy(buffer, _address, 8);
44+
}
45+
46+
bool compareUID(uint8_t * buffer)
47+
{
48+
return memcmp(buffer, _address, 8);
49+
}
50+
51+
52+
private:
53+
OneWire * _oneWire;
54+
uint8_t _address[8];
55+
};
56+
57+
58+
// -- END OF FILE --
59+

libraries/DS2401/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-2023 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/DS2401/README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/DS2401/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/DS2401/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DS2401/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/DS2401/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DS2401/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/DS2401.svg)](https://github.com/RobTillaart/DS2401/issues)
6+
7+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DS2401/blob/master/LICENSE)
8+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DS2401.svg?maxAge=3600)](https://github.com/RobTillaart/DS2401/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/DS2401.svg)](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+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// FILE: DS2401_getUID.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: DS2401 lib getUID
5+
// URL: https://github.com/RobTillaart/DS2401
6+
7+
#include <OneWire.h>
8+
#include "DS2401.h"
9+
10+
11+
#define ONE_WIRE_BUS 2
12+
13+
OneWire oneWire(ONE_WIRE_BUS);
14+
DS2401 ds24(&oneWire);
15+
16+
uint8_t uid[8];
17+
18+
19+
void setup()
20+
{
21+
Serial.begin(115200);
22+
Serial.println(__FILE__);
23+
Serial.print("DS2401_LIB_VERSION: ");
24+
Serial.println(DS2401_LIB_VERSION);
25+
26+
Serial.print("\ngetUID: ");
27+
ds24.getUID(uid);
28+
29+
for (int i = 0; i < 8; i++)
30+
{
31+
if (uid[i] < 0x10) Serial.print(0);
32+
Serial.print(uid[i]);
33+
Serial.print(" ");
34+
}
35+
Serial.println();
36+
37+
Serial.println("\ndone...");
38+
}
39+
40+
41+
void loop()
42+
{
43+
}
44+
45+
46+
// -- END OF FILE --

0 commit comments

Comments
 (0)