Hi,
I've got a project that that involves reading from a dozen sensors, processing the results, displaying them on a LCD screen, and logging everything at regular intervals.
Reading and processing each sensor takes time, this ranges from about 80ms (reading an Ultrasonic rangefinder) to 40ms (reading atmospheric pressure) and about 4ms to read windspeed from an anemometer.
I'm also reading incoming serial data on all four serial ports (GPS, radiation levels, power input, control inputs).
Adding to the complexity is the fact that the serial data is arriving at known intervals at a high baud rate - this means I need to know when data is about to arrive, and make sure I'm listening to the port just when it does. (if I start a 80ms read from the rangefinder just before a few hundred bytes arrive on a serial port, then most of that data will have already overflowed the serial buffer before I'm ready to start reading it).
Currently, I can just about manage to log consistently about once a second. But I'd like to be able to up that frequency to at least twice a seconds (ideally 10 times a second). However, I've run out of ideas about how to speed things up, I've been through my code and have managed to save a few milliseconds here and there, but many of the bottle-necks are outside of
my control. For instance, some of the i2c devices require 30ms (or more) to return their results, and I can't control this. The rangefinder requires the pulseIn() function that seem to take up to 90ms to provide a result.
In the past I've managed to speed things up by building a separate, dedicated logger (a mini-pro with a SD card), but this requires access to another serial port -which I not longer have!
Any suggestion?
Thanks