Just if anyone is interested, I also just tried to maximally send 4 digits for (up to 9998) the time variable to minimize the amount that needs to be sent. I did it with this code:
#define sf 1000 //change this for wanted sampling fq
//~ #define tc (1000/(sf)) // time constant
#define tc 1000
unsigned int ADC_Value = 0; //ADC current value
unsigned long last_time = 0;
unsigned long t = 0;
unsigned long reset = 0;
void setup() {
Serial.begin(500000);
}
// the loop routine runs over and over again forever:
void loop() {
if (micros() - last_time >= tc) {
last_time = micros();
ADC_Value = analogRead(A0);
// to not have more than 4 digits to send
t = millis()-reset;
if (t >= 9999){
t = 1;
reset = millis();
}
Serial.print(ADC_Value);
Serial.print(',');
Serial.print(t);
Serial.println();
}
}
I will probably just change the experiment so that I never have to collect data for longer than 20 seconds or so. Usually the problem starts not before 50s of data collection.
Maitschi95:
Just if anyone is interested, I also just tried to maximally send 4 digits for (up to 9998) the time variable to minimize the amount that needs to be sent. I did it with this code:
#define sf 1000 //change this for wanted sampling fq
//~ #define tc (1000/(sf)) // time constant #define tc 1000
unsigned int ADC_Value = 0; //ADC current value
unsigned long last_time = 0;
unsigned long t = 0;
unsigned long reset = 0;
void setup() {
Serial.begin(500000);
}
// the loop routine runs over and over again forever:
void loop() {
I still got missing data. E.g.:
312,6712
311,6713
311,6714
3283
316,8284
315,8285
314,8286
I will probably just change the experiment so that I never have to collect data for longer than 20 seconds or so. Usually the problem starts not before 50s of data collection.
That sounds like a practical solution. Or You could treat a miss of data as a swap to the next measurement sequence.