Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FDC1004 added to modulino.h #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/Modulino_Farad/basic/basic.ino
Original file line number Diff line number Diff line change
@@ -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 <Wire.h>
#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);
}
75 changes: 75 additions & 0 deletions src/Modulino.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Arduino_LSM6DSOX.h"
#include <Arduino_LPS22HB.h>
#include <Arduino_HS300x.h>
#include <Arduino_FDC1004.h>
//#include <SE05X.h> // need to provide a way to change Wire object

#ifndef ARDUINO_API_VERSION
Expand Down Expand Up @@ -506,3 +507,77 @@ 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;
}

void resetRequest()
{
if (initialized)
_sensor->resetRequest();
}

private:
FDC1004Class* _sensor = nullptr;
int initialized = 0;
};
Loading