mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.1.2 DS2401
This commit is contained in:
parent
2408a607c0
commit
5e4b3dd54e
2
libraries/DS2401/.github/FUNDING.yml
vendored
2
libraries/DS2401/.github/FUNDING.yml
vendored
@ -1,4 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
||||
custom: "https://www.paypal.me/robtillaart"
|
||||
|
@ -6,7 +6,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -6,12 +6,14 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
sudo sysctl vm.mmap_rnd_bits=28
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
||||
|
@ -10,9 +10,9 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
uses: limitusus/json-syntax-check@v2
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
||||
|
@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.2] - 2024-03-23
|
||||
- Fix #3, getUID example (kudos to Arduino 12)
|
||||
- add **getUID4()** and **compareUID4()**
|
||||
- fix **compareUID()** functions
|
||||
- update GitHub actions
|
||||
- add examples
|
||||
- update readme.md
|
||||
- minor edits.
|
||||
|
||||
|
||||
## [0.1.1] - 2024-01-01
|
||||
- add **getUID6()** and **compartUID6()**
|
||||
- update readme.md
|
||||
|
@ -3,7 +3,7 @@
|
||||
// FILE: DS2401.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Library for the DS2401 1-wire unique identification chip.
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// URL: https://github.com/RobTillaart/DS2401
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#include "OneWire.h"
|
||||
|
||||
|
||||
#define DS2401_LIB_VERSION (F("0.1.1"))
|
||||
#define DS2401_LIB_VERSION (F("0.1.2"))
|
||||
|
||||
|
||||
class DS2401
|
||||
@ -47,7 +47,7 @@ public:
|
||||
|
||||
bool compareUID(uint8_t * buffer)
|
||||
{
|
||||
return memcmp(buffer, _address, 8);
|
||||
return !memcmp(buffer, _address, 8);
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,19 @@ public:
|
||||
|
||||
bool compareUID6(uint8_t * buffer)
|
||||
{
|
||||
return memcmp(buffer, &_address[1], 6);
|
||||
return !memcmp(buffer, &_address[1], 6);
|
||||
}
|
||||
|
||||
|
||||
void getUID4(uint32_t * buffer)
|
||||
{
|
||||
memcpy(buffer, &_address[1], 4);
|
||||
}
|
||||
|
||||
|
||||
bool compareUID4(uint32_t * buffer)
|
||||
{
|
||||
return !memcmp(buffer, &_address[1], 4);
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,12 +41,14 @@ Known family bytes, there are many other 1-Wire devices with unknown family.
|
||||
| byte | device | description |
|
||||
|:------:|:----------:|:--------------|
|
||||
| 0x01 | DS2401 | UID device
|
||||
| 0x26 | DS2438 | Battery monitor
|
||||
| 0x2D | DS2807 | EEPROM
|
||||
| 0x22 | DS1822 | thermometer
|
||||
| 0x3B | DS1825 | thermometer
|
||||
| 0x28 | DS18B20 | thermometer
|
||||
| 0x05 | DS2405 | Switch
|
||||
| 0x10 | DS18S20 | thermometer
|
||||
| 0x22 | DS1822 | thermometer
|
||||
| 0x26 | DS2438 | Battery monitor
|
||||
| 0x28 | DS18B20 | thermometer
|
||||
| 0x2D | DS2807 | EEPROM
|
||||
| 0x38 | DS1825 | thermometer
|
||||
| 0x3B | MAX31850 | thermometer
|
||||
| 0x42 | DS28EA00 | thermometer
|
||||
|
||||
|
||||
@ -72,23 +74,42 @@ This DS2401 library supports only one device per pin, and no parasite mode.
|
||||
The class supports getting an UID and compare an UID.
|
||||
|
||||
- **DS2401(OneWire \* ow)** constructor needs a reference to OneWire object.
|
||||
- **bool begin()** resets oneWire and search fot the address.
|
||||
- **bool begin()** resets oneWire and search for the device address.
|
||||
Returns true if address / UID of the device is found.
|
||||
Must be called to read the UID.
|
||||
|
||||
|
||||
#### 8 bytes UID
|
||||
|
||||
- **void getUID(uint8_t \* buffer)** copies the found UID (64 bits) in **begin()** to buffer which should be 8 bytes.
|
||||
- **bool compareUID(uint8_t \* buffer)** compares the buffer (8 bytes) with the internal UID.
|
||||
Returns true if they are identical.
|
||||
- **void getUID(uint8_t \* buffer)** copies the found UID (64 bits) in
|
||||
**begin()** to a buffer which should be at least 8 bytes.
|
||||
- **bool compareUID(uint8_t \* buffer)** compares the buffer (8 bytes)
|
||||
with the internal UID. Returns true if they are identical.
|
||||
|
||||
|
||||
#### 6 bytes UID
|
||||
|
||||
The 6 bytes interface does not use the family byte and the CRC byte in the UID.
|
||||
The reason is that these are either constant or can be calculated from the other
|
||||
bytes, so not unique.
|
||||
|
||||
- **void getUID6(uint8_t \* buffer)** copies the found UID (48 bits) in **begin()** to buffer which should be 6 bytes.
|
||||
- **bool compareUID6(uint8_t \* buffer)** compares the buffer (6 bytes) with 6 bytes of the internal UID.
|
||||
- **void getUID6(uint8_t \* buffer)** copies the found UID (48 bits) in
|
||||
**begin()** to a buffer which should be at least 6 bytes.
|
||||
- **bool compareUID6(uint8_t \* buffer)** compares the buffer (6 bytes)
|
||||
with 6 bytes of the internal UID.
|
||||
Returns true if they are identical.
|
||||
|
||||
|
||||
#### 4 bytes UID
|
||||
|
||||
The 4 bytes interface only uses 4 bytes of the unique part of the address.
|
||||
These functions are added as it allows to copy the number directly into a
|
||||
uint32_t variable.
|
||||
|
||||
- **void getUID4(uint32_t \* buffer)** copies 4 unique bytes of the found UID
|
||||
to a uint32_t variable.
|
||||
- **bool compareUID4(uint32_t \* buffer)** compares the uint32_t variable
|
||||
with 4 unique bytes of the internal UID.
|
||||
Returns true if they are identical.
|
||||
|
||||
|
||||
@ -117,11 +138,12 @@ When the wires are longer this resistor needs to be smaller.
|
||||
#### Must
|
||||
|
||||
- Improve documentation.
|
||||
- test with different hardware.
|
||||
- verify UID4 interface with hardware
|
||||
|
||||
|
||||
#### Should
|
||||
|
||||
- example of compare function.
|
||||
- test with different hardware.
|
||||
|
||||
#### Could
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
//
|
||||
// FILE: DS2401_compareUID.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DS2401 lib demo
|
||||
// URL: https://github.com/RobTillaart/DS2401
|
||||
|
||||
|
||||
#include <OneWire.h>
|
||||
#include "DS2401.h"
|
||||
|
||||
|
||||
#define ONE_WIRE_BUS 2
|
||||
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
DS2401 ds24(&oneWire);
|
||||
|
||||
uint8_t uid[8];
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DS2401_LIB_VERSION: ");
|
||||
Serial.println(DS2401_LIB_VERSION);
|
||||
|
||||
|
||||
ds24.begin(); // read UID
|
||||
|
||||
Serial.print("\ngetUID:\t ");
|
||||
ds24.getUID(uid);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (uid[i] < 0x10) Serial.print(0);
|
||||
Serial.print(uid[i]);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("compareUID:\t");
|
||||
Serial.println(ds24.compareUID(uid));
|
||||
Serial.println();
|
||||
|
||||
|
||||
Serial.print("\ngetUID6:\t ");
|
||||
ds24.getUID6(uid);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (uid[i] < 0x10) Serial.print(0);
|
||||
Serial.print(uid[i]);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.print("compareUID6:\t");
|
||||
Serial.println(ds24.compareUID6(uid));
|
||||
Serial.println();
|
||||
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -23,6 +23,7 @@ void setup()
|
||||
Serial.print("DS2401_LIB_VERSION: ");
|
||||
Serial.println(DS2401_LIB_VERSION);
|
||||
|
||||
ds24.begin(); // read UID
|
||||
Serial.print("\ngetUID:\t ");
|
||||
ds24.getUID(uid);
|
||||
for (int i = 0; i < 8; i++)
|
||||
|
42
libraries/DS2401/examples/DS2401-getUID4/DS2401-getUID4.ino
Normal file
42
libraries/DS2401/examples/DS2401-getUID4/DS2401-getUID4.ino
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// FILE: DS2401_getUID4.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: DS2401 lib getUID
|
||||
// URL: https://github.com/RobTillaart/DS2401
|
||||
|
||||
#include <OneWire.h>
|
||||
#include "DS2401.h"
|
||||
|
||||
|
||||
#define ONE_WIRE_BUS 2
|
||||
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
DS2401 ds24(&oneWire);
|
||||
|
||||
uint32_t uid; // 4 bytes
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DS2401_LIB_VERSION: ");
|
||||
Serial.println(DS2401_LIB_VERSION);
|
||||
|
||||
ds24.begin(); // read UID
|
||||
Serial.print("\ngetUID4:\t ");
|
||||
ds24.getUID4(&uid);
|
||||
Serial.println(uid, HEX);
|
||||
Serial.print("compareUID4:\t ");
|
||||
Serial.println(ds24.compareUID4(&uid));
|
||||
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -23,7 +23,7 @@
|
||||
"version": "^2.3.5"
|
||||
}
|
||||
],
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DS2401
|
||||
version=0.1.1
|
||||
version=0.1.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for 1-Wire DS2401 UID restricted to a single device per pin.
|
||||
|
Loading…
Reference in New Issue
Block a user