Skip to content

Commit f63e396

Browse files
authored
Merge pull request #817 from adafruit/add-SPA06-003
add(component): SPA06-003 Temp+Pressure sensor
2 parents 9167c77 + e9b91b3 commit f63e396

File tree

5 files changed

+143
-1
lines changed

5 files changed

+143
-1
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit AS5600 Library, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit BMP5xx Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit QMC5883P Library, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306
10+
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPA06_003, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit AS5600 Library, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit BMP5xx Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit QMC5883P Library, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ lib_deps =
5454
adafruit/Adafruit SGP30 Sensor
5555
adafruit/Adafruit SGP40 Sensor
5656
adafruit/Adafruit Si7021 Library
57+
adafruit/Adafruit SPA06_003
5758
adafruit/Adafruit VCNL4020 Library
5859
adafruit/Adafruit VCNL4040
5960
adafruit/Adafruit VCNL4200 Library

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
538538
_si7021->configureDriver(msgDeviceInitReq);
539539
drivers.push_back(_si7021);
540540
WS_DEBUG_PRINTLN("SI7021/SHT20 Initialized Successfully!");
541+
} else if (strcmp("spa06_003", msgDeviceInitReq->i2c_device_name) == 0) {
542+
_spa06_003 = new WipperSnapper_I2C_Driver_SPA06_003(this->_i2c, i2cAddress);
543+
if (!_spa06_003->begin()) {
544+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize SPA06-003!");
545+
_busStatusResponse =
546+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
547+
return false;
548+
}
549+
_spa06_003->configureDriver(msgDeviceInitReq);
550+
drivers.push_back(_spa06_003);
551+
WS_DEBUG_PRINTLN("SPA06-003 Initialized Successfully!");
541552
} else if (strcmp("mcp3421", msgDeviceInitReq->i2c_device_name) == 0) {
542553
_mcp3421 = new WipperSnapper_I2C_Driver_MCP3421(this->_i2c, i2cAddress);
543554
if (!_mcp3421->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "drivers/WipperSnapper_I2C_Driver_SHT4X.h"
7777
#include "drivers/WipperSnapper_I2C_Driver_SHTC3.h"
7878
#include "drivers/WipperSnapper_I2C_Driver_SI7021.h"
79+
#include "drivers/WipperSnapper_I2C_Driver_SPA06_003.h"
7980
#include "drivers/WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor.h"
8081
#include "drivers/WipperSnapper_I2C_Driver_TMP117.h"
8182
#include "drivers/WipperSnapper_I2C_Driver_TSL2591.h"
@@ -204,6 +205,7 @@ class WipperSnapper_Component_I2C {
204205
WipperSnapper_I2C_Driver_SEN6X *_sen6x = nullptr;
205206
WipperSnapper_I2C_Driver_SGP30 *_sgp30 = nullptr;
206207
WipperSnapper_I2C_Driver_SGP40 *_sgp40 = nullptr;
208+
WipperSnapper_I2C_Driver_SPA06_003 *_spa06_003 = nullptr;
207209
WipperSnapper_I2C_Driver_PCT2075 *_pct2075 = nullptr;
208210
WipperSnapper_I2C_Driver_PM25 *_pm25 = nullptr;
209211
WipperSnapper_I2C_Driver_QMC5883P *_qmc5883p = nullptr;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_SPA06_003.h
3+
*
4+
* Device driver for an SPA06-003 Pressure and Temperature sensor.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Tyeth Gundry 2025 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
16+
#ifndef WipperSnapper_I2C_Driver_SPA06_003_H
17+
#define WipperSnapper_I2C_Driver_SPA06_003_H
18+
19+
#include "WipperSnapper_I2C_Driver.h"
20+
#include <Adafruit_SPA06_003.h>
21+
22+
#define SPA06_003_TEMP_MIN -40.0 ///< Minimum valid temperature reading
23+
#define SPA06_003_TEMP_MAX 85.0 ///< Maximum valid temperature reading
24+
#define SPA06_003_PRESSURE_MIN \
25+
300.0 ///< Minimum valid pressure (9km above sea level)
26+
#define SPA06_003_PRESSURE_MAX \
27+
1100.0 ///< Maximum valid pressure (500m below sea level)
28+
29+
/**************************************************************************/
30+
/*!
31+
@brief Class that provides a sensor driver for the SPA06-003 PT sensor.
32+
*/
33+
/**************************************************************************/
34+
class WipperSnapper_I2C_Driver_SPA06_003 : public WipperSnapper_I2C_Driver {
35+
36+
public:
37+
/*******************************************************************************/
38+
/*!
39+
@brief Constructor for an SPA06-003 sensor.
40+
@param i2c
41+
The I2C interface.
42+
@param sensorAddress
43+
7-bit device address.
44+
*/
45+
/*******************************************************************************/
46+
WipperSnapper_I2C_Driver_SPA06_003(TwoWire *i2c, uint16_t sensorAddress)
47+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
48+
_i2c = i2c;
49+
_sensorAddress = sensorAddress;
50+
}
51+
52+
/*******************************************************************************/
53+
/*!
54+
@brief Destructor for an SPA06-003 sensor.
55+
*/
56+
/*******************************************************************************/
57+
~WipperSnapper_I2C_Driver_SPA06_003() { delete _spa06_003; }
58+
59+
/*******************************************************************************/
60+
/*!
61+
@brief Initializes the SPA06-003 sensor and begins I2C.
62+
@returns True if initialized successfully, False otherwise.
63+
*/
64+
/*******************************************************************************/
65+
bool begin() {
66+
_spa06_003 = new Adafruit_SPA06_003();
67+
// attempt to initialize SPA06-003
68+
if (!_spa06_003->begin(_sensorAddress, _i2c))
69+
return false;
70+
71+
_spa06_003_temp = _spa06_003->getTemperatureSensor();
72+
_spa06_003_pressure = _spa06_003->getPressureSensor();
73+
return true;
74+
}
75+
76+
/*******************************************************************************/
77+
/*!
78+
@brief Gets the SPA06-003's current temperature.
79+
@param tempEvent
80+
Pointer to an Adafruit_Sensor event.
81+
@returns True if the temperature was obtained successfully, False
82+
otherwise.
83+
*/
84+
/*******************************************************************************/
85+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
86+
bool success = false;
87+
if (_spa06_003_temp == NULL)
88+
return false;
89+
success = _spa06_003_temp->getEvent(tempEvent);
90+
if (tempEvent->temperature > SPA06_003_TEMP_MAX ||
91+
tempEvent->temperature < SPA06_003_TEMP_MIN) {
92+
success = false;
93+
}
94+
return success;
95+
}
96+
97+
/*******************************************************************************/
98+
/*!
99+
@brief Reads a pressure sensor and converts
100+
the reading into the expected SI unit.
101+
@param pressureEvent
102+
Pointer to an Adafruit_Sensor event.
103+
@returns True if the sensor event was obtained successfully, False
104+
otherwise.
105+
*/
106+
/*******************************************************************************/
107+
bool getEventPressure(sensors_event_t *pressureEvent) {
108+
bool success = false;
109+
if (_spa06_003_pressure == NULL || _spa06_003->isPresDataReady() == false) {
110+
return false;
111+
}
112+
success = _spa06_003_pressure->getEvent(pressureEvent);
113+
if (pressureEvent->pressure < SPA06_003_PRESSURE_MIN ||
114+
pressureEvent->pressure > SPA06_003_PRESSURE_MAX) {
115+
success = false;
116+
}
117+
return success;
118+
}
119+
120+
protected:
121+
Adafruit_SPA06_003 *_spa06_003 = nullptr; ///< SPA06-003 object
122+
Adafruit_Sensor *_spa06_003_temp =
123+
nullptr; ///< Ptr to an adafruit_sensor representing the temperature
124+
Adafruit_Sensor *_spa06_003_pressure =
125+
nullptr; ///< Ptr to an adafruit_sensor representing the pressure
126+
};
127+
128+
#endif // WipperSnapper_I2C_Driver_SPA06_003_H

0 commit comments

Comments
 (0)