Skip to content

Commit 3791d19

Browse files
committed
add examples
1 parent 137da10 commit 3791d19

10 files changed

+598
-1
lines changed

.github/ISSUE_TEMPLATE.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Thank you for opening an issue on an Adafruit Arduino library repository. To
2+
improve the speed of resolution please review the following guidelines and
3+
common troubleshooting steps below before creating the issue:
4+
5+
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
6+
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
7+
something isn't working as expected. In many cases the problem is a common issue
8+
that you will more quickly receive help from the forum community. GitHub issues
9+
are meant for known defects in the code. If you don't know if there is a defect
10+
in the code then start with troubleshooting on the forum first.
11+
12+
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
13+
check all of the steps and commands to run have been followed. Consult the
14+
forum if you're unsure or have questions about steps in a guide/tutorial.
15+
16+
- **For Arduino projects check these very common issues to ensure they don't apply**:
17+
18+
- For uploading sketches or communicating with the board make sure you're using
19+
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
20+
very hard to tell the difference between a data and charge cable! Try using the
21+
cable with other devices or swapping to another cable to confirm it is not
22+
the problem.
23+
24+
- **Be sure you are supplying adequate power to the board.** Check the specs of
25+
your board and plug in an external power supply. In many cases just
26+
plugging a board into your computer is not enough to power it and other
27+
peripherals.
28+
29+
- **Double check all soldering joints and connections.** Flakey connections
30+
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
31+
32+
- **Ensure you are using an official Arduino or Adafruit board.** We can't
33+
guarantee a clone board will have the same functionality and work as expected
34+
with this code and don't support them.
35+
36+
If you're sure this issue is a defect in the code and checked the steps above
37+
please fill in the following fields to provide enough troubleshooting information.
38+
You may delete the guideline and text above to just leave the following details:
39+
40+
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
41+
42+
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
43+
VERSION HERE**
44+
45+
- List the steps to reproduce the problem below (if possible attach a sketch or
46+
copy the sketch code in too): **LIST REPRO STEPS BELOW**

.github/PULL_REQUEST_TEMPLATE.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
2+
Before you open the request please review the following guidelines and tips to
3+
help it be more easily integrated:
4+
5+
- **Describe the scope of your change--i.e. what the change does and what parts
6+
of the code were modified.** This will help us understand any risks of integrating
7+
the code.
8+
9+
- **Describe any known limitations with your change.** For example if the change
10+
doesn't apply to a supported platform of the library please mention it.
11+
12+
- **Please run any tests or examples that can exercise your modified code.** We
13+
strive to not break users of the code and running tests/examples helps with this
14+
process.
15+
16+
Thank you again for contributing! We will try to test and integrate the change
17+
as soon as we can, but be aware we have many GitHub repositories to manage and
18+
can't immediately respond to every request. There is no need to bump or check in
19+
on a pull request (it will clutter the discussion of the request).
20+
21+
Also don't be worried if the request is closed or not integrated--sometimes the
22+
priorities of Adafruit's GitHub code (education, ease of use) might not match the
23+
priorities of the pull request. Don't fret, the open source community thrives on
24+
forks and GitHub makes it easy to keep your changes in a forked repo.
25+
26+
After reviewing the guidelines above you can delete this text from the pull request.

.github/workflows/githubci.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Arduino Library CI
2+
3+
on: [pull_request, push, repository_dispatch]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/setup-python@v4
11+
with:
12+
python-version: '3.x'
13+
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v3
15+
with:
16+
repository: adafruit/ci-arduino
17+
path: ci
18+
19+
- name: pre-install
20+
run: bash ci/actions_install.sh
21+
22+
- name: test platforms
23+
run: python3 ci/build_platform.py main_platforms
24+
25+
- name: clang
26+
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
27+
28+
- name: doxygen
29+
env:
30+
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
31+
PRETTYNAME : "Adafruit LPS28 Barometric Pressure Sensor Library"
32+
run: bash ci/doxy_gen_and_deploy.sh

