Skip to content
Snippets Groups Projects
Commit b236f935 authored by User expired's avatar User expired
Browse files

setup multiple dendrometers on one client

parent 225fa471
No related branches found
No related tags found
4 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!6Espnow
Showing
with 970 additions and 3 deletions
# Byte-compiled / optimized / DLL files
#b/li Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
......@@ -14,8 +14,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
!host/fipy/lib
!client/client/lib
lib64/
parts/
......
{
"folders": [
{
"name": "client",
"path": "."
}
],
"settings": {}
}
\ No newline at end of file
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
#include <drs26.hpp>
/*
It happens for some reason that the sensor cant get reached every 2 time
Because the sensor use sdi12 protocoll we have to wait aproxemettly 1 secound between the commands
It is not known how lond the response takes so we use a while loop which can be a risk wehre the programm can get stuck
*/
void Forte_DRS26 ::setup()
{
drs26.begin(SDI_DATA);
}
out_data_drs26 *Forte_DRS26 ::read_data()
{
String sdiResponse = "";
String measurement_command="1M!"; //The drs26 sensor uses the sdi12 protocoll , in the sdi12 protocoll is the measurement command is specified as 1M!=Sebsir measurement request at adress 1
String data_command="1D0!"; //and the followed data command 1D0! = Sensor data request at adress 1
drs26.sendCommand(measurement_command);
delay(1000);
drs26.sendCommand(data_command);
while (drs26.available())
{
char next_character = drs26.read();
if ((next_character != '\n') && (next_character != '\r'))
{
sdiResponse += next_character;
delay(10); // 1 character ~ 7.5ms
}
}
// Serial.println(sdiResponse);
if (sdiResponse.length() > 1)
{
data.id = sdiResponse.substring(0, 8).toInt();
data.circumference = sdiResponse.substring(8, 16).toFloat();
data.temperatur = sdiResponse.substring(15, 22).toFloat();
return &data;
}
return 0;
}
\ No newline at end of file
#ifndef _DRS26
#define _DRS26
#include <forte_sensor.hpp>
#include <SDI12.h>
#include <pinout.hpp>
#include "Wire.h"
struct out_data_drs26 {
int id;
float circumference;
float temperatur;
};
class Forte_DRS26 : public Forte_Sensor{
public:
void setup();
out_data_drs26* read_data();
private:
SDI12 drs26;
out_data_drs26 data;
};
#endif
\ No newline at end of file
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
class Forte_Sensor {
public:
virtual void* read_data() = 0;
virtual void setup() = 0;
private:
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for SDI12
#define SDI_DATA 4
#endif
\ No newline at end of file
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
class Forte_Sensor {
public:
virtual void* read_data() = 0;
virtual void setup() = 0;
private:
};
#endif
\ No newline at end of file
#include "ina219.hpp"
void Forte_INA219 :: setup(){
Wire.begin(I2C_SDA, I2C_SCL);
if(!ina219.init()){
// Sensor init went wrong
return;
}
}
out_data_ina219* Forte_INA219 :: read_data(){
if(!ina219.getOverflow())
{
data.shuntVoltage_mV = ina219.getShuntVoltage_mV();
data.busVoltage_V= ina219.getBusVoltage_V();
data.current_mA= ina219.getCurrent_mA();
data.power_mW= ina219.getBusPower();
data.loadVoltage_V = data.busVoltage_V + (data.shuntVoltage_mV/1000);
data.ina219_overflow=ina219.getOverflow();
return &data;
}
else
return 0;
}
\ No newline at end of file
#ifndef _INA219
#define _INA219
#include <forte_sensor.hpp>
#include <pinout.hpp>
#include <INA219_WE.h>
#include <Wire.h>
//TwoWire I2Cone = TwoWire(0);
//TwoWire I2Ctwo = TwoWire(1);
struct out_data_ina219 {
float shuntVoltage_mV = 0.0;
float loadVoltage_V = 0.0;
float busVoltage_V = 0.0;
float current_mA = 0.0;
float power_mW = 0.0;
bool ina219_overflow = false;
};
class Forte_INA219 : public Forte_Sensor{
public:
void setup();
out_data_ina219* read_data();
private:
INA219_WE ina219;
out_data_ina219 data;
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for I2C Protocol (for digital communication between ESP and the Sensor)
#define I2C_SCL 7
#define I2C_SDA 6
#endif
\ No newline at end of file
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
class Forte_Sensor {
public:
virtual void* read_data() = 0;
virtual void setup() = 0;
private:
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for I2C Proctocol (for digital communication between ESP and the Sensor)
#define I2C_SCL 9
#define I2C_SDA 8
#endif
\ No newline at end of file
#include "scd30.hpp"
void Forte_SCD30 :: setup(){
Wire.begin(I2C_SDA, I2C_SCL);
if(!airSensor.begin()){
// Sensor init went wrong
return;
}
}
out_data_scd30* Forte_SCD30 :: read_data(){
if(airSensor.dataAvailable())
{
data.C02= airSensor.getCO2();
data.Temperature = airSensor.getTemperature();
data.Humidity = airSensor.getHumidity();
return &data;
}
else
return 0;
}
\ No newline at end of file
#ifndef _SCD30
#define _SCD30
#include <forte_sensor.hpp>
#include <Wire.h>
#include <pinout.hpp>
#include <SparkFun_SCD30_Arduino_Library.h>
struct out_data_scd30
{
float C02;
float Temperature;
float Humidity;
};
class Forte_SCD30 : public Forte_Sensor{
public:
void setup();
out_data_scd30* read_data();
private:
SCD30 airSensor;
out_data_scd30 data;
};
#endif
\ No newline at end of file
/**************************************************************************/
/*!
@file Adafruit_ADS1X15.cpp
@author K.Townsend (Adafruit Industries)
@mainpage Adafruit ADS1X15 ADC Breakout Driver
@section intro_sec Introduction
This is a library for the Adafruit ADS1X15 ADC breakout boards.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section author Author
Written by Kevin "KTOWN" Townsend for Adafruit Industries.
@section HISTORY
v1.0 - First release
v1.1 - Added ADS1115 support - W. Earl
v2.0 - Refactor - C. Nelson
@section license License
BSD license, all text here must be included in any redistribution
*/
/**************************************************************************/
#include "Adafruit_ADS1X15_Forte.h"
/**************************************************************************/
/*!
@brief Instantiates a new ADS1015 class w/appropriate properties
*/
/**************************************************************************/
Adafruit_ADS1015::Adafruit_ADS1015() {
m_bitShift = 4;
m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
m_dataRate = RATE_ADS1015_1600SPS;
}
/**************************************************************************/
/*!
@brief Instantiates a new ADS1115 class w/appropriate properties
*/
/**************************************************************************/
Adafruit_ADS1115::Adafruit_ADS1115() {
m_bitShift = 0;
m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
m_dataRate = RATE_ADS1115_128SPS;
}
/**************************************************************************/
/*!
@brief Sets up the HW (reads coefficients values, etc.)
@param i2c_addr I2C address of device
@param wire I2C bus
@return true if successful, otherwise false
*/
/**************************************************************************/
bool Adafruit_ADS1X15::begin(uint8_t i2c_addr, TwoWire *wire) {
m_i2c_dev = new Adafruit_I2CDevice(i2c_addr, wire);
return m_i2c_dev->begin();
}
/**************************************************************************/
/*!
@brief Sets the gain and input voltage range
@param gain gain setting to use
*/
/**************************************************************************/
void Adafruit_ADS1X15::setGain(adsGain_t gain) { m_gain = gain; }
/**************************************************************************/
/*!
@brief Gets a gain and input voltage range
@return the gain setting
*/
/**************************************************************************/
adsGain_t Adafruit_ADS1X15::getGain() { return m_gain; }
/**************************************************************************/
/*!
@brief Sets the data rate
@param rate the data rate to use
*/
/**************************************************************************/
void Adafruit_ADS1X15::setDataRate(uint16_t rate) { m_dataRate = rate; }
/**************************************************************************/
/*!
@brief Gets the current data rate
@return the data rate
*/
/**************************************************************************/
uint16_t Adafruit_ADS1X15::getDataRate() { return m_dataRate; }
/**************************************************************************/
/*!
@brief Gets a single-ended ADC reading from the specified channel
@param channel ADC channel to read + @FORTEsecurity
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_SingleEnded(uint8_t channel) {
if (channel > 3) {
return 0;
}
startADCReading(MUX_BY_CHANNEL[channel], /*continuous=*/false);
// Wait for the conversion to complete + @FORTEsecurity throw exeption if it takes to long
long i=0;
long max_wait=100;
while (!conversionComplete()&&i<max_wait){
++i;
delay(10);
}
if(i==max_wait)
throw NoDataAvailableException();
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN0) and N (AIN1) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_0_1() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_0_1, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN0) and N (AIN3) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_0_3() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_0_3, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN1) and N (AIN3) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_1_3() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_1_3, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN2) and N (AIN3) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_2_3() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_2_3, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Sets up the comparator to operate in basic mode, causing the
ALERT/RDY pin to assert (go from high to low) when the ADC
value exceeds the specified threshold.
This will also set the ADC in continuous conversion mode.
@param channel ADC channel to use
@param threshold comparator threshold
*/
/**************************************************************************/
void Adafruit_ADS1X15::startComparator_SingleEnded(uint8_t channel,
int16_t threshold) {
// Start with default values
uint16_t config =
ADS1X15_REG_CONFIG_CQUE_1CONV | // Comparator enabled and asserts on 1
// match
ADS1X15_REG_CONFIG_CLAT_LATCH | // Latching mode
ADS1X15_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1X15_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
ADS1X15_REG_CONFIG_MODE_CONTIN | // Continuous conversion mode
ADS1X15_REG_CONFIG_MODE_CONTIN; // Continuous conversion mode
// Set PGA/voltage range
config |= m_gain;
// Set data rate
config |= m_dataRate;
config |= MUX_BY_CHANNEL[channel];
// Set the high threshold register
// Shift 12-bit results left 4 bits for the ADS1015
writeRegister(ADS1X15_REG_POINTER_HITHRESH, threshold << m_bitShift);
// Write config register to the ADC
writeRegister(ADS1X15_REG_POINTER_CONFIG, config);
}
/**************************************************************************/
/*!
@brief In order to clear the comparator, we need to read the
conversion results. This function reads the last conversion
results without changing the config value.
@return the last ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::getLastConversionResults() {
// Read the conversion results
uint16_t res = readRegister(ADS1X15_REG_POINTER_CONVERT) >> m_bitShift;
if (m_bitShift == 0) {
return (int16_t)res;
} else {
// Shift 12-bit results right 4 bits for the ADS1015,
// making sure we keep the sign bit intact
if (res > 0x07FF) {
// negative number - extend the sign to 16th bit
res |= 0xF000;
}
return (int16_t)res;
}
}
/**************************************************************************/
/*!
@brief Returns true if conversion is complete, false otherwise.
@param counts the ADC reading in raw counts
@return the ADC reading in volts
*/
/**************************************************************************/
float Adafruit_ADS1X15::computeVolts(int16_t counts) {
// see data sheet Table 3
float fsRange;
switch (m_gain) {
case GAIN_TWOTHIRDS:
fsRange = 6.144f;
break;
case GAIN_ONE:
fsRange = 4.096f;
break;
case GAIN_TWO:
fsRange = 2.048f;
break;
case GAIN_FOUR:
fsRange = 1.024f;
break;
case GAIN_EIGHT:
fsRange = 0.512f;
break;
case GAIN_SIXTEEN:
fsRange = 0.256f;
break;
default:
fsRange = 0.0f;
}
return counts * (fsRange / (32768 >> m_bitShift));
}
/**************************************************************************/
/*!
@brief Non-blocking start conversion function
Call getLastConversionResults() once conversionComplete() returns true.
In continuous mode, getLastConversionResults() will always return the
latest result.
ALERT/RDY pin is set to RDY mode, and a 8us pulse is generated every
time new data is ready.
@param mux mux field value
@param continuous continuous if set, otherwise single shot
*/
/**************************************************************************/
void Adafruit_ADS1X15::startADCReading(uint16_t mux, bool continuous) {
// Start with default values
uint16_t config =
ADS1X15_REG_CONFIG_CQUE_1CONV | // Set CQUE to any value other than
// None so we can use it in RDY mode
ADS1X15_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
ADS1X15_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1X15_REG_CONFIG_CMODE_TRAD; // Traditional comparator (default val)
if (continuous) {
config |= ADS1X15_REG_CONFIG_MODE_CONTIN;
} else {
config |= ADS1X15_REG_CONFIG_MODE_SINGLE;
}
// Set PGA/voltage range
config |= m_gain;
// Set data rate
config |= m_dataRate;
// Set channels
config |= mux;
// Set 'start single-conversion' bit
config |= ADS1X15_REG_CONFIG_OS_SINGLE;
// Write config register to the ADC
writeRegister(ADS1X15_REG_POINTER_CONFIG, config);
// Set ALERT/RDY to RDY mode.
writeRegister(ADS1X15_REG_POINTER_HITHRESH, 0x8000);
writeRegister(ADS1X15_REG_POINTER_LOWTHRESH, 0x0000);
}
/**************************************************************************/
/*!
@brief Returns true if conversion is complete, false otherwise.
@return True if conversion is complete, false otherwise.
*/
/**************************************************************************/
bool Adafruit_ADS1X15::conversionComplete() {
return (readRegister(ADS1X15_REG_POINTER_CONFIG) & 0x8000) != 0;
}
/**************************************************************************/
/*!
@brief Writes 16-bits to the specified destination register
@param reg register address to write to
@param value value to write to register
*/
/**************************************************************************/
void Adafruit_ADS1X15::writeRegister(uint8_t reg, uint16_t value) {
buffer[0] = reg;
buffer[1] = value >> 8;
buffer[2] = value & 0xFF;
m_i2c_dev->write(buffer, 3);
}
/**************************************************************************/
/*!
@brief Read 16-bits from the specified destination register
@param reg register address to read from
@return 16 bit register value read
*/
/**************************************************************************/
uint16_t Adafruit_ADS1X15::readRegister(uint8_t reg) {
buffer[0] = reg;
m_i2c_dev->write(buffer, 1);
m_i2c_dev->read(buffer, 2);
return ((buffer[0] << 8) | buffer[1]);
}
/**************************************************************************/
/*!
@file Adafruit_ADS1X15.h
This is a library for the Adafruit ADS1X15 ADC breakout boards.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Kevin "KTOWN" Townsend for Adafruit Industries.
BSD license, all text here must be included in any redistribution
*/
/**************************************************************************/
#ifndef __ADS1X15_Forte_H__
#define __ADS1X15_Forte_H__
#include <Adafruit_I2CDevice.h>
#include <Arduino.h>
#include <Wire.h>
#include "NoDataAvailableException.hpp"
/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define ADS1X15_ADDRESS (0x48) ///< 1001 000 (ADDR = GND)
/*=========================================================================*/
/*=========================================================================
POINTER REGISTER
-----------------------------------------------------------------------*/
#define ADS1X15_REG_POINTER_MASK (0x03) ///< Point mask
#define ADS1X15_REG_POINTER_CONVERT (0x00) ///< Conversion
#define ADS1X15_REG_POINTER_CONFIG (0x01) ///< Configuration
#define ADS1X15_REG_POINTER_LOWTHRESH (0x02) ///< Low threshold
#define ADS1X15_REG_POINTER_HITHRESH (0x03) ///< High threshold
/*=========================================================================*/
/*=========================================================================
CONFIG REGISTER
-----------------------------------------------------------------------*/
#define ADS1X15_REG_CONFIG_OS_MASK (0x8000) ///< OS Mask
#define ADS1X15_REG_CONFIG_OS_SINGLE \
(0x8000) ///< Write: Set to start a single-conversion
#define ADS1X15_REG_CONFIG_OS_BUSY \
(0x0000) ///< Read: Bit = 0 when conversion is in progress
#define ADS1X15_REG_CONFIG_OS_NOTBUSY \
(0x8000) ///< Read: Bit = 1 when device is not performing a conversion
#define ADS1X15_REG_CONFIG_MUX_MASK (0x7000) ///< Mux Mask
#define ADS1X15_REG_CONFIG_MUX_DIFF_0_1 \
(0x0000) ///< Differential P = AIN0, N = AIN1 (default)
#define ADS1X15_REG_CONFIG_MUX_DIFF_0_3 \
(0x1000) ///< Differential P = AIN0, N = AIN3
#define ADS1X15_REG_CONFIG_MUX_DIFF_1_3 \
(0x2000) ///< Differential P = AIN1, N = AIN3
#define ADS1X15_REG_CONFIG_MUX_DIFF_2_3 \
(0x3000) ///< Differential P = AIN2, N = AIN3
#define ADS1X15_REG_CONFIG_MUX_SINGLE_0 (0x4000) ///< Single-ended AIN0
#define ADS1X15_REG_CONFIG_MUX_SINGLE_1 (0x5000) ///< Single-ended AIN1
#define ADS1X15_REG_CONFIG_MUX_SINGLE_2 (0x6000) ///< Single-ended AIN2
#define ADS1X15_REG_CONFIG_MUX_SINGLE_3 (0x7000) ///< Single-ended AIN3
constexpr uint16_t MUX_BY_CHANNEL[] = {
ADS1X15_REG_CONFIG_MUX_SINGLE_0, ///< Single-ended AIN0
ADS1X15_REG_CONFIG_MUX_SINGLE_1, ///< Single-ended AIN1
ADS1X15_REG_CONFIG_MUX_SINGLE_2, ///< Single-ended AIN2
ADS1X15_REG_CONFIG_MUX_SINGLE_3 ///< Single-ended AIN3
}; ///< MUX config by channel
#define ADS1X15_REG_CONFIG_PGA_MASK (0x0E00) ///< PGA Mask
#define ADS1X15_REG_CONFIG_PGA_6_144V (0x0000) ///< +/-6.144V range = Gain 2/3
#define ADS1X15_REG_CONFIG_PGA_4_096V (0x0200) ///< +/-4.096V range = Gain 1
#define ADS1X15_REG_CONFIG_PGA_2_048V \
(0x0400) ///< +/-2.048V range = Gain 2 (default)
#define ADS1X15_REG_CONFIG_PGA_1_024V (0x0600) ///< +/-1.024V range = Gain 4
#define ADS1X15_REG_CONFIG_PGA_0_512V (0x0800) ///< +/-0.512V range = Gain 8
#define ADS1X15_REG_CONFIG_PGA_0_256V (0x0A00) ///< +/-0.256V range = Gain 16
#define ADS1X15_REG_CONFIG_MODE_MASK (0x0100) ///< Mode Mask
#define ADS1X15_REG_CONFIG_MODE_CONTIN (0x0000) ///< Continuous conversion mode
#define ADS1X15_REG_CONFIG_MODE_SINGLE \
(0x0100) ///< Power-down single-shot mode (default)
#define ADS1X15_REG_CONFIG_RATE_MASK (0x00E0) ///< Data Rate Mask
#define ADS1X15_REG_CONFIG_CMODE_MASK (0x0010) ///< CMode Mask
#define ADS1X15_REG_CONFIG_CMODE_TRAD \
(0x0000) ///< Traditional comparator with hysteresis (default)
#define ADS1X15_REG_CONFIG_CMODE_WINDOW (0x0010) ///< Window comparator
#define ADS1X15_REG_CONFIG_CPOL_MASK (0x0008) ///< CPol Mask
#define ADS1X15_REG_CONFIG_CPOL_ACTVLOW \
(0x0000) ///< ALERT/RDY pin is low when active (default)
#define ADS1X15_REG_CONFIG_CPOL_ACTVHI \
(0x0008) ///< ALERT/RDY pin is high when active
#define ADS1X15_REG_CONFIG_CLAT_MASK \
(0x0004) ///< Determines if ALERT/RDY pin latches once asserted
#define ADS1X15_REG_CONFIG_CLAT_NONLAT \
(0x0000) ///< Non-latching comparator (default)
#define ADS1X15_REG_CONFIG_CLAT_LATCH (0x0004) ///< Latching comparator
#define ADS1X15_REG_CONFIG_CQUE_MASK (0x0003) ///< CQue Mask
#define ADS1X15_REG_CONFIG_CQUE_1CONV \
(0x0000) ///< Assert ALERT/RDY after one conversions
#define ADS1X15_REG_CONFIG_CQUE_2CONV \
(0x0001) ///< Assert ALERT/RDY after two conversions
#define ADS1X15_REG_CONFIG_CQUE_4CONV \
(0x0002) ///< Assert ALERT/RDY after four conversions
#define ADS1X15_REG_CONFIG_CQUE_NONE \
(0x0003) ///< Disable the comparator and put ALERT/RDY in high state (default)
/*=========================================================================*/
/** Gain settings */
typedef enum {
GAIN_TWOTHIRDS = ADS1X15_REG_CONFIG_PGA_6_144V,
GAIN_ONE = ADS1X15_REG_CONFIG_PGA_4_096V,
GAIN_TWO = ADS1X15_REG_CONFIG_PGA_2_048V,
GAIN_FOUR = ADS1X15_REG_CONFIG_PGA_1_024V,
GAIN_EIGHT = ADS1X15_REG_CONFIG_PGA_0_512V,
GAIN_SIXTEEN = ADS1X15_REG_CONFIG_PGA_0_256V
} adsGain_t;
/** Data rates */
#define RATE_ADS1015_128SPS (0x0000) ///< 128 samples per second
#define RATE_ADS1015_250SPS (0x0020) ///< 250 samples per second
#define RATE_ADS1015_490SPS (0x0040) ///< 490 samples per second
#define RATE_ADS1015_920SPS (0x0060) ///< 920 samples per second
#define RATE_ADS1015_1600SPS (0x0080) ///< 1600 samples per second (default)
#define RATE_ADS1015_2400SPS (0x00A0) ///< 2400 samples per second
#define RATE_ADS1015_3300SPS (0x00C0) ///< 3300 samples per second
#define RATE_ADS1115_8SPS (0x0000) ///< 8 samples per second
#define RATE_ADS1115_16SPS (0x0020) ///< 16 samples per second
#define RATE_ADS1115_32SPS (0x0040) ///< 32 samples per second
#define RATE_ADS1115_64SPS (0x0060) ///< 64 samples per second
#define RATE_ADS1115_128SPS (0x0080) ///< 128 samples per second (default)
#define RATE_ADS1115_250SPS (0x00A0) ///< 250 samples per second
#define RATE_ADS1115_475SPS (0x00C0) ///< 475 samples per second
#define RATE_ADS1115_860SPS (0x00E0) ///< 860 samples per second
/**************************************************************************/
/*!
@brief Sensor driver for the Adafruit ADS1X15 ADC breakouts.
*/
/**************************************************************************/
class Adafruit_ADS1X15 {
protected:
// Instance-specific properties
Adafruit_I2CDevice *m_i2c_dev; ///< I2C bus device
uint8_t m_bitShift; ///< bit shift amount
adsGain_t m_gain; ///< ADC gain
uint16_t m_dataRate; ///< Data rate
public:
bool begin(uint8_t i2c_addr = ADS1X15_ADDRESS, TwoWire *wire = &Wire);
int16_t readADC_SingleEnded(uint8_t channel);
int16_t readADC_Differential_0_1();
int16_t readADC_Differential_0_3();
int16_t readADC_Differential_1_3();
int16_t readADC_Differential_2_3();
void startComparator_SingleEnded(uint8_t channel, int16_t threshold);
int16_t getLastConversionResults();
float computeVolts(int16_t counts);
void setGain(adsGain_t gain);
adsGain_t getGain();
void setDataRate(uint16_t rate);
uint16_t getDataRate();
void startADCReading(uint16_t mux, bool continuous);
bool conversionComplete();
private:
void writeRegister(uint8_t reg, uint16_t value);
uint16_t readRegister(uint8_t reg);
uint8_t buffer[3];
};
/**************************************************************************/
/*!
@brief Sensor driver for the Adafruit ADS1015 ADC breakout.
*/
/**************************************************************************/
class Adafruit_ADS1015 : public Adafruit_ADS1X15 {
public:
Adafruit_ADS1015();
};
/**************************************************************************/
/*!
@brief Sensor driver for the Adafruit ADS1115 ADC breakout.
*/
/**************************************************************************/
class Adafruit_ADS1115 : public Adafruit_ADS1X15 {
public:
Adafruit_ADS1115();
};
#endif
#pragma once
#define NUM_SENSORS 10
// packing the struct without padding, makes reading it on the fipy easier
#pragma pack(1)
// having the data be a struct of basic types makes sending easier,
// otherwise we would have to serialize the data before sending
struct ClientDataPackage {
int identifiers[NUM_SENSORS];
float values[NUM_SENSORS];
int amountData;
long timestamp; // maybe make this array
};
#include "Message.hpp"
void Message::add_data(float value, int identifier)
{
if (data.amountData < NUM_SENSORS) {
data.values[data.amountData] = value;
data.identifiers[data.amountData] = identifier;
data.amountData++;
}
}
ClientDataPackage Message ::get_client_data_package() const
{
return data;
}
Message ::Message()
{
// check for existing host mac address, use broadcast otherwise
data.amountData = 0;
data.timestamp = Time::getInstance().getMillis(); // I am assuming we are not sending data from Unix Epoch
}
Message ::Message(ClientDataPackage old_data)
{
data = old_data;
// memcpy(&data, &old_data, sizeof(data));
}
\ No newline at end of file
#pragma once
#include "ClientDataPackage.hpp"
#include "Time.hpp"
#include <Arduino.h>
#include <ESP32Time.h>
#include <esp_now.h>
// Format of the message sent from host to client
// if more things are sent from the host the name might not be accurate anymore
class Message {
public:
Message();
Message(ClientDataPackage old_data);
void add_data(float value, int identifier);
ClientDataPackage get_client_data_package() const;
private:
ClientDataPackage data;
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment