void loop()
{
int16_t adc0, adc1, adc2, adc3;
int16_t i=0;
for (i=0; i< 4; i++) {
adc0 = ads.readADC_SingleEnded(i);
delay(10);
adc1 = ads.readADC_SingleEnded(i);
delay(10);
Serial.print(i); Serial.print("...read0 (bogus): "); Serial.println(adc0);
Serial.print(" ...read1 (real ): "); Serial.println(adc1);
}
Serial.println(" ");
delay(1000);
}
This new version of the thrash loop reads each port twice.
Watch this output:
0...read0 (bogus): 3165 // my pot is really on A0 set to min
...read1 (real ): -1 // second read gets it, why -1 I have no idea. s/b 0
1...read0 (bogus): -1 // notice 1st read of pin 1 is same as 2nd read of pin 0
...read1 (real ): 3121
2...read0 (bogus): 3160
...read1 (real ): 3142
3...read0 (bogus): 3165
...read1 (real ): 3155
0...read0 (bogus): 3175
...read1 (real ): -1
1...read0 (bogus): -1
...read1 (real ): 3132
2...read0 (bogus): 3162
...read1 (real ): 3142
3...read0 (bogus): 3158
...read1 (real ): 3141
0...read0 (bogus): 3161 // OK now I am cranking up the pot
...read1 (real ): 3800 // 2nd read catches the real value
1...read0 (bogus): 3857 // and 1st read of pin 1 also seems to sample pin 0
...read1 (real ): 3134
2...read0 (bogus): 3169
...read1 (real ): 3152
3...read0 (bogus): 3172
...read1 (real ): 3158
0...read0 (bogus): 3169
...read1 (real ): 6089 // I keep cranking the pot up
1...read0 (bogus): 6124 // pin 1 is tracking pin 0 on the first read
...read1 (real ): 3133 // but reading correctly as floating on the 2nd read
2...read0 (bogus): 3163
...read1 (real ): 3133
3...read0 (bogus): 3167
...read1 (real ): 3154
0...read0 (bogus): 3180
...read1 (real ): 8012 // crank crank
1...read0 (bogus): 8047
...read1 (real ): 3147
2...read0 (bogus): 3159
...read1 (real ): 3144
3...read0 (bogus): 3163
...read1 (real ): 3140
0...read0 (bogus): 3161
...read1 (real ): 9979
1...read0 (bogus): 10022
...read1 (real ): 3144
2...read0 (bogus): 3159
...read1 (real ): 3141
3...read0 (bogus): 3173
...read1 (real ): 3159
0...read0 (bogus): 3170
...read1 (real ): 13918
1...read0 (bogus): 13946
...read1 (real ): 3149
2...read0 (bogus): 3160
...read1 (real ): 3138
3...read0 (bogus): 3163
...read1 (real ): 3147
0...read0 (bogus): 3170
...read1 (real ): 16808
1...read0 (bogus): 16808
...read1 (real ): 3160
2...read0 (bogus): 3160
...read1 (real ): 3148
3...read0 (bogus): 3165
...read1 (real ): 3146
0...read0 (bogus): 3162
...read1 (real ): 17573 // max pot value
1...read0 (bogus): 17573
...read1 (real ): 3145
2...read0 (bogus): 3165
...read1 (real ): 3146
3...read0 (bogus): 3170
...read1 (real ): 3165
0...read0 (bogus): 3178
...read1 (real ): 17572
1...read0 (bogus): 17572
...read1 (real ): 3158
2...read0 (bogus): 3164
...read1 (real ): 3138
3...read0 (bogus): 3161
...read1 (real ): 3139
0...read0 (bogus): 3169
...read1 (real ): 17573
1...read0 (bogus): 17573
...read1 (real ): 3155
2...read0 (bogus): 3170
...read1 (real ): 3149
3...read0 (bogus): 3163
...read1 (real ): 3148
0...read0 (bogus): 3162
...read1 (real ): 14120 // now I am turning the pot down
1...read0 (bogus): 14050 // and pin 1 is now reading a few counts lower than pin 0
...read1 (real ): 3145
2...read0 (bogus): 3159
...read1 (real ): 3143
3...read0 (bogus): 3159
...read1 (real ): 3155
0...read0 (bogus): 3185
...read1 (real ): 12574
1...read0 (bogus): 12500
...read1 (real ): 3150
2...read0 (bogus): 3159
...read1 (real ): 3141
3...read0 (bogus): 3154
...read1 (real ): 3142
0...read0 (bogus): 3164
...read1 (real ): 7680
1...read0 (bogus): 7596
...read1 (real ): 3139
2...read0 (bogus): 3165
...read1 (real ): 3149
3...read0 (bogus): 3171
...read1 (real ): 3157
0...read0 (bogus): 3166
...read1 (real ): 2669
1...read0 (bogus): 2559
...read1 (real ): 3129
2...read0 (bogus): 3162
...read1 (real ): 3133
3...read0 (bogus): 3162
...read1 (real ): 3150
0...read0 (bogus): 3171
...read1 (real ): -1 // pot at zero again
1...read0 (bogus): -2
...read1 (real ): 3132
2...read0 (bogus): 3164
...read1 (real ): 3143
3...read0 (bogus): 3162
...read1 (real ): 3140
0...read0 (bogus): 3157
...read1 (real ): -1
1...read0 (bogus): -1
...read1 (real ): 3122
2...read0 (bogus): 3156
...read1 (real ): 3145
3...read0 (bogus): 3173
...read1 (real ): 3162
This has had me going in circles. When I first tested the thing, I hung the pot on one port and did a loop reading all four ports while twiddling the pot. I connected the pot to A0 but saw A1 changing as I twiddled, so I thought the silk screen on the board was wrong! When I moved the pot to A1 I saw A2 changing. So I thought the silk was really wrong.
Now I see that (for whatever reasons) if I am monitoring a voltage on port 0, when I read port 0 the first time I get garbage; on the 2nd read I get the real value. If I then read port 1, I get the updated value from port 0. If I read port 1 again, I get the real reading from port 1. And so on.
So for my code to work it will have to read any given port on the ADC twice in a row to be sure of getting a sensible value.
Maybe this all makes sense if you know how ADCs really work. All I need to know is that the 2nd read is the one that works.
A strange postscript to all this: I tried reading each port 3x. When I do this, I get:
Port A0, read 1: bogus data
Port A0, read 2: good data
Port A0, read 3: good updated data
Port A1, read 1: good data?
Port A1, read 1: good data?
Port A1, read 1: good data?
So when I do three reads instead of two, I don't get the bizarro effect of the data from port 0 being "copied" to port 1. What is magic about three reads? Search me. If anyone has a good, rational explanation for all this I'd be interested to know more. But for the moment, knowing that you have to "knock twice and ask for Charlie," I can keep moving ahead with my project...