HI Guys,
I am working on a simple datalogger which includes 4 different sensors and SD card.
Everything is working fine but I would like to increase the sampling rate.
Currently I am getting approximately each reading every ~800ms.
Please suggest how to optimize the code for higher sampling rate.
Serial.begin(9600); // could be faster
delay(50); // etc. directly or indirectly in the loop clearly slows things.
sensors.requestTemperatures(); // maybe check how fast this is
c = thermocouple.readCelsius(); // maybe check how fast this is
lcd.print("No T/C"); // etc. LCD operations are not fast. Do you need to do these every loop iteration ?
Maybe use a buffer here and consolidate to 1 write per target stream:
Serial.begin(9600); // could be faster
delay(50); // etc. directly or indirectly in the loop clearly slows things.
sensors.requestTemperatures(); // maybe check how fast this is
c = thermocouple.readCelsius(); // maybe check how fast this is
I just noticed that max6675 requires at least 200ms every cycle.
My intensional delay of 50ms adds up to 250ms (roughly).
I am still losing 550ms.
6v6gt:
Maybe use a buffer here and consolidate to 1 write per target stream:
Do you mean to write on serial and SD as a string?
Maybe look at sprintf() to format the output and pack it into a buffer for printing/storing to the SDcard.
With the 2 floats, you may have to play a trick like treating the whole number part and the decimal part as separate integers with a '.' in between. Depending on which Arduino you are using, floats may not be directly compatible with sprintf().