-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from marcuswu/issue/14/Add_STEMMA_Soil_Sensor…
…_Support Add STEMMA Soil Sensor support
- Loading branch information
Showing
6 changed files
with
240 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
name=Adafruit WipperSnapper | ||
version=1.0.0-beta.45 | ||
version=1.0.0-beta.46 | ||
author=Adafruit | ||
maintainer=Adafruit <adafruitio@adafruit.com> | ||
sentence=Arduino client for Adafruit.io WipperSnapper | ||
paragraph=Arduino client for Adafruit.io WipperSnapper | ||
category=Communication | ||
url=https://github.com/adafruit/Adafruit_IO_Arduino | ||
architectures=* | ||
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library, Adafruit SHT4x Library, Adafruit PM25 AQI Sensor, Adafruit LC709203F | ||
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library, Adafruit SHT4x Library, Adafruit PM25 AQI Sensor, Adafruit LC709203F, Adafruit seesaw Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/components/i2c/drivers/WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor.h | ||
* | ||
* Device driver for the STEMMA Soil Sensor | ||
* | ||
* Adafruit invests time and resources providing this open source code, | ||
* please support Adafruit and open-source hardware by purchasing | ||
* products from Adafruit! | ||
* | ||
* Copyright (c) Marcus Wu 2022 | ||
* | ||
* MIT license, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
|
||
#ifndef WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor_H | ||
#define WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_seesaw.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a driver interface for the STEMMA soil sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor | ||
: public WipperSnapper_I2C_Driver { | ||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for a STEMMA soil sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor(TwoWire *i2c, | ||
uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
_seesaw = new Adafruit_seesaw(_i2c); | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for a STEMMA soil sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor() { delete _seesaw; } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the soil sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { return _seesaw->begin(_sensorAddress); } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the sensor's current temperature. | ||
@param tempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventAmbientTemperature(sensors_event_t *tempEvent) { | ||
tempEvent->temperature = _seesaw->getTemp(); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the sensor's current moisture sensor capacitance value. | ||
@param rawEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventRaw(sensors_event_t *rawEvent) { | ||
uint16_t touchData = _seesaw->touchRead(0); | ||
|
||
// seesaw->touchRead() will return 65535 on a read error | ||
// see | ||
// https://github.com/adafruit/Adafruit_Seesaw/blob/master/Adafruit_seesaw.cpp | ||
if (touchData == 65535) { | ||
return false; | ||
} | ||
|
||
// TODO: Update this should we add a capacitive moisture type to | ||
// adafruit_sensor | ||
rawEvent->data[0] = (float)touchData; | ||
return true; | ||
} | ||
|
||
protected: | ||
Adafruit_seesaw *_seesaw; ///< Seesaw object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor_H |