I'm making this Electric Impedance Tomography project on proteus and the code is in arduino Mega1280. The circuit is working fine. The problem is when I'm simulating the circuit on proteus, the input voltages coming to A0 pin are being printed as 0 for some reason. Even though when I put a probe on that wire and it shows the voltage, arduino is printing as zero. Can someone help me?
Here is the code:
//library of the multiplexors
//library for calculating RMSvalues
// loop period time in microseconds (time between samples)
#define LPERIOD 1000
// define the used ADC input channel
#define ADC_INPUT 0
// RMS window of 40 samples, means 2 periods at 50Hz
#define RMS_WINDOW 40
unsigned long nextLoop;
// ADC full scale peak-to-peak is 5.00Volts
float VoltRange = 5.00;
// create an instance
Rms readRms ;
readRms.begin(VoltRange, RMS_WINDOW, ADC_10BIT, BLR_ON,CNT_SCAN);
// Set the loop timer variable for the next loop interval.
//micros( ) Returns the number of microseconds since the Arduino board began running the current program.
nextLoop = micros() + LPERIOD;
//electrode 0 and 1//electrode 0 and 1
for (int k=2;k<15;k++)
// Read the ADC and remove the DC-offset
adcVal = analogRead(ADC_INPUT);
//take an instance again
//repeating the readings of one sample
if(cnt >= 500)
// publish every 0.5s
// wait until the end of the time interval
while(nextLoop > micros());
// set next loop time to current time + LOOP_PERIOD
nextLoop += LPERIOD;
Im sorry I provided the code the way I did
Im relatively new to coding so I just copy pasted the code from a paper I found. And also the code provided didn't have any loop function. I just added an empty loop function so that the code can be compiled successfully.
Can you explain me how I can fix the issue?
It should be printing the voltage values but this is all it's printing
Yeha the voltage is no longer zero. I'm not sure how fast it exactly is but the voltage variation is rapid on the probe. By the way I provided the proteus file. Can you please check it if possible? I'm not very good at debugging and coding so Im assuming you might get a better idea if you check it
Tbh I copy pasted it from a research paper. The original code didn't have any loop function. I added an empty void loop just to avoid compilation error. And for this situation I just want 13 values so I didn't modify to put it in loop
The analogRead() function makes the assumption that the function parameter refers to an analog pin, so you can use just the number 0 for A0, 1 for A1, etc. The danger with this is that pinMode(), digitalWrite(), and digitalRead() cannot make this assumption, and will instead use digital pin 0 when given the 0 instead of A0. If the code had used pinMode(ADC_INPUT) it would have set the mode of digital pin 0 (the Rx pin) instead of A0.
I think I see your problem. The input is always 1023 (5V) and you have 'baseline restoration' turned on. I think that means the RMS library is taking an average of your readings and calling that the baseline (0V) . Since your signal is not varying you never get a signal other than baseline. The RMS average is 0.
blr sets the automatically baseline restoration function on or off. Use the predifined constants BLR_ON or BLR_OFF.