I've been writing my code to make 7 reads of 7 batteries (each one to never gets the 5V limit of the ADS1115
so far they measure fine but there is some error in each reading (after a loop of 3 seconds).
working:
Reading_B1 = ADS1115.readADC_SingleEnded(0);
V_B1 = ADS1115.computeVolts(Reading_B1);
Not working:
Reading_B1 = ADS1115.readADC_SingleEnded(0);
for (int i=0; i< 50 ; i++) {
sample = ADS1115.computeVolts(Reading_B1);
sample_sum += sample;
delayMicroseconds(50);
}
V_B1 = sample_sum / 50;
It happens that in the not working coding the V_B1 value gets stuck at a fixed value.
Did I not see the error in the code?
Try to imagine we can't see your code.
Because we can't.
Don't forget the code tags
No surprise.
Read the comments added. Do You get it?
void controlador_carga(int tempo) {
int16_t Lectura_B1, Lectura_B2, Lectura_B3, Lectura_B4, Lectura_B5, Lectura_B6, Lectura_B7;
float V_B1, V_B2, V_B3, V_B4, V_B5, V_B6, V_B7, VB1, VB2, VB3, VB4, VB5, VB6, VB7, VSol;
Lectura_B1 = revisor1.readADC_SingleEnded(0); //son dos ADS1115
Lectura_B2 = revisor1.readADC_SingleEnded(1);
Lectura_B3 = revisor1.readADC_SingleEnded(2);
Lectura_B4 = revisor2.readADC_SingleEnded(0);
Lectura_B5 = revisor2.readADC_SingleEnded(1);
Lectura_B6 = revisor2.readADC_SingleEnded(2);
Lectura_B7 = revisor2.readADC_SingleEnded(3);
V_B1 = revisor1.computeVolts(Lectura_B1);
VB1 = (V_B1 * 0.7977);
V_B2 = revisor1.computeVolts(Lectura_B2);
VB2 = (V_B2 * 1.8832) - VB1;
V_B3 = revisor1.computeVolts(Lectura_B3);
VB3 = (V_B3 * 2.7159) - (VB1 + VB2);
V_B4 = revisor2.computeVolts(Lectura_B4);
VB4 = (V_B4 * 3.5371) - (VB1 + VB2 + VB3);
V_B5 = revisor2.computeVolts(Lectura_B5);
VB5 = (V_B5 * 4.2734) - (VB1 + VB2 + VB3 + VB4);
V_B6 = revisor2.computeVolts(Lectura_B6);
VB6 = (V_B6 * 5.2699) - (VB1 + VB2 + VB3 + VB4 + VB5);
V_B7 = revisor2.computeVolts(Lectura_B7);
VB7 = (V_B7 * 6.1297) - (VB1 + VB2 + VB3 + VB4 + VB5 + VB6);
delay(3000);
}
this is working
It doesn't compile, so I don't see how it can be said to be working.
Should I put the definition inside the “For” for it to define each time as a new reading???
aarg
7
There are no definitions here, so you're either lost on the terminology, or else you don't understand C++ at all.
What you have to do, is obtain a new value for 'Reading_B1' each time through the 'for' loop... as indicated in reply #3.
It's performed using "assignment" not "definition".
you were right !!!
void controlador_carga() {
int16_t muestra;
float VB1, muestra_convertida, suma_muestras;
suma_muestras = 0;
for (int i=0; i<50; i++) {
muestra = ADS1115.readADC_SingleEnded(0);
muestra_convertida = ADS1115.computeVolts(muestra);
suma_muestras += muestra_convertida;
delayMicroseconds(50);
}
VB1 = (suma_muestras/50);
}
this now read a "stable" output out of the ADS1115 input
thanks
system
Closed
10
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.