Working with an UNO and Adafruit datalogger, having a few problems with the code I have put together. I want to write to SD card every minute. Between writes, I want to count the number of pulses from three pulse flow meters. RTC is being used to print the time of each sample. Trying to cut down in delays by using the 60 second pulse sample since the analog reads are only required once a minute. My problems are, the timing is not standard but sporadic. Instead of at set intervals ( which have been shortened for troubleshooting) it prints in bursts, if at all. Second, it's not actually writing to the file. The data will print to the serial window but fails to write to the SD file. As a side note, is anyone aware of conflicts with the Adafruit datalogger and the selected digital pins? I don't have the flow sensors attached and I am still reading pulses so I assume that is the problem. I have attached the code in a separate file.
The compiler won't complain since it is technically legal, but who knows what is sitting out there in memory 5 slots past the end of your array. Anytime you have something like this you're going to have unpredictable results. There's no use troubleshooting any further until this is fixed.
Right, sorry. It's my understanding that PulseOutput p[3] creates an array of three positions. But the values that enter those three positions are affected by the change in state of the register. I have changed the points you outline to p[0], p[1], and p[2] but I still get the same issues.
DHResearch:
Right, sorry. It's my understanding that PulseOutput p[3] creates an array of three positions. But the values that enter those three positions are affected by the change in state of the register. I have changed the points you outline to p[0], p[1], and p[2] but I still get the same issues.
Nope. The indices to an array are pretty straight forward. There are no registers involved. If you create an array with 3 elements then they are numbered 0, 1, and 2.
Here is the code. Adjusting the array did fix the writing to file problem (though it doesn't write properly to the window now?). Still getting one pin with a large pulse count despite now sensor being connected. Thanks by the way for your help.
I removed those now. Finally understood my mixup with the array/ register confusion after reading more. Those defines were never called, would they still affect the readout?
Oh, I took your word that you changed to 0, 1, and 2. You did in a few spots, but you used 1, 2, and 3 in others. 0, 1, and 2 are your only legal indices to a 3 element array.
p[1].pulse(0,a,time); // Digital input 1
p[2].pulse(1,a,time); // Digital input 2
p[3].pulse(2,a,time);
Worked on it more. Cleaned up the code and put the file naming/saving part into it's own function. Still having trouble getting an accurate pulse read though. I've chosen digital pins 5-7 for the inputs. These aren't use by the shield, but somehow I am not getting the right pulse count.