Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.idea
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# BlueRobotics_KellerLD_Library

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

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.
See the [Keller Communication Protocol 4LD-9LD][com] document for more details
on the I²C communication protocol, and the [Keller 4LD-9LD
Datasheet][datasheet] for sensor specification details.

[com]: http://www.keller-druck2.ch/swupdate/InstallerD-LineAddressManager/manual/Communication_Protocol_4LD-9LD_en.pdf
[datasheet]: https://download.keller-druck.com/api/download/2LfcGMzMbeHdjFbyUd5DWA/en/latest

## Changelog

* `2.0.0`
* Allow user-defined I²C address for the sensor
* Calibration date fields renamed to `calibration{Year,Month,Day}`
* `1.1.2` (2022-02-16)
* Fix pressure calculation; all sensors were treated as PAA
* `1.1.1` (2021-07-01)
* Add P-mode pressure offset handling for PR, PA and PAA type sensors,
auto-determined based on sensor mode
* Add support to read out the calibration date
* `1.0.0` (2017-08-31)
* Initial release.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=BlueRobotics Keller LD Library
version=1.1.2
version=2.0.0
author=BlueRobotics
maintainer=BlueRobotics <info@bluerobotics.com>
sentence=A simple and easy library for the Keller LD series pressure/depth sensors
Expand Down
15 changes: 15 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html


[env:promini]
platform = atmelavr
board = pro8MHzatmega328
framework = arduino

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is also not necessary.

43 changes: 22 additions & 21 deletions KellerLD.cpp → src/KellerLD.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "KellerLD.h"
#include <Wire.h>

#define LD_ADDR 0x40
#define LD_DEFAULT_ADDR 0x40
#define LD_REQUEST 0xAC
#define LD_CUST_ID0 0x00
#define LD_CUST_ID1 0x01
Expand All @@ -11,8 +11,9 @@
#define LD_SCALING3 0x15
#define LD_SCALING4 0x16

KellerLD::KellerLD() {
fluidDensity = 1029;

KellerLD::KellerLD(int i2cAddress = LD_DEFAULT_ADDR)
: i2cAddress(i2cAddress) {
}

void KellerLD::init() {
Expand All @@ -29,10 +30,10 @@ void KellerLD::init() {
scaling0 = readMemoryMap(LD_SCALING0);

mode = scaling0 & 0b00000011;
year = scaling0 >> 11;
month = (scaling0 & 0b0000011110000000) >> 7;
day = (scaling0 & 0b0000000001111100) >> 2;
calibrationYear = scaling0 >> 11;
calibrationMonth = (scaling0 & 0b0000011110000000) >> 7;
calibrationDay = (scaling0 & 0b0000000001111100) >> 2;

// handle P-mode pressure offset (to vacuum pressure)

if (mode == 0) {
Expand All @@ -51,11 +52,11 @@ void KellerLD::init() {

uint32_t scaling12 = (uint32_t(readMemoryMap(LD_SCALING1)) << 16) | readMemoryMap(LD_SCALING2);

P_min = *reinterpret_cast<float*>(&scaling12);
P_min = *reinterpret_cast<float *>(&scaling12);

uint32_t scaling34 = (uint32_t(readMemoryMap(LD_SCALING3)) << 16) | readMemoryMap(LD_SCALING4);

P_max = *reinterpret_cast<float*>(&scaling34);
P_max = *reinterpret_cast<float *>(&scaling34);
}

void KellerLD::setFluidDensity(float density) {
Expand All @@ -65,61 +66,61 @@ void KellerLD::setFluidDensity(float density) {
void KellerLD::read() {
uint8_t status;

Wire.beginTransmission(LD_ADDR);
Wire.beginTransmission(i2cAddress);
Wire.write(LD_REQUEST);
Wire.endTransmission();

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

Wire.requestFrom(LD_ADDR,5);
Wire.requestFrom(i2cAddress, 5);
status = Wire.read();
P = (Wire.read() << 8) | Wire.read();
uint16_t T = (Wire.read() << 8) | Wire.read();
P_bar = (float(P)-16384)*(P_max-P_min)/32768 + P_min + P_mode;
T_degc = ((T>>4)-24)*0.05-50;

P_bar = (float(P) - 16384) * (P_max - P_min) / 32768 + P_min + P_mode;
T_degc = ((T >> 4) - 24) * 0.05 - 50;
}

uint16_t KellerLD::readMemoryMap(uint8_t mtp_address) {
uint8_t status;

Wire.beginTransmission(LD_ADDR);
Wire.beginTransmission(i2cAddress);
Wire.write(mtp_address);
Wire.endTransmission();

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

Wire.requestFrom(LD_ADDR,3);
Wire.requestFrom(i2cAddress, 3);
status = Wire.read();
return ((Wire.read() << 8) | Wire.read());
}

bool KellerLD::status() {
if (equipment <= 62 ) {
if (equipment <= 62) {
return true;
} else {
return false;
}
}

float KellerLD::range() {
return P_max-P_min;
return P_max - P_min;
}

float KellerLD::pressure(float conversion) {
return P_bar*1000.0f*conversion;
return P_bar * 1000.0f * conversion;
}

float KellerLD::temperature() {
return T_degc;
}

float KellerLD::depth() {
return (pressure(KellerLD::Pa)-101325)/(fluidDensity*9.80665);
return (pressure(KellerLD::Pa) - 101325) / (fluidDensity * 9.80665);
}

float KellerLD::altitude() {
return (1-pow((pressure()/1013.25),0.190284))*145366.45*.3048;
return (1 - pow((pressure() / 1013.25), 0.190284)) * 145366.45 * .3048;
}

bool KellerLD::isInitialized() {
Expand Down
14 changes: 9 additions & 5 deletions KellerLD.h → src/KellerLD.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class KellerLD {

KellerLD();

explicit KellerLD(int i2cAddress);

/** Reads the onboard memory map to determine min and max pressure as
* well as manufacture date, mode, and customer ID.
*/
Expand All @@ -59,7 +61,7 @@ class KellerLD {
*/
void read();

/** Checks if the attached sensor is connectored or not. */
/** Checks if the attached sensor is connected or not. */
bool status();

/** Returns current range of the attached sensor. */
Expand Down Expand Up @@ -90,9 +92,9 @@ class KellerLD {
uint16_t file;

uint8_t mode;
uint16_t year;
uint8_t month;
uint8_t day;
uint16_t calibrationYear;
uint8_t calibrationMonth;
uint8_t calibrationDay;

uint32_t code;

Expand All @@ -103,13 +105,15 @@ class KellerLD {
float P_max;

private:
float fluidDensity;
float fluidDensity = 1029;
float T_degc;

uint16_t cust_id0;
uint16_t cust_id1;

uint16_t readMemoryMap(uint8_t mtp_address);

const int i2cAddress;
};

#endif
10 changes: 10 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Arduino.h"
#include "KellerLD.h"

KellerLD sensor(0x61);

void setup() {
}

void loop() {
}