My son and me are trying to build a eDrum using Arduino UNO. We have 3 piezo sensor discs, each of which can be read as expected using analogRead() individually, but having difficulty in reading them simultaneously (rather sequentially).
Have read and I think understood the part that the UNO has a single 10-bit SAR-type ADC that takes 13 clock-cycles to produce 10-bit resolution output, for each pin. Also understood that the S/H capacitor needs a finite bit of time to charge. I have introduced delayMicroseconds(20). The analog value read is then compared against a Threshold (values tried from 20-200), and only if higher than Threshold is the number 1, 2 or 3 printed on Serial output. The Serial port baudRates tried are 9600, 19200, 115200 and the observation is unimpacted, i.e. whenever I hit the piezo disc connected to pin A0, I notice that both 1 and 2 are printed (almost 90% of the times). When I hit piezo disc connected to ping A2, I notice that 90% of the time, I get 3 printed. Of course, because there is no debounce logic, I actually get output like:
when disc connected to A0:
1 2 1 2 1 2 1 2
where-as, I'd expect to see only 1.
when disc connected to A2:
3 3 3 3 1 3 1 3
where-as, I'd expect to see only 3.
Finally, I modified the code to try to introduce some crude de-bounce logic using averaging (3 rounds). Also I tried using Faster ADC mechanism found here. AFAIU, it modifies the ADC prescaler and sacrifice the resolution, for faster ADC read.
Code:
#include <Albert.h>
const int BaudRate = 19200;
const int Threshold = 150;
const int AvgLoopCt = 3;
int sensVal1 = 0;
int sensVal2 = 0;
int sensVal3 = 0;
int loopCount = 0;
void setup() {
Serial.begin(BaudRate);
}
void loop() {
if (loopCount < AvgLoopCt) {
sensVal1 += analogReadFast(A0, 2);
delayMicroseconds(10);
sensVal2 += analogReadFast(A1, 2);
delayMicroseconds(10);
sensVal3 += analogReadFast(A2, 2);
delayMicroseconds(10);
loopCount++;
}
else {
if ((sensVal1 / AvgLoopCt) >= Threshold) {
Serial.print("1 ");
sensVal1 = 0;
}
if ((sensVal2 / AvgLoopCt) >= Threshold) {
Serial.print("2 ");
sensVal2 = 0;
}
if ((sensVal3 / AvgLoopCt) >= Threshold) {
Serial.print("3 ");
sensVal3 = 0;
}
loopCount = 0;
}
}
Would appreciate any help in trying to understand what the problem is. Kindly note that, instead of using the "Albert.h" (Fast ADC) library, using the standard inbuilt readAnalog(), the results aren't much different.
The circuit is connected on a breadboard and I've ripped apart the circuit assembly several times and reconnected, but that hasn't helped.