Skip to content

Commit 9eac02c

Browse files
authored
Merge pull request #1 from Kenneract/development
V1.0.0 Release
2 parents a5510cb + 22d2403 commit 9eac02c

File tree

9 files changed

+1090
-2
lines changed

9 files changed

+1090
-2
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
1-
# SPL07-003-Arduino-Library
2-
Arduino library for the SPL07-003 pressure/temperature sensor
1+
# SPL07-003 Arduino Library
2+
An Arduino library for interfacing with the SPL07-003 pressure & temperature sensor over I2C.
3+
4+
5+
<img src="docs/SPL07-003.jpg" width=350px>
6+
7+
## Introduction
8+
Recently I was looking for an inexpensive pressure + temperature sensor for a barometric altimeter project, which then led to me finding the SPL07-003. After learning there was no existing library to interface with it, I decided to make one myself.
9+
10+
I've written and tested this library on an STM32F103-based board using the STM32duino framework, though it should work fine on almost any platform. If you have any problems please open an [issue on GitHub](https://github.com/Kenneract/SPL07-003-Arduino-Library/issues).
11+
12+
Note: While the library was designed for the **SPL07-003**, with minor modifications to the coefficient parsing code it should work with similar sensors such as the **SPL06-001** or **SPL06-007**. *(The SPL06 series is also similar to the DPS310, in case you're looking for a potentially compatible library).*
13+
14+
15+
## Features
16+
- Set sensor to idle, single, or continuous measurement modes
17+
- Configure measurement rates (1Hz - 200Hz) and oversampling rates (1x - 128x) for both the pressure and temperature sensors
18+
- Read the most recent pressure or temperature readings with a single function call
19+
- Can apply a linear offset to pressure / temperature measurements
20+
- Configure interrupt pin function and polarity
21+
- Query the interrupt register to find what triggered any interrupts
22+
- Can accept a custom TwoWire object for unique I2C setups
23+
- Can accept a custom I2C address and `SENSOR_ID` for use with other compatible sensors
24+
25+
### Current Limitations
26+
- FIFO buffer usage is not available.
27+
- Only works via I2C, **cannot use SPI**.
28+
- Requires the host MCU support the `uint32_t` datatype.
29+
- *(This shouldn't be an issue in most cases)*
30+
31+
32+
## Usage
33+
Read the [docs.md](docs/docs.md) file for documentation, and find examples in the [examples](examples) directory.
34+
35+
36+
37+
## Installation
38+
39+
#### Through the Arduino Library Manager (pending)
40+
- Navigate to the Arduino Library Manager
41+
- Search for "SPL07-003"
42+
- Install latest version by Kenneract
43+
44+
#### Manual Installation
45+
- Download this repository as a ZIP file
46+
- Navigate to your Arduino library directory
47+
- On Windows this is often `.../documents/arduino/libraries/`
48+
- Create a folder named "SPL07-003" in your libraries folder
49+
- Extract the files inside the ZIP file into the "SPL07-003" folder

docs/SPL07-003.jpg

125 KB
Loading

docs/docs.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# SPL07-003 Library Documentation
2+
3+
This file contains documentation on how to use the SPL07-003 library.
4+
5+
## Prelude: Measurement & Oversampling
6+
7+
The SPL07-003 effectively functions as two different sensors (pressure + temperature), both of which can have their measurement rates and accuracy selected independently from each other.
8+
9+
Both the **measurement rate** (how many measurements are initiated per second) and the **oversampling rate** (how many samples are taken & averaged per measurement) can be configured for each element.
10+
11+
Care must be taken when selecting settings so that the total measurement cycle time does not exceed 1 second:
12+
13+
$$Rate_{(pres)} \times Time_{(pres)} + Rate_{(temp)} \times Time_{(temp)} < 1sec$$
14+
15+
Where the $Rate_{(pres)}$ and $Rate_{(temp)}$ are the measurement rates (`SPL07_Measure_Rates`), and $Time_{(pres)}$ and $Time_{(temp)}$ are how long each measurement takes, which is determined by their respective oversampling rates:
16+
17+
| Oversample Rate | $Time_{(pres)}$ | $Time_{(temp)}$ |
18+
| --- | --- | --- |
19+
|`SPL07_1SAMPLE`| 3.6ms | 3.6ms |
20+
|`SPL07_2SAMPLES`| 5.2ms | 5.2ms* |
21+
|`SPL07_4SAMPLES`| 8.4ms | 8.4ms* |
22+
|`SPL07_8SAMPLES`| 14.8ms | 14.8ms* |
23+
|`SPL07_16SAMPLES`| 27.6ms | 27.6ms* |
24+
|`SPL07_32SAMPLES`| 53.2ms | 53.2ms* |
25+
|`SPL07_64SAMPLES`| 104.4ms | 104.4ms* |
26+
|`SPL07_128SAMPLES`| 206.8ms | 206.8ms* |
27+
28+
<sup>\**Temperature measurement time is only specified for single-sample mode in the datasheet, but is assumed to be similar to that of the pressure sensor for other oversampling rates*</sup>
29+
30+
31+
Below are some example settings with their associated cycle times:
32+
33+
| Use Case | Pressure Config | Temperature Config | Cycle Time |
34+
| --- | --- | --- | --- |
35+
| Low power | `SPL07_1HZ`, `SPL07_2SAMPLES` | `SPL07_1HZ`, `SPL07_1SAMPLE` | ~8.8ms |
36+
| Standard precision | `SPL07_2HZ`, `SPL07_16SAMPLES` | `SPL07_1HZ`, `SPL07_1SAMPLE` | ~58.8ms |
37+
| High precision | `SPL07_4HZ`, `SPL07_64SAMPLES` | `SPL07_4HZ`, `SPL07_1SAMPLE` | ~432ms |
38+
39+
---
40+
41+
## SPL07_003 Class Functions
42+
Below are functions of the `SPL07_003` class:
43+
44+
🟣 `void reset()`
45+
- **Purpose:** Performs a software reset of the chip. Blocks until ready.
46+
- **Param:** None
47+
- **Returns:** None
48+
49+
---
50+
🟣 `bool begin(uint8_t addr, TwoWire *wire, uint8_t id)`
51+
- **Purpose:** Connects to and initializes the chip.
52+
- **Params:**
53+
54+
| Parameter | Comment |
55+
| -------- | -------- |
56+
| `addr` | Optional; I2C address of sensor. Defaults to `SPL07_ADDR_DEF`. Use `SPL07_ADDR_ALT` if SDO pin is pulled low.|
57+
| `*wire` | Optional; TwoWire interface to use. Defaults to `&Wire`.
58+
| `id` | Optional; Expected sensor ID, see SPL07-003 datasheet section 7.10. Defaults to `SPL07_EXPECTED_ID`. |
59+
60+
- **Returns:** `true` if connects to SPL07-003 and the sensor ID is correct, `false` otherwise.
61+
62+
63+
---
64+
🟣 `void setMode(SPL07_Modes mode)`
65+
- **Purpose:** Sets the operating mode of the SPL07-003.
66+
- **Params:**
67+
68+
| Parameter | Comment |
69+
| -------- | -------- |
70+
| `mode` | Options: `SPL07_IDLE`, `SPL07_ONE_PRESSURE`, `SPL07_ONE_TEMPERATURE`, `SPL07_CONT_PRESSURE`, `SPL07_CONT_TEMPERATURE`, `SPL07_CONT_PRES_TEMP`. |
71+
72+
- **Returns:** None
73+
74+
75+
---
76+
🟣 `void setPressureConfig(SPL07_Measure_Rates rate, SPL07_Oversample_Rates oversample)`
77+
- **Purpose:** Sets the measurement and oversampling rates for the pressure sensor. See note at top of document for selecting values.
78+
- **Params:**
79+
80+
| Parameter | Comment |
81+
| -------- | -------- |
82+
| `rate` | Options: `SPL07_1HZ`, `SPL07_2HZ`, `SPL07_4HZ`, `SPL07_8HZ`, `SPL07_16HZ`, `SPL07_32HZ`, `SPL07_64HZ`, `SPL07_128HZ`, `SPL07_25_16HZ`, `SPL07_25_8HZ`, `SPL07_25_4HZ`, `SPL07_25_2HZ`, `SPL07_25HZ`, `SPL07_50HZ`, `SPL07_100HZ`, `SPL07_200HZ`. |
83+
| `oversample` | Options: `SPL07_1SAMPLE`, `SPL07_2SAMPLES`, `SPL07_4SAMPLES`, `SPL07_8SAMPLES`, `SPL07_16SAMPLES`, `SPL07_32SAMPLES`, `SPL07_64SAMPLES`, `SPL07_128SAMPLES`. |
84+
85+
- **Returns:** None
86+
87+
---
88+
🟣 `void setTemperatureConfig(SPL07_Measure_Rates rate, SPL07_Oversample_Rates oversample)`
89+
- **Purpose:** Sets the measurement and oversampling rates for the temperature sensor. See note at top of document for selecting values.
90+
- **Params:**
91+
92+
| Parameter | Comment |
93+
| -------- | -------- |
94+
| `rate` | Options: `SPL07_1HZ`, `SPL07_2HZ`, `SPL07_4HZ`, `SPL07_8HZ`, `SPL07_16HZ`, `SPL07_32HZ`, `SPL07_64HZ`, `SPL07_128HZ`, `SPL07_25_16HZ`, `SPL07_25_8HZ`, `SPL07_25_4HZ`, `SPL07_25_2HZ`, `SPL07_25HZ`, `SPL07_50HZ`, `SPL07_100HZ`, `SPL07_200HZ`. |
95+
| `oversample` | Options: `SPL07_1SAMPLE`, `SPL07_2SAMPLES`, `SPL07_4SAMPLES`, `SPL07_8SAMPLES`, `SPL07_16SAMPLES`, `SPL07_32SAMPLES`, `SPL07_64SAMPLES`, `SPL07_128SAMPLES`. |
96+
97+
- **Returns:** None
98+
99+
100+
---
101+
🟣 `void setTemperatureSource(SPL07_Temperature_Source src)`
102+
- **Purpose:** Sets the temperature sensor source.
103+
- **Params:**
104+
105+
| Parameter | Comment |
106+
| -------- | -------- |
107+
| `src` | Options are `SPL07_TSRC_ASIC` for the default internal ASIC, or `SPL07_TSRC_MEMS` to use the temperature sensor on the MEMS unit, if available. |
108+
109+
- **Returns:** None
110+
111+
112+
---
113+
🟣 `void setInterruptActiveHigh(bool activeHigh)`
114+
- **Purpose:** Sets the polarity (active level) of the interrupt pin.
115+
- **Params:**
116+
117+
| Parameter | Comment |
118+
| -------- | -------- |
119+
| `activeHigh` | Set to `true` if SDO is pulled low, otherwise set `false`.|
120+
121+
- **Returns:** None
122+
123+
124+
---
125+
🟣 `void configureInterrupt(SPL07_Interrupt_Options opt)`
126+
- **Purpose:** Configures which actions/events should trigger and interrupt.
127+
- **Params:**
128+
129+
| Parameter | Comment |
130+
| -------- | -------- |
131+
| `opt` | Options: `SPL07_INT_OFF`, `SPL07_INT_PRES`, `SPL07_INT_TEMP`, `SPL07_INT_PRES_TEMP`, `SPL07_INT_FIFO`, `SPL07_INT_FIFO_PRES`, `SPL07_INT_FIFO_TEMP`, `SPL07_INT_ALL`.|
132+
133+
- **Returns:** None
134+
135+
136+
---
137+
🟣 `void getInterruptStatus()`
138+
- **Purpose:** Retrieves the interrupt status from the chip. Calling this will reset the interrupt value register.
139+
- **Params:** None
140+
- **Returns:** A `uint8_t` where the 3 least-significant bits represent interrupt flags. Bit 0 is Pressure Ready, Bit 1 is Temperature Ready, Bit 2 is FIFO full. See datasheet 7.7.
141+
142+
143+
---
144+
🟣 `void setPressureOffset(double offset)`
145+
- **Purpose:** Sets the linear pressure offset to apply during pressure calculation. By default the offset is 0.
146+
- **Params:**
147+
148+
| Parameter | Comment |
149+
| -------- | -------- |
150+
| `offset` | Offset in Pascals |
151+
152+
- **Returns:** None
153+
154+
155+
---
156+
🟣 `void setTemperatureOffset(double offset)`
157+
- **Purpose:** Sets the linear temperature offset to apply during temperature calculation. By default the offset is 0.
158+
- **Params:**
159+
160+
| Parameter | Comment |
161+
| -------- | -------- |
162+
| `offset` | Offset in degrees Celsius |
163+
164+
- **Returns:** None
165+
166+
167+
---
168+
🟣 `bool pressureAvailable()`
169+
- **Purpose:** Returns if fresh pressure data is available for reading.
170+
- **Params:** None
171+
- **Returns:** `true` if new pressure reading available, `false` otherwise.
172+
173+
174+
---
175+
🟣 `bool temperatureAvailable()`
176+
- **Purpose:** Returns if fresh temperature data is available for reading.
177+
- **Params:** None
178+
- **Returns:** `true` if new temperature reading available, `false` otherwise.
179+
180+
181+
---
182+
🟣 `double readPressure()`
183+
- **Purpose:** Fetches and converts the latest pressure reading from the sensor.
184+
- **Params:** None
185+
- **Returns:** Pressure in Pascals
186+
187+
188+
---
189+
🟣 `double readTemperature()`
190+
- **Purpose:** Fetches and converts the latest temperature reading from the sensor.
191+
- **Params:** None
192+
- **Returns:** Temperature in degrees Celsius
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Author: Kennan / Kenneract
3+
* GitHub: https://github.com/Kenneract/SPL07-003-Arduino-Library
4+
* Created: Mar.15.2025
5+
* Purpose: Example usage for the SPL07-003 sensor library. Connects
6+
* to the sensor, configures the measurement and oversampling
7+
* rate, sets the SPL07-003 to continuous sampling mode, then
8+
* prints pressure/temperature measurements to the serial monitor.
9+
*/
10+
11+
#include <Wire.h>
12+
#include "SPL07_003.h"
13+
14+
// Define SPL07-006 I2C address
15+
//#define SPL07_ADDR SPL07_ADDR_DEF // Default I2C address (SDO=high)
16+
#define SPL07_ADDR SPL07_ADDR_ALT // Alternate I2C address (SDO=low)
17+
18+
// Create SPL07-003 sensor instance
19+
SPL07_003 spl;
20+
21+
//HardwareSerial SerialOut(PA10, PA9); //for STM32F103C8Tx
22+
23+
// Runs at startup
24+
void setup() {
25+
26+
// Begin Serial
27+
Serial.begin(115200);
28+
29+
// Configure & start I2C
30+
//Wire.setSDA(PB7); //for STM32F103C8Tx
31+
//Wire.setSCL(PB6); //for STM32F103C8Tx
32+
Wire.begin();
33+
34+
// Connect to SPL07-003
35+
if (spl.begin(SPL07_ADDR) == false) {
36+
Serial.println("Error initializing SPL07-003 :(");
37+
while (1) {}
38+
}//if
39+
Serial.println("Connected to SPL07-003! :)");
40+
41+
// Set pressure & temperature sampling settings
42+
spl.setPressureConfig(SPL07_4HZ, SPL07_32SAMPLES);
43+
spl.setTemperatureConfig(SPL07_4HZ, SPL07_1SAMPLE);
44+
45+
// Set SPL07-003 to continuous measurements
46+
spl.setMode(SPL07_CONT_PRES_TEMP);
47+
48+
}//setup()
49+
50+
51+
// Runs continuously
52+
void loop() {
53+
54+
// Wait for available reading
55+
if (spl.pressureAvailable() || spl.temperatureAvailable()) {
56+
// Read latest values
57+
double pres = spl.readPressure();
58+
double temp = spl.readTemperature();
59+
// Print to serial
60+
Serial.print("Pres: ");
61+
Serial.print(pres, 3);
62+
Serial.print(" Pa, Temp: ");
63+
Serial.print(temp, 3);
64+
Serial.println(" C");
65+
}//if
66+
67+
}//loop()

0 commit comments

Comments
 (0)