My data logging setup uses three DS18B20 and a flow meter with display to a LCD and serial feed to Bluetooth. Backup to SD and internet feed is only every ten seconds. I want display and serial update at one second intervals and have a delay of 850ms to achieve this. Display is a 5110 and six numbers are updated.
I am currently upgrading one Mega to use a 400x240 TFT screen. At the moment, I am just using one DS18B20, so the loop is mostly about the display, but it is taking more than a second to go round and I have been obliged to add 3900ms to get an update at five second intervals. Thus, if I want one second updates, I am about 100ms short, and it's only going to get worse.
This is really disappointing. The fundamental difference between the two is that, with the TFT, I am updating one more number and two graphs. To add insult to injury, the slow update obliges me to draw lines on the graph rather than simply add a pixel, which I guess makes a bad situation worse.
Needless to say, all the fixed text etc. is done in the setup.
EDIT
OK I have solved the problem sufficiently to enable one-second updates. There was a degree sign on the screen that was flashing when it shouldn't have been, which revealed a right-royal ballsup in the subroutines - stuff in the wrong place and stuff being displayed twice. The loop is unchanged, but fixing the subroutines has saved me 200ms, which is twice what I need right now, and may suffice for the finished product. This still means that using this display slows the process considerably.
void loop() {
int t = millis();
sec = sec + 1;
if (sec>460)
{
runscrn ();
sec = 101;
}
GetClock();
if (hour == 0 && minute == 0 && second <2)
{
getFileName();
}
//get the values from the DS8B20's
sensors.requestTemperatures();
InTemp = (sensorValue(InThermo));
// OutTemp = (sensorValue(OutThermo));
// DrainTemp = (sensorValue(DrainThermo));
Serial.println(InTemp);
diff = (InTemp - 20)/2;
if (flag =1)
{
running();
}
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(255,255,255);
tab = 174;
if (DrainTemp<10)
{
tab = 182;
}
myGLCD.printNumF(DrainTemp, 2, tab, 150);
tab = 174;
if (InTemp<10)
{
tab = 182;
}
myGLCD.printNumF(InTemp, 2, tab, 165);
tab = 174;
if (OutTemp<10)
{
tab = 182;
}
myGLCD.printNumF(OutTemp, 2, tab, 180);
tab = 182;
if(int(flow) > 9)
{
tab = 174;
}
myGLCD.printNumI((int)flow, tab, 210); // Print the integer part of the variable
myGLCD.drawCircle((tab+10),219,1); // Print the decimal point
frac=(flow - int (flow))*100;
myGLCD.printNumI(frac,(tab+16),210) ; // Print the fractional part of the variable
tab = 174;
if (Conv < 10 && Conv >=0)
{
tab = 182;
}
if (Conv < -10)
{
tab=166;
}
myGLCD.printNumF(Conv, 2, tab, 225);
tab = 174; // diff is two digits or 1 digit plus "-" sign
if (diff <10 && diff >=0)
{
tab = tab + 8;
}
if (diff < -10)
{
tab=tab -8;
}
myGLCD.printNumF(diff, 2, tab, 195);
myGLCD.setFont(SevenSegNumFont);
kW=InTemp/3;
whole = int (kW);
frac = int((kW - whole) * 10);
tab = 362;
if (whole <10)
{
tab = 394;
}
myGLCD.setColor(0,255,255);
myGLCD.setBackColor(0,0,0);
myGLCD.printNumI(whole, tab, 190);
myGLCD.printNumI(frac, 436, 190);
myGLCD.setColor(0,250,200);
myGLCD.drawLine((sec-1),(125-int(oldiff*10)),sec, (125-int(diff*10)));
myGLCD.setColor(255,150,0);
myGLCD.drawLine((sec-1),(125-int(kW1*10)),sec, (125-int(kW*10)));
kW1=kW;
oldiff=diff;
delay(3906);
int t2 = millis();
int tim = t2-t;
Serial.println(tim);
}