From 2545f82d40f2bb02dcd51464051deb2d7bcee39c Mon Sep 17 00:00:00 2001 From: ColpittsEEE Date: Tue, 5 Nov 2024 09:52:53 +0100 Subject: [PATCH 1/3] FDC1004 added to modulino.h --- src/Modulino.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/Modulino.h b/src/Modulino.h index cfe420b..d066d09 100644 --- a/src/Modulino.h +++ b/src/Modulino.h @@ -7,6 +7,7 @@ #include "Arduino_LSM6DSOX.h" #include #include +#include //#include // need to provide a way to change Wire object #ifndef ARDUINO_API_VERSION @@ -506,3 +507,71 @@ class ModulinoDistance : public Module { float internal = NAN; _distance_api* api = nullptr; }; + + +class ModulinoFarad: public Module { +public: + bool begin() { + if (_sensor == nullptr) { + _sensor = new FDC1004Class(*((TwoWire*)getWire())); + } + initialized = _sensor->begin(); + __increaseI2CPriority(); + return initialized; + } + operator bool() { + return (initialized != 0); + } + + bool measurementSettings(int measuresEn, int measurementRate, int measurementRepeat) + { + if (initialized) + { + _sensor->measurementConfiguration(measuresEn,measurementRate,measurementRepeat); + return 1; + } + return 0; + } + bool channelSettings(int channel,int chA,int chB, int CAPDAC) + { + if (initialized) + { + _sensor->channelConfiguration(channel,chA,chB,CAPDAC); + return 1; + } + return 0; + } + bool channelOffset(int channel,uint16_t offset) + { + if (initialized) + { + _sensor->channelOffset(channel,offset); + return 1; + } + return 0; + } + bool channelGain(int channel ,uint16_t gain) + { + if (initialized) + { + _sensor->channelGainConfiguration(channel,gain); + return 1; + } + return 0; + } + bool measureAvailable(int channel) + { + if (initialized) + return _sensor->measureAvailable(channel); + return 0; + } + int getMeasure(int channel) { + if (initialized) + return _sensor->getChannelMeasurement(channel); + return 0; + } + +private: + FDC1004Class* _sensor = nullptr; + int initialized = 0; +}; From d0e825c2fc9fe41b6ff620d2cdb9649e20f967f0 Mon Sep 17 00:00:00 2001 From: ColpittsEEE Date: Tue, 5 Nov 2024 14:46:18 +0100 Subject: [PATCH 2/3] Added Modulino Farad example --- examples/Modulino_Farad/basic/basic.ino | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/Modulino_Farad/basic/basic.ino diff --git a/examples/Modulino_Farad/basic/basic.ino b/examples/Modulino_Farad/basic/basic.ino new file mode 100644 index 0000000..cc95c57 --- /dev/null +++ b/examples/Modulino_Farad/basic/basic.ino @@ -0,0 +1,41 @@ +/* + FDC1004 - basic + + This example reads data from Modulino Farad + With this settings you can read channel 1. + Offset and gain are set to Zero. + + + This example code is in the public domain. +*/ +#include +#include "Modulino.h" + +uint16_t reg_read; +int measured_cap; +ModulinoFarad farad; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + Modulino.begin(); + farad.begin(); + //Offset settings - Value set to Zero + farad.channelOffset(CHANNEL1,0x00); + //Channel settings - Channel 1 will measure the capacitance on input CIN1sa and the offset is set to Zero + farad.channelSettings(CHANNEL1,CIN1,CAPDAC,0x00); + //Measure settings - Channel 1 enabled, sample rate is 100 Samples/sec and measure is repeated + farad.measurementSettings(MEAS_1_EN,RATE_100Ss,REPEAT_ENABLED); + +} + +void loop() { + // put your main code here, to run repeatedly: + if (farad.measureAvailable(CHANNEL1)) + { + measured_cap = farad.getMeasure(CHANNEL1); + Serial.print("The Value of the measured Capacitance is "); + Serial.println(measured_cap); + } + delay(200); +} From bd573dbed4c38a338f1e80561413d17d1144e885 Mon Sep 17 00:00:00 2001 From: ColpittsEEE Date: Thu, 21 Nov 2024 09:18:43 +0100 Subject: [PATCH 3/3] Added Reset Function for FDC1004 --- src/Modulino.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Modulino.h b/src/Modulino.h index d066d09..5b52c4c 100644 --- a/src/Modulino.h +++ b/src/Modulino.h @@ -570,6 +570,12 @@ class ModulinoFarad: public Module { return _sensor->getChannelMeasurement(channel); return 0; } + + void resetRequest() + { + if (initialized) + _sensor->resetRequest(); + } private: FDC1004Class* _sensor = nullptr;