ij96 / Honeywell_ABP

Arduino library for communication with Honeywell ABP Series digital pressure sensors via I2C
MIT License
9 stars 5 forks source link

Add temperature read feature from Honeywell #4

Closed caiosignor closed 2 years ago

caiosignor commented 3 years ago

Some sensors have the temperature outputs available to software read from i2c bus; See the datasheet page 5 for more details.

So, with this pr, your library can read the pressure and temperature from honeywell sensors.

Main changes

example/example.ino:12

void setup() {
  ...
  Serial.print(" ");
  Serial.print("Temperature: ");
  Serial.print(abp.temperature());
  Serial.println(" ºC ");
}

src/Honeywell_ABP.cpp:27

void Honeywell_ABP::update() {
 + Wire.requestFrom(_address, (uint8_t)4);
  while (Wire.available())
  {
    uint8_t data_byte_1 = Wire.read();
    uint8_t data_byte_2 = Wire.read();
   + uint8_t data_byte_3 = Wire.read();
   + uint8_t data_byte_4 = Wire.read();
    _status = Honeywell_ABP::Status(data_byte_1 >> 6);
    _bridge_data = (data_byte_1 << 8 | data_byte_2) & 0x3FFF;
   + _temperature_data = ((data_byte_3 << 8) | (data_byte_4)) >> 5;
  }
  _pressure = raw_to_pressure(_bridge_data);
  + _temperature = raw_to_temperature(_temperature_data);
}

src/Honeywell_ABP.cpp:87

float Honeywell_ABP::raw_to_temperature(uint16_t output) {
  return (output * 0.0977) - 50;
}
ij96 commented 2 years ago

Thank you very much for your contribution! I don't have a sensor to test out temperature reading, but your code looks good.