Stop Delaying Traffic!
Obligatory visual metaphor.
I’ve had a very tedious problem with ‘traffic’ in my network. Due to jitter from each sensor it means that each slave device is constantly sending information to the master. Each time a message is sent to the master, I have the arduino run the delay() function. After doing some research this evening, I read an interesting article on the arduino site (find it here).
I know that the delay function means that nothing else can happen during the specified time. I delay for 8 ms on each packet sent from the slave device. Because of this jotter issue, this means that the slave device sends a packet of information on each passing of the loop() function within arduino. To speak english – Every 4ms or so I delay for 8
and so on…
So, let’s visualise this issue one more time..
This is more time of doing nothing that is actually running code. This code contains vital ‘listeners’ waiting for information from the master device for information to update the LED. At this point, this information is typically lost or very infrequent. Whilst removing the delays won’t stop the jitter issue, It may well keep the code running at a crucial point of receiving this information. Moving forward, I will be replacing my delays with timers using millis() – an arduino function which allows us to count a measure of time before performing another task – thus keeping busy whilst waiting on its time to do something else, keeping the master happy!