File tree Expand file tree Collapse file tree 4 files changed +29
-4
lines changed
Expand file tree Collapse file tree 4 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
3335LPS22HBClass::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+
8494int LPS22HBClass::i2cRead (uint8_t reg)
8595{
8696 _wire->beginTransmission (LPS22HB_ADDRESS);
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ class LPS22HBClass {
3737 void end ();
3838
3939 float readPressure (int units = KILOPASCAL);
40+ float readTemperature (void );
4041
4142private:
4243 int i2cRead (uint8_t reg);
You can’t perform that action at this time.
0 commit comments