Adafruit_LPS28.cpp

+137
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ bool Adafruit_LPS28::setFullScaleMode(bool mode) {
5858
return fs_mode_bit.write(mode);
5959
}
6060

61+
bool Adafruit_LPS28::getFullScaleMode() {
62+
Adafruit_BusIO_Register ctrl_reg2(i2c_dev, LPS28_CTRL_REG2, 1);
63+
Adafruit_BusIO_RegisterBits fs_mode_bit(&ctrl_reg2, 1, 6); // FS_MODE bit is bit 6
64+
return fs_mode_bit.read();
65+
}
66+
6167
bool Adafruit_LPS28::setLowPassODR9(bool enable) {
6268
Adafruit_BusIO_Register ctrl_reg2(i2c_dev, LPS28_CTRL_REG2, 1);
6369
Adafruit_BusIO_RegisterBits lpfp_cfg_bit(&ctrl_reg2, 1, 5);
@@ -138,3 +144,134 @@ bool Adafruit_LPS28::setPressureInterrupt(bool low, bool high, bool latching) {
138144
Adafruit_BusIO_RegisterBits lir_bit(&interrupt_cfg, 1, 3);
139145
return phe_bit.write(high) && ple_bit.write(low) && lir_bit.write(latching);
140146
}
147+
148+
149+
bool Adafruit_LPS28::setIntPinOutput(bool drdy, bool drdy_pulse, bool int_enable,
150+
bool fifo_full, bool fifo_watermark, bool fifo_overrun) {
151+
Adafruit_BusIO_Register ctrl_reg4(i2c_dev, LPS28_CTRL_REG4, 1);
152+
153+
Adafruit_BusIO_RegisterBits drdy_pulse_bit(&ctrl_reg4, 1, 6); // Bit 6: DRDY_PLS
154+
Adafruit_BusIO_RegisterBits drdy_bit(&ctrl_reg4, 1, 5); // Bit 5: DRDY
155+
Adafruit_BusIO_RegisterBits int_enable_bit(&ctrl_reg4, 1, 4); // Bit 4: INT_EN
156+
Adafruit_BusIO_RegisterBits fifo_full_bit(&ctrl_reg4, 1, 2); // Bit 2: INT_F_FULL
157+
Adafruit_BusIO_RegisterBits fifo_watermark_bit(&ctrl_reg4, 1, 1); // Bit 1: INT_F_WTM
158+
Adafruit_BusIO_RegisterBits fifo_overrun_bit(&ctrl_reg4, 1, 0); // Bit 0: INT_F_OVR
159+
160+
bool drdy_pulse_ok = drdy_pulse_bit.write(drdy_pulse);
161+
bool drdy_ok = drdy_bit.write(drdy);
162+
bool int_enable_ok = int_enable_bit.write(int_enable);
163+
bool fifo_full_ok = fifo_full_bit.write(fifo_full);
164+
bool fifo_watermark_ok = fifo_watermark_bit.write(fifo_watermark);
165+
bool fifo_overrun_ok = fifo_overrun_bit.write(fifo_overrun);
166+
167+
return drdy_pulse_ok && drdy_ok && int_enable_ok &&
168+
fifo_full_ok && fifo_watermark_ok && fifo_overrun_ok;
169+
}
170+
171+
172+
bool Adafruit_LPS28::setFIFOmode(bool stop_on_watermark, lps28_fifo_mode_t mode) {
173+
Adafruit_BusIO_Register fifo_ctrl(i2c_dev, LPS28_FIFO_CTRL, 1);
174+
175+
Adafruit_BusIO_RegisterBits stop_on_wtm_bit(&fifo_ctrl, 1, 3); // Bit 3: STOP_ON_WTM
176+
Adafruit_BusIO_RegisterBits f_mode_bits(&fifo_ctrl, 3, 0); // Bits 2:0 (F_MODE[2:0])
177+
178+
bool stop_ok = stop_on_wtm_bit.write(stop_on_watermark);
179+
bool mode_ok = f_mode_bits.write(mode);
180+
181+
return stop_ok && mode_ok;
182+
}
183+
184+
185+
bool Adafruit_LPS28::setFIFOWatermark(uint8_t wtm) {
186+
Adafruit_BusIO_Register fifo_wtm(i2c_dev, LPS28_FIFO_WTM, 1);
187+
return fifo_wtm.write(wtm);
188+
}
189+
190+
uint8_t Adafruit_LPS28::getFIFOWatermark() {
191+
Adafruit_BusIO_Register fifo_wtm(i2c_dev, LPS28_FIFO_WTM, 1);
192+
return fifo_wtm.read();
193+
}
194+
195+
196+
int16_t Adafruit_LPS28::getReferencePressure() {
197+
Adafruit_BusIO_Register ref_p(i2c_dev, LPS28_REF_P, 2, LSBFIRST);
198+
return ref_p.read();
199+
}
200+
201+
bool Adafruit_LPS28::setPressureOffset(int16_t offset) {
202+
Adafruit_BusIO_Register rpds(i2c_dev, LPS28_RPDS, 2, LSBFIRST);
203+
return rpds.write(offset);
204+
}
205+
206+
int16_t Adafruit_LPS28::getPressureOffset() {
207+
Adafruit_BusIO_Register rpds(i2c_dev, LPS28_RPDS, 2, LSBFIRST);
208+
return rpds.read();
209+
}
210+
211+
212+
uint8_t Adafruit_LPS28::getIntSource() {
213+
Adafruit_BusIO_Register int_source(i2c_dev, LPS28_INT_SOURCE, 1);
214+
return int_source.read();
215+
}
216+
217+
uint8_t Adafruit_LPS28::getFIFOunreadSamples() {
218+
Adafruit_BusIO_Register fifo_status1(i2c_dev, LPS28_FIFO_STATUS1, 1);
219+
return fifo_status1.read();
220+
}
221+
222+
uint8_t Adafruit_LPS28::getStatus() {
223+
Adafruit_BusIO_Register status_reg(i2c_dev, LPS28_STATUS, 1);
224+
return status_reg.read();
225+
}
226+
227+
228+
229+
float Adafruit_LPS28::getPressure() {
230+
// Read the 3-byte PRESS_OUT register
231+
Adafruit_BusIO_Register pressure_out(i2c_dev, LPS28_PRESS_OUT, 3, LSBFIRST);
232+
int32_t raw_pressure = pressure_out.read();
233+
234+
// Get full-scale mode using the getter
235+
bool fs_mode = getFullScaleMode();
236+
237+
// Convert raw pressure value to hPa based on FS_MODE
238+
float pressure_hpa;
239+
if (fs_mode) {
240+
pressure_hpa = raw_pressure / 2048.0; // FS_MODE = 1, 1 LSB = 1/2048 hPa
241+
} else {
242+
pressure_hpa = raw_pressure / 4096.0; // FS_MODE = 0, 1 LSB = 1/4096 hPa
243+
}
244+
245+
return pressure_hpa;
246+
}
247+
248+
249+
float Adafruit_LPS28::getTemperature() {
250+
// Read the 2-byte TEMP_OUT register (signed 16-bit, 2's complement)
251+
Adafruit_BusIO_Register temp_out(i2c_dev, LPS28_TEMP_OUT, 2, LSBFIRST);
252+
int16_t raw_temperature = (int16_t)temp_out.read();
253+
254+
// Convert raw temperature to degrees Celsius
255+
float temperature_celsius = raw_temperature * 0.01; // 1 LSB = 0.01 °C
256+
257+
return temperature_celsius;
258+
}
259+
260+
float Adafruit_LPS28::getFIFOpressure() {
261+
// Read the 3-byte FIFO_DATA_OUT_PRESS_XL register
262+
Adafruit_BusIO_Register fifo_pressure_out(i2c_dev, LPS28_FIFO_DATA_OUT_PRESS_XL, 3, LSBFIRST);
263+
int32_t raw_pressure = fifo_pressure_out.read();
264+
265+
// Get full-scale mode using the getter
266+
bool fs_mode = getFullScaleMode();
267+
268+
// Convert raw pressure value to hPa based on FS_MODE
269+
float pressure_hpa;
270+
if (fs_mode) {
271+
pressure_hpa = raw_pressure / 2048.0; // FS_MODE = 1, 1 LSB = 1/2048 hPa
272+
} else {
273+
pressure_hpa = raw_pressure / 4096.0; // FS_MODE = 0, 1 LSB = 1/4096 hPa
274+
}
275+
276+
return pressure_hpa;
277+
}

Adafruit_LPS28.h

+66-1
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,48 @@
66
#include <Adafruit_BusIO_Register.h>
77

88
// I2C Address and Register Definitions
9-
#define LPS28_DEFAULT_ADDRESS (0x5D) ///< Default I2C address
9+
#define LPS28_DEFAULT_ADDRESS (0x5C) ///< Default I2C address
1010
#define LPS28_WHOAMI_REG 0x0F ///< WHO_AM_I register
1111
#define LPS28_WHOAMI_EXPECTED 0xB4 ///< Expected WHO_AM_I value
1212

1313
#define LPS28_THS_P 0x0C ///< Threshold Pressure (2 bytes)
1414
#define LPS28_CTRL_REG1 0x10 ///< Control Register 1 (ODR and AVG)
1515
#define LPS28_CTRL_REG2 0x11 ///< Control Register 2
1616
#define LPS28_CTRL_REG3 0x12 ///< Control Register 3 (Interrupt config)
17+
#define LPS28_CTRL_REG4 0x13 ///< Control Register 4
1718
#define LPS28_INTERRUPT_CFG 0x0B ///< Interrupt Configuration Register
1819
#define LPS28_IF_CTRL 0x0E ///< Interface Control Register
20+
#define LPS28_FIFO_CTRL 0x14 ///< FIFO Control Register
21+
#define LPS28_FIFO_WTM 0x15 ///< FIFO Watermark Register
22+
#define LPS28_REF_P 0x16 ///< Reference Pressure Register (2 bytes)
23+
#define LPS28_RPDS 0x18 ///< RPDS Register (Pressure Offset, 2 bytes)
24+
#define LPS28_INT_SOURCE 0x24 ///< INT_SOURCE Register
25+
#define LPS28_FIFO_STATUS1 0x25 ///< FIFO_STATUS1 Register
26+
#define LPS28_FIFO_STATUS2 0x26 ///< FIFO_STATUS2 Register
27+
#define LPS28_STATUS 0x27 ///< STATUS Register
28+
#define LPS28_PRESS_OUT 0x28 ///< PRESS_OUT Register (3 bytes)
29+
#define LPS28_TEMP_OUT 0x2B ///< TEMP_OUT Register (2 bytes)
30+
#define LPS28_FIFO_DATA_OUT_PRESS_XL 0x78 ///< FIFO_DATA_OUT_PRESS_XL Register (3 bytes)
31+
32+
33+
34+
// STATUS flags
35+
#define LPS28_STATUS_TEMP_OVERRUN 0x20 ///< Temperature data overrun (bit 5)
36+
#define LPS28_STATUS_PRESS_OVERRUN 0x10 ///< Pressure data overrun (bit 4)
37+
#define LPS28_STATUS_TEMP_READY 0x02 ///< Temperature data available (bit 1)
38+
#define LPS28_STATUS_PRESS_READY 0x01 ///< Pressure data available (bit 0)
39+
40+
// FIFO_STATUS2 flags
41+
#define LPS28_FIFO_STATUS_WTM_IA 0x80 ///< FIFO Watermark interrupt active (bit 7)
42+
#define LPS28_FIFO_STATUS_OVR_IA 0x40 ///< FIFO Overrun interrupt active (bit 6)
43+
#define LPS28_FIFO_STATUS_FULL_IA 0x20 ///< FIFO Full interrupt active (bit 5)
44+
45+
// INT_SOURCE flags
46+
#define LPS28_INT_SOURCE_IA 0x20 ///< Interrupt Active flag (bit 5)
47+
#define LPS28_INT_SOURCE_PL 0x10 ///< Low pressure event flag (bit 4)
48+
#define LPS28_INT_SOURCE_PH 0x08 ///< High pressure event flag (bit 3)
49+
#define LPS28_INT_SOURCE_BOOT_ON 0x80 ///< Boot status flag (bit 7)
50+
1951

2052
// Output Data Rate (ODR) configuration (Table 19)
2153
typedef enum {
@@ -41,6 +73,19 @@ typedef enum {
4173
LPS28_AVG_512 = 0b111 ///< 512 samples
4274
} lps28_avg_t;
4375

76+
77+
// FIFO Mode Selection based on TRIG_MODE and F_MODE bits
78+
typedef enum {
79+
LPS28_FIFO_BYPASS = 0b00, ///< Bypass mode (F_MODE[1:0] = 00)
80+
LPS28_FIFO_FIFO = 0b01, ///< FIFO mode (TRIG = 0, F_MODE[1:0] = 01)
81+
LPS28_FIFO_CONTINUOUS = 0b10, ///< Continuous mode (TRIG = 0, F_MODE[1:0] = 1x)
82+
LPS28_FIFO_BYPASS_TO_FIFO = 0b101, ///< Bypass-to-FIFO mode (TRIG = 1, F_MODE[1:0] = 01)
83+
LPS28_FIFO_BYPASS_TO_CONTINUOUS = 0b110, ///< Bypass-to-Continuous mode (TRIG = 1, F_MODE[1:0] = 10)
84+
LPS28_FIFO_CONTINUOUS_TO_FIFO = 0b111 ///< Continuous-to-FIFO mode (TRIG = 1, F_MODE[1:0] = 11)
85+
} lps28_fifo_mode_t;
86+
87+
88+
4489
class Adafruit_LPS28 {
4590
public:
4691
Adafruit_LPS28();
@@ -62,12 +107,15 @@ class Adafruit_LPS28 {
62107
// CTRL_REG2 functions
63108
bool rebootMemory();
64109
bool setFullScaleMode(bool mode);
110+
bool getFullScaleMode();
65111
bool setLowPassODR9(bool enable);
66112
bool reset();
67113
bool triggerOneShot();
68114

69115
// Interrupt Configuration (CTRL_REG3) functions
70116
bool setInterruptPin(bool polarity, bool openDrain);
117+
bool setIntPinOutput(bool drdy, bool drdy_pulse, bool int_enable,
118+
bool fifo_full, bool fifo_watermark, bool fifo_overrun);
71119

72120
// Interface Control Register (IF_CTRL) functions
73121
bool setSDAPullup(bool enable);
@@ -78,11 +126,28 @@ class Adafruit_LPS28 {
78126
bool getAutoReferencePressure();
79127
bool resetAutoReferencePressure();
80128

129+
int16_t getReferencePressure();
130+
bool setPressureOffset(int16_t offset);
131+
int16_t getPressureOffset();
132+
81133
bool setAutoZero(bool enable);
82134
bool getAutoZero();
83135
bool resetAutoZero();
84136

85137
bool setPressureInterrupt(bool low, bool high, bool latching);
138+
uint8_t getIntSource();
139+
140+
// FIFO
141+
bool setFIFOWatermark(uint8_t wtm);
142+
uint8_t getFIFOWatermark();
143+
uint8_t getFIFOunreadSamples();
144+
uint8_t getFIFOstatus();
145+
bool setFIFOmode(bool stop_on_watermark, lps28_fifo_mode_t mode);
146+
147+
uint8_t getStatus();
148+
float getPressure();
149+
float getTemperature();
150+
float getFIFOpressure();
86151

87152
private:
88153
Adafruit_I2CDevice *i2c_dev = nullptr; ///< Pointer to I2C device interface

0 commit comments

Comments
 (0)