From 90888d0e86aaf91952f2e1d12f75a7213e3fdfe8 Mon Sep 17 00:00:00 2001 From: ladyada Date: Tue, 26 Aug 2025 20:53:24 -0400 Subject: [PATCH] Add auto-configuration for highest precision and new simpletest example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Configure begin() for highest precision (128x oversampling, 200Hz rate) - Enable temperature and pressure ready interrupts automatically - Add simpletest example with data-driven updates - Update library.properties with Adafruit Unified Sensor dependency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- Adafruit_SPA06_003.cpp | 12 +++++++ examples/simpletest/simpletest.ino | 57 ++++++++++++++++++++++++++++++ library.properties | 2 +- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 examples/simpletest/simpletest.ino diff --git a/Adafruit_SPA06_003.cpp b/Adafruit_SPA06_003.cpp index fd7dcee..16d1e7f 100644 --- a/Adafruit_SPA06_003.cpp +++ b/Adafruit_SPA06_003.cpp @@ -91,6 +91,18 @@ bool Adafruit_SPA06_003::begin(uint8_t i2c_addr, TwoWire *wire) { return false; } + // Configure for highest precision and sample rate + // Set pressure to highest oversampling (128x) and highest rate (200 Hz) + setPressureOversampling(SPA06_003_OVERSAMPLE_128); + setPressureMeasureRate(SPA06_003_RATE_200); + + // Set temperature to highest oversampling (128x) and highest rate (200 Hz) + setTemperatureOversampling(SPA06_003_OVERSAMPLE_128); + setTemperatureMeasureRate(SPA06_003_RATE_200); + + // Enable interrupts for temperature and pressure ready + setInterruptSource(false, true, true); // FIFO=false, temp_ready=true, pres_ready=true + // Set measurement mode to continuous both setMeasurementMode(SPA06_003_MEAS_CONTINUOUS_BOTH); diff --git a/examples/simpletest/simpletest.ino b/examples/simpletest/simpletest.ino new file mode 100644 index 0000000..82fcaa7 --- /dev/null +++ b/examples/simpletest/simpletest.ino @@ -0,0 +1,57 @@ +/*! + * @file simpletest.ino + * + * A simple test for the SPA06_003 pressure and temperature sensor. + * This example shows basic pressure and temperature readings using the sensor. + * + * The begin() function automatically configures the sensor for: + * - Highest precision (128x oversampling) + * - Highest sample rate (200 Hz) + * - Continuous measurement mode + * + * Designed specifically to work with the Adafruit SPA06_003 Breakout + * ----> https://www.adafruit.com/products/xxxx + * + * These sensors use I2C to communicate, 2 pins are required to interface. + * + * Written by Limor 'ladyada' Fried with assistance from Claude Code + * for Adafruit Industries. + * MIT license, check license.txt for more information + * All text above must be included in any redistribution + */ + +#include + +Adafruit_SPA06_003 spa; + +void setup() { + Serial.begin(115200); + while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens + + Serial.println("Adafruit SPA06_003 Simple Test"); + + // Try to initialize! + if (!spa.begin()) { + Serial.println("Failed to find SPA06_003 chip"); + while (1) { delay(10); } + } + Serial.println("SPA06_003 Found!"); +} + +void loop() { + // Only read and print when new data is available + if (spa.isTempDataReady() || spa.isPresDataReady()) { + float temperature = spa.readTemperature(); + float pressure = spa.readPressure(); + + Serial.print("Temperature: "); + Serial.print(temperature); + Serial.print(" °C"); + + Serial.print("\tPressure: "); + Serial.print(pressure); + Serial.println(" hPa"); + } + + delay(10); // Short delay to avoid overwhelming the sensor +} \ No newline at end of file diff --git a/library.properties b/library.properties index 94214f2..c74647e 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=Arduino library for the SPA06_003 miniaturized digital barometric air category=Sensors url=https://github.com/adafruit/Adafruit_SPA06_003 architectures=* -depends=Adafruit BusIO \ No newline at end of file +depends=Adafruit BusIO, Adafruit Unified Sensor \ No newline at end of file