Skip to content

Commit a52ee39

Browse files
authored
Merge pull request #8 from awatterott/add-temperature
Add temperature reading
2 parents caec7ab + 98522c0 commit a52ee39

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

examples/ReadPressure/ReadPressure.ino

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
LPS22HB - Read Pressure
33
44
This example reads data from the on-board LPS22HB sensor of the
5-
Nano 33 BLE Sense and prints the pressure sensor value to the
6-
Serial Monitor once a second.
5+
Nano 33 BLE Sense and prints the temperature and pressure sensor
6+
value to the Serial Monitor once a second.
77
88
The circuit:
99
- Arduino Nano 33 BLE Sense
@@ -32,6 +32,13 @@ void loop() {
3232
Serial.print(pressure);
3333
Serial.println(" kPa");
3434

35+
float temperature = BARO.readTemperature();
36+
37+
// print the sensor value
38+
Serial.print("Temperature = ");
39+
Serial.print(temperature);
40+
Serial.println(" C");
41+
3542
// print an empty line
3643
Serial.println();
3744

examples/ReadPressureImperial/ReadPressureImperial.ino

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
LPS22HB - Read Pressure Imperial
33
44
This example reads data from the on-board LPS22HB sensor of the
5-
Nano 33 BLE Sense and prints the pressure sensor value in imperial
6-
units to the Serial Monitor once a second.
5+
Nano 33 BLE Sense and prints the temperature and pressure sensor
6+
value in imperial units to the Serial Monitor once a second.
77
88
The circuit:
99
- Arduino Nano 33 BLE Sense
@@ -33,6 +33,13 @@ void loop() {
3333
Serial.print(pressure);
3434
Serial.println(" psi");
3535

36+
float temperature = BARO.readTemperature();
37+
38+
// print the sensor value
39+
Serial.print("Temperature = ");
40+
Serial.print(temperature);
41+
Serial.println(" C");
42+
3643
// print an empty line
3744
Serial.println();
3845

src/BARO.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define LPS22HB_PRESS_OUT_XL_REG 0x28
3030
#define LPS22HB_PRESS_OUT_L_REG 0x29
3131
#define LPS22HB_PRESS_OUT_H_REG 0x2a
32+
#define LPS22HB_TEMP_OUT_L_REG 0x2b
33+
#define LPS22HB_TEMP_OUT_H_REG 0x2c
3234

3335
LPS22HBClass::LPS22HBClass(TwoWire& wire) :
3436
_wire(&wire),
@@ -81,6 +83,14 @@ float LPS22HBClass::readPressure(int units)
8183
return 0;
8284
}
8385

86+
float LPS22HBClass::readTemperature(void)
87+
{
88+
float reading = (i2cRead(LPS22HB_TEMP_OUT_L_REG) << 0) |
89+
(i2cRead(LPS22HB_TEMP_OUT_H_REG) << 8);
90+
91+
return reading/100;
92+
}
93+
8494
int LPS22HBClass::i2cRead(uint8_t reg)
8595
{
8696
_wire->beginTransmission(LPS22HB_ADDRESS);

src/BARO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class LPS22HBClass {
3737
void end();
3838

3939
float readPressure(int units = KILOPASCAL);
40+
float readTemperature(void);
4041

4142
private:
4243
int i2cRead(uint8_t reg);

0 commit comments

Comments
 (0)