I have a problem and hope someone here can help me.
I want to measure changes in capacity over time. One Arduino is used per capacity sensor. There is one anode per Arduino and a total of one common cahode. (See picture)
With four Arduinos connected in series via I2C master-slave connection, successful results were obtained. With more than four Arduinos all measurement results were 0, because no voltage is measured at the input pin anymore. I then lowered the reference voltage for analogRead. So 10 Arduinos in series were possible. However, the measured values are clearly lower. However, no absolute values are to be measured, but eun difference in the capacity is sufficient. Finally 50 Arduinos should be used. I have thought of the following possibilities
reduce the reference voltage further, but this may reduce the measurement results further, so that no deflection is measured.
increase the output voltage at the Arduino via an operational amplifier to compensate the voltage drop.
Does anyone have another idea how I could proceed to get a usable result with all 50 Arduinos? The code I used is to be found below.
Many thanks in advance
Greetings Imogdia
Master
const int OUT_PIN = A0;
const int IN_PIN = A2;
//Capacitance between IN_PIN and Ground
//Stray capacitance is always present. Extra capacitance can be added to
//allow higher capacitance to be measured.
const float IN_STRAY_CAP_TO_GND = 30.00;
const float IN_EXTRA_CAP_TO_GND = 0.0;
const float IN_CAP_TO_GND = IN_STRAY_CAP_TO_GND + IN_EXTRA_CAP_TO_GND;
const int MAX_ADC_VALUE = 1023;
#include <Wire.h>
#define nodeMax 10
#define nodeStart 2
union u_capacitance
{
struct
{
float capa_slave;
};
byte bytes[10];
};
u_capacitance capacitanceSlave;
void setup()
{
analogReference(EXTERNAL);
Wire.begin(); // join i2c bus (address optional for master)
pinMode(OUT_PIN, OUTPUT);
pinMode(IN_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
//Capacitor under test between OUT_PIN and IN_PIN
//Rising high edge on OUT_PIN
pinMode(IN_PIN, INPUT);
digitalWrite(OUT_PIN, HIGH);
int val = analogRead(IN_PIN);
//Clear everything for next measurement
digitalWrite(OUT_PIN, LOW);
pinMode(IN_PIN, OUTPUT);
//digitalWrite(IN_PIN, LOW);
//Calculate and print result
float capacitance = (float)val * IN_CAP_TO_GND / (float)(MAX_ADC_VALUE - val);
Serial.print(capacitance, 2);
Serial.print(",");
Serial.print(val);
Serial.print(",");
delay(10);
for( int node = nodeStart; node <= nodeMax; node++){
Wire.requestFrom(node, sizeof(capacitanceSlave));
for (unsigned int i = 0; i < sizeof(capacitanceSlave); i++){
capacitanceSlave.bytes[i] = Wire.read();
}
Serial.print(capacitanceSlave.capa_slave);
Serial.print(",");
delay(10);
}
Serial.println();
delay(50);
}
Slave
const int OUT_PIN = A0;
const int IN_PIN = A2;
//Capacitance between IN_PIN and Ground
//Stray capacitance is always present. Extra capacitance can be added to
//allow higher capacitance to be measured.
const float IN_STRAY_CAP_TO_GND = 30.00;
const float IN_EXTRA_CAP_TO_GND = 0.0;
const float IN_CAP_TO_GND = IN_STRAY_CAP_TO_GND + IN_EXTRA_CAP_TO_GND;
const int MAX_ADC_VALUE = 1023;
#include <Wire.h>
#define node 10
union u_capacitance
{
struct
{
float capa_slave;
};
byte bytes[10];
};
u_capacitance capacitanceSlave;
void setup()
{
analogReference(EXTERNAL);
Wire.begin(node); // join i2c bus with address node
Wire.onRequest(requestEvent); // register event
Serial.begin(9600); // start serial for output
pinMode(OUT_PIN, OUTPUT);
pinMode(IN_PIN, OUTPUT);
}
void loop()
{
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void requestEvent()
{
//Capacitor under test between OUT_PIN and IN_PIN
//Rising high edge on OUT_PIN
pinMode(IN_PIN, INPUT);
digitalWrite(OUT_PIN, HIGH);
int val = analogRead(IN_PIN);
//Clear everything for next measurement
digitalWrite(OUT_PIN, LOW);
pinMode(IN_PIN, OUTPUT);
//digitalWrite(IN_PIN, LOW);
//Calculate and print result
float capacitance = (float)val * IN_CAP_TO_GND / (float)(MAX_ADC_VALUE - val);
capacitanceSlave.capa_slave = capacitance;
Wire.write(capacitanceSlave.bytes, sizeof(capacitanceSlave));
//Serial.println(capacitance, 3);
}