Skip to content

Add temperature reading #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2021
Merged
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
11 changes: 9 additions & 2 deletions examples/ReadPressure/ReadPressure.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
LPS22HB - Read Pressure

This example reads data from the on-board LPS22HB sensor of the
Nano 33 BLE Sense and prints the pressure sensor value to the
Serial Monitor once a second.
Nano 33 BLE Sense and prints the temperature and pressure sensor
value to the Serial Monitor once a second.

The circuit:
- Arduino Nano 33 BLE Sense
Expand Down Expand Up @@ -32,6 +32,13 @@ void loop() {
Serial.print(pressure);
Serial.println(" kPa");

float temperature = BARO.readTemperature();

// print the sensor value
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" C");

// print an empty line
Serial.println();

Expand Down
11 changes: 9 additions & 2 deletions examples/ReadPressureImperial/ReadPressureImperial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
LPS22HB - Read Pressure Imperial

This example reads data from the on-board LPS22HB sensor of the
Nano 33 BLE Sense and prints the pressure sensor value in imperial
units to the Serial Monitor once a second.
Nano 33 BLE Sense and prints the temperature and pressure sensor
value in imperial units to the Serial Monitor once a second.

The circuit:
- Arduino Nano 33 BLE Sense
Expand Down Expand Up @@ -33,6 +33,13 @@ void loop() {
Serial.print(pressure);
Serial.println(" psi");

float temperature = BARO.readTemperature();

// print the sensor value
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" C");

// print an empty line
Serial.println();

Expand Down
10 changes: 10 additions & 0 deletions src/BARO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#define LPS22HB_PRESS_OUT_XL_REG 0x28
#define LPS22HB_PRESS_OUT_L_REG 0x29
#define LPS22HB_PRESS_OUT_H_REG 0x2a
#define LPS22HB_TEMP_OUT_L_REG 0x2b
#define LPS22HB_TEMP_OUT_H_REG 0x2c

LPS22HBClass::LPS22HBClass(TwoWire& wire) :
_wire(&wire)
Expand Down Expand Up @@ -75,6 +77,14 @@ float LPS22HBClass::readPressure(int units)
}
}

float LPS22HBClass::readTemperature(void)
{
float reading = (i2cRead(LPS22HB_TEMP_OUT_L_REG) << 0) |
(i2cRead(LPS22HB_TEMP_OUT_H_REG) << 8);

return reading/100;
}

int LPS22HBClass::i2cRead(uint8_t reg)
{
_wire->beginTransmission(LPS22HB_ADDRESS);
Expand Down
1 change: 1 addition & 0 deletions src/BARO.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LPS22HBClass {
void end();

float readPressure(int units = KILOPASCAL);
float readTemperature(void);

private:
int i2cRead(uint8_t reg);
Expand Down