Skip to content

Commit de5c245

Browse files
committed
Allow custom I²C address, rename calibration date variables
1 parent 320035a commit de5c245

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# BlueRobotics_KellerLD_Library
22

3-
Arduino library for the Keller 4LD - 9LD I2C pressure and temperature sensors; used in the Bar100 Sensor from Blue Robotics.
3+
Arduino library for the Keller 4LD to 9LD I²C pressure and temperature sensors;
4+
used in the Bar100 Sensor from Blue Robotics.
45

5-
See the [Keller Communication Protocol 4LD-9LD](http://www.keller-druck2.ch/swupdate/InstallerD-LineAddressManager/manual/Communication_Protocol_4LD-9LD_en.pdf) document for more details on the I<sup>2</sup>C communication protocol, and the [Keller 4LD-9LD Datasheet](https://download.keller-druck.com/api/download/2LfcGMzMbeHdjFbyUd5DWA/en/latest) for sensor specification details.
6+
See the [Keller Communication Protocol 4LD-9LD][com] document for more details
7+
on the I²C communication protocol, and the [Keller 4LD-9LD
8+
Datasheet][datasheet] for sensor specification details.
9+
10+
[com]: http://www.keller-druck2.ch/swupdate/InstallerD-LineAddressManager/manual/Communication_Protocol_4LD-9LD_en.pdf
11+
[datasheet]: https://download.keller-druck.com/api/download/2LfcGMzMbeHdjFbyUd5DWA/en/latest
12+
13+
## Changelog
14+
15+
* `2.0.0`
16+
* Allow user-defined I²C address for the sensor
17+
* Calibration date fields renamed to `calibration{Year,Month,Day}`
18+
* `1.1.0` (2021-07-01)
19+
* Add P-mode pressure offset handling for PR, PA and PAA type sensors,
20+
auto-determined based on sensor mode
21+
* Add support to read out the calibration date
22+
* `1.0.0` (2017-08-31)
23+
* Initial release.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=BlueRobotics Keller LD Library
2-
version=1.1.1
2+
version=2.0.0
33
author=BlueRobotics
44
maintainer=BlueRobotics <[email protected]>
55
sentence=A simple and easy library for the Keller LD series pressure/depth sensors

src/KellerLD.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "KellerLD.h"
22
#include <Wire.h>
33

4-
#define LD_ADDR 0x40
4+
#define LD_DEFAULT_ADDR 0x40
55
#define LD_REQUEST 0xAC
66
#define LD_CUST_ID0 0x00
77
#define LD_CUST_ID1 0x01
@@ -11,8 +11,13 @@
1111
#define LD_SCALING3 0x15
1212
#define LD_SCALING4 0x16
1313

14-
KellerLD::KellerLD() {
15-
fluidDensity = 1029;
14+
15+
KellerLD::KellerLD()
16+
: i2cAddress(LD_DEFAULT_ADDR) {
17+
}
18+
19+
KellerLD::KellerLD(int i2cAddress)
20+
: i2cAddress(i2cAddress) {
1621
}
1722

1823
void KellerLD::init() {
@@ -29,12 +34,11 @@ void KellerLD::init() {
2934
scaling0 = readMemoryMap(LD_SCALING0);
3035

3136
mode = scaling0 & 0b00000011;
32-
year = scaling0 >> 11;
33-
month = (scaling0 & 0b0000011110000000) >> 7;
34-
day = (scaling0 & 0b0000000001111100) >> 2;
37+
calibrationYear = scaling0 >> 11;
38+
calibrationMonth = (scaling0 & 0b0000011110000000) >> 7;
39+
calibrationDay = (scaling0 & 0b0000000001111100) >> 2;
3540

3641
// handle P-mode pressure offset (to vacuum pressure)
37-
3842
if (mode == 0) {
3943
// PA mode, Vented Gauge. Zero at atmospheric pressure
4044
P_mode = 1.01325;
@@ -63,13 +67,13 @@ void KellerLD::setFluidDensity(float density) {
6367
void KellerLD::read() {
6468
uint8_t status;
6569

66-
Wire.beginTransmission(LD_ADDR);
70+
Wire.beginTransmission(i2cAddress);
6771
Wire.write(LD_REQUEST);
6872
Wire.endTransmission();
6973

7074
delay(9); // Max conversion time per datasheet
7175

72-
Wire.requestFrom(LD_ADDR, 5);
76+
Wire.requestFrom(i2cAddress, 5);
7377
status = Wire.read();
7478
P = (Wire.read() << 8) | Wire.read();
7579
uint16_t T = (Wire.read() << 8) | Wire.read();
@@ -81,13 +85,13 @@ void KellerLD::read() {
8185
uint16_t KellerLD::readMemoryMap(uint8_t mtp_address) {
8286
uint8_t status;
8387

84-
Wire.beginTransmission(LD_ADDR);
88+
Wire.beginTransmission(i2cAddress);
8589
Wire.write(mtp_address);
8690
Wire.endTransmission();
8791

8892
delay(1); // allow for response to come in
8993

90-
Wire.requestFrom(LD_ADDR, 3);
94+
Wire.requestFrom(i2cAddress, 3);
9195
status = Wire.read();
9296
return ((Wire.read() << 8) | Wire.read());
9397
}

src/KellerLD.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class KellerLD {
4545

4646
KellerLD();
4747

48+
explicit KellerLD(int i2cAddress);
49+
4850
/** Reads the onboard memory map to determine min and max pressure as
4951
* well as manufacture date, mode, and customer ID.
5052
*/
@@ -90,9 +92,9 @@ class KellerLD {
9092
uint16_t file;
9193

9294
uint8_t mode;
93-
uint16_t year;
94-
uint8_t month;
95-
uint8_t day;
95+
uint16_t calibrationYear;
96+
uint8_t calibrationMonth;
97+
uint8_t calibrationDay;
9698

9799
uint32_t code;
98100

@@ -103,7 +105,7 @@ class KellerLD {
103105
float P_max;
104106

105107
private:
106-
float fluidDensity;
108+
float fluidDensity = 1029;
107109
float T_degc;
108110

109111
uint16_t cust_id0;

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Arduino.h"
22
#include "KellerLD.h"
33

4-
KellerLD sensor;
4+
KellerLD sensor(0x61);
55

66
void setup() {
77
}

0 commit comments

Comments
 (0)