Overloaded data-logger.

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

If you really can't keep up, consider offloading some of the work to a second arduino - you can talk to it over serial (or software serial).

Alternatively, post your code.

consider off-loading some of the work to a second arduino - you can talk to it over serial

I'm already using all four serial ports, and software serial tends to be quite resource-intensive (and I'm already struggling with resources)

Alternatively, post your code.

Not really practical - it's over 30 libraries and compiles to 150k.

Most of the biggest bottle-necks seem to be outside of my control, if an i2c device takes 35ms to return a value, I don't see much I can do about it, similarly, when it takes 80ms for the pulseIn() function to return something it just have to put up with it.

Is the mega 2560 the biggest/best arduino available? do any other boards have more clout?

What I'm suggesting is that you can afford to give up a serial port if the second Arduino can take care of the function you were using it for and as a bonus a few others besides. For more speed & RAM, take a look at the Teensy 3.0 - cheap too :slight_smile:

ok, I get it you mean daisy-chain them together.

I'll have a look at the teensy - seem to have more oomph than the mini-pro - what I usually use when I need to downsize!

similarly, when it takes 80ms for the pulseIn() function to return something it just have to put up with it.

No. You could use the NewPing library, which uses interrupts to provide non-blocking behavior.

You could use the NewPing library

looks ideal, will try using that instead!