Skip to content

Commit 5e4b3dd

Browse files
committed
0.1.2 DS2401
1 parent 2408a60 commit 5e4b3dd

File tree

12 files changed

+178
-23
lines changed

12 files changed

+178
-23
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# These are supported funding model platforms
22

33
github: RobTillaart
4-
4+
custom: "https://www.paypal.me/robtillaart"

libraries/DS2401/.github/workflows/arduino-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010
- uses: arduino/arduino-lint-action@v1
1111
with:
1212
library-manager: update

libraries/DS2401/.github/workflows/arduino_test_runner.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ on: [push, pull_request]
66
jobs:
77
runTest:
88
runs-on: ubuntu-latest
9+
timeout-minutes: 20
910

1011
steps:
11-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1213
- uses: ruby/setup-ruby@v1
1314
with:
1415
ruby-version: 2.6
1516
- run: |
17+
sudo sysctl vm.mmap_rnd_bits=28
1618
gem install arduino_ci
1719
arduino_ci.rb

libraries/DS2401/.github/workflows/jsoncheck.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- name: json-syntax-check
15-
uses: limitusus/json-syntax-check@v1
15+
uses: limitusus/json-syntax-check@v2
1616
with:
1717
pattern: "\\.json$"
1818

libraries/DS2401/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.1.2] - 2024-03-23
10+
- Fix #3, getUID example (kudos to Arduino 12)
11+
- add **getUID4()** and **compareUID4()**
12+
- fix **compareUID()** functions
13+
- update GitHub actions
14+
- add examples
15+
- update readme.md
16+
- minor edits.
17+
18+
919
## [0.1.1] - 2024-01-01
1020
- add **getUID6()** and **compartUID6()**
1121
- update readme.md

libraries/DS2401/DS2401.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
// FILE: DS2401.h
44
// AUTHOR: Rob Tillaart
55
// PURPOSE: Library for the DS2401 1-wire unique identification chip.
6-
// VERSION: 0.1.1
6+
// VERSION: 0.1.2
77
// URL: https://github.com/RobTillaart/DS2401
88

99

1010
#include "Arduino.h"
1111
#include "OneWire.h"
1212

1313

14-
#define DS2401_LIB_VERSION (F("0.1.1"))
14+
#define DS2401_LIB_VERSION (F("0.1.2"))
1515

1616

1717
class DS2401
@@ -47,7 +47,7 @@ class DS2401
4747

4848
bool compareUID(uint8_t * buffer)
4949
{
50-
return memcmp(buffer, _address, 8);
50+
return !memcmp(buffer, _address, 8);
5151
}
5252

5353

@@ -59,7 +59,19 @@ class DS2401
5959

6060
bool compareUID6(uint8_t * buffer)
6161
{
62-
return memcmp(buffer, &_address[1], 6);
62+
return !memcmp(buffer, &_address[1], 6);
63+
}
64+
65+
66+
void getUID4(uint32_t * buffer)
67+
{
68+
memcpy(buffer, &_address[1], 4);
69+
}
70+
71+
72+
bool compareUID4(uint32_t * buffer)
73+
{
74+
return !memcmp(buffer, &_address[1], 4);
6375
}
6476

6577

libraries/DS2401/README.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ Known family bytes, there are many other 1-Wire devices with unknown family.
4141
| byte | device | description |
4242
|:------:|:----------:|:--------------|
4343
| 0x01 | DS2401 | UID device
44-
| 0x26 | DS2438 | Battery monitor
45-
| 0x2D | DS2807 | EEPROM
44+
| 0x05 | DS2405 | Switch
45+
| 0x10 | DS18S20 | thermometer
4646
| 0x22 | DS1822 | thermometer
47-
| 0x3B | DS1825 | thermometer
47+
| 0x26 | DS2438 | Battery monitor
4848
| 0x28 | DS18B20 | thermometer
49-
| 0x10 | DS18S20 | thermometer
49+
| 0x2D | DS2807 | EEPROM
50+
| 0x38 | DS1825 | thermometer
51+
| 0x3B | MAX31850 | thermometer
5052
| 0x42 | DS28EA00 | thermometer
5153

5254

@@ -72,23 +74,42 @@ This DS2401 library supports only one device per pin, and no parasite mode.
7274
The class supports getting an UID and compare an UID.
7375

7476
- **DS2401(OneWire \* ow)** constructor needs a reference to OneWire object.
75-
- **bool begin()** resets oneWire and search fot the address.
77+
- **bool begin()** resets oneWire and search for the device address.
7678
Returns true if address / UID of the device is found.
79+
Must be called to read the UID.
7780

7881

7982
#### 8 bytes UID
8083

81-
- **void getUID(uint8_t \* buffer)** copies the found UID (64 bits) in **begin()** to buffer which should be 8 bytes.
82-
- **bool compareUID(uint8_t \* buffer)** compares the buffer (8 bytes) with the internal UID.
83-
Returns true if they are identical.
84+
- **void getUID(uint8_t \* buffer)** copies the found UID (64 bits) in
85+
**begin()** to a buffer which should be at least 8 bytes.
86+
- **bool compareUID(uint8_t \* buffer)** compares the buffer (8 bytes)
87+
with the internal UID. Returns true if they are identical.
8488

8589

8690
#### 6 bytes UID
8791

8892
The 6 bytes interface does not use the family byte and the CRC byte in the UID.
93+
The reason is that these are either constant or can be calculated from the other
94+
bytes, so not unique.
8995

90-
- **void getUID6(uint8_t \* buffer)** copies the found UID (48 bits) in **begin()** to buffer which should be 6 bytes.
91-
- **bool compareUID6(uint8_t \* buffer)** compares the buffer (6 bytes) with 6 bytes of the internal UID.
96+
- **void getUID6(uint8_t \* buffer)** copies the found UID (48 bits) in
97+
**begin()** to a buffer which should be at least 6 bytes.
98+
- **bool compareUID6(uint8_t \* buffer)** compares the buffer (6 bytes)
99+
with 6 bytes of the internal UID.
100+
Returns true if they are identical.
101+
102+
103+
#### 4 bytes UID
104+
105+
The 4 bytes interface only uses 4 bytes of the unique part of the address.
106+
These functions are added as it allows to copy the number directly into a
107+
uint32_t variable.
108+
109+
- **void getUID4(uint32_t \* buffer)** copies 4 unique bytes of the found UID
110+
to a uint32_t variable.
111+
- **bool compareUID4(uint32_t \* buffer)** compares the uint32_t variable
112+
with 4 unique bytes of the internal UID.
92113
Returns true if they are identical.
93114

94115

@@ -117,11 +138,12 @@ When the wires are longer this resistor needs to be smaller.
117138
#### Must
118139

119140
- Improve documentation.
141+
- test with different hardware.
142+
- verify UID4 interface with hardware
143+
120144

121145
#### Should
122146

123-
- example of compare function.
124-
- test with different hardware.
125147

126148
#### Could
127149

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// FILE: DS2401_compareUID.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: DS2401 lib demo
5+
// URL: https://github.com/RobTillaart/DS2401
6+
7+
8+
#include <OneWire.h>
9+
#include "DS2401.h"
10+
11+
12+
#define ONE_WIRE_BUS 2
13+
14+
OneWire oneWire(ONE_WIRE_BUS);
15+
DS2401 ds24(&oneWire);
16+
17+
uint8_t uid[8];
18+
19+
20+
void setup()
21+
{
22+
Serial.begin(115200);
23+
Serial.println(__FILE__);
24+
Serial.print("DS2401_LIB_VERSION: ");
25+
Serial.println(DS2401_LIB_VERSION);
26+
27+
28+
ds24.begin(); // read UID
29+
30+
Serial.print("\ngetUID:\t ");
31+
ds24.getUID(uid);
32+
for (int i = 0; i < 8; i++)
33+
{
34+
if (uid[i] < 0x10) Serial.print(0);
35+
Serial.print(uid[i]);
36+
Serial.print(" ");
37+
}
38+
Serial.println();
39+
Serial.print("compareUID:\t");
40+
Serial.println(ds24.compareUID(uid));
41+
Serial.println();
42+
43+
44+
Serial.print("\ngetUID6:\t ");
45+
ds24.getUID6(uid);
46+
for (int i = 0; i < 6; i++)
47+
{
48+
if (uid[i] < 0x10) Serial.print(0);
49+
Serial.print(uid[i]);
50+
Serial.print(" ");
51+
}
52+
Serial.println();
53+
Serial.print("compareUID6:\t");
54+
Serial.println(ds24.compareUID6(uid));
55+
Serial.println();
56+
57+
Serial.println("\ndone...");
58+
}
59+
60+
61+
void loop()
62+
{
63+
}
64+
65+
66+
// -- END OF FILE --

libraries/DS2401/examples/DS2401-getUID/DS2401-getUID.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void setup()
2323
Serial.print("DS2401_LIB_VERSION: ");
2424
Serial.println(DS2401_LIB_VERSION);
2525

26+
ds24.begin(); // read UID
2627
Serial.print("\ngetUID:\t ");
2728
ds24.getUID(uid);
2829
for (int i = 0; i < 8; i++)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// FILE: DS2401_getUID4.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+
uint32_t uid; // 4 bytes
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+
ds24.begin(); // read UID
27+
Serial.print("\ngetUID4:\t ");
28+
ds24.getUID4(&uid);
29+
Serial.println(uid, HEX);
30+
Serial.print("compareUID4:\t ");
31+
Serial.println(ds24.compareUID4(&uid));
32+
33+
Serial.println("\ndone...");
34+
}
35+
36+
37+
void loop()
38+
{
39+
}
40+
41+
42+
// -- END OF FILE --

0 commit comments

Comments
 (0)