Hi all,
I have a project sending multiple serial updates to a display constantly throughout the run time of the system.
From Sensor values and sensor pressures to brightness settings for touchpad and button logos etc.
Im coming across the issue now when if i include these serial writes to the display then it is affecting the rest of the loop with serial input coming to the arduino mega.
sometimes it will work sometimes it wont i'm assuming its because the buffer is filling up with outputs to send and cant process the inputs straight away or something along those lines.
i was wondering what is best practice to cope with this?
The following is some short code as a function sending data to the touchpad.
Each one of these if i comment out the others works flawlessly on its own but if i start to add all of them together then it progressively gets worse.
I currently have a clock in the background sending this data every 300ms
where the TPClockDelay = 300ms
void TpClock() {
CurrentTime = millis();
if (CurrentTime - TpClockDelay >= TimeLastTpDataSent) {
SendTpData();
TimeLastTpDataSent = millis();
}
}
so i started to only send certain data in certain run through of the loop example below. This makes it run smoother again and not fault when the mega is receiving commands but before i continue i didnt know if there is another way i should be going
void SendTpData() {
if(DataPacket < 10){
TankDataToSend();
}
if(10 < DataPacket < 20){
HandbrakeDataToSend();
}
if(20 < DataPacket < 30){
HeightSensorDataToSend();
}
if(30 < DataPacket < 40){
DimmingData();
}
DataPacket++;
if(DataPacket > 40){
DataPacket = 0;
}
}
Would this be the best way to cope with this or do you have other suggestions?
A few of these functions only need to be sent when changing and changing won't happen much ( as in LCD brightness, or if the handbrake has been applied or not, or if the headlights have been turned on etc) so these i could easily only write out when a change has occurred but the other functions such as pressures and height sensors will be constantly updating and would want to be updated to the touchpad display every 300ms or so.
Just after advise what would be recommended to do to send these functions without filling up buffers or trying to send too much data at once
thanks for your time