Need more serial ports.

I have an arduino Mega data-logging project. It's quite a 'busy' application, and it uses all the serial ports (one GPS, one GSM modem, one satellite modem and one serially connected remote arduino)

It also reads from a number of sensors and writes them to an onboard SD card three times a second. Because the system is so busy, occasional there's a delay and I don't manage to write a full three records in one second.

Because of this, I'd like to out-source the logging to a dedicated arduino SD logger (there are several similar ones available). The problem is that the loggers all require an extra serial port - which I don't have!

I'm aware of 'software' serial ports, and I've used them in the past, but they take time and memory, both of which my current application is short of!

Any suggestions?

Cheers

Sure. Move the Arduino to Arduino comms to I2C.

Could you out-source the serial ports with another Mega board ?
There are also SPI/I2C serial port chips.
Or use I2C or SPI to communicate with another Arduino board.
Perhaps an extra Arduino board that has all the sensors and a SD card, and does the reading from the sensors and writing the file on its own.

Why is the "tree records in one second" so important ? Is "now and then" not good enough ?

The problem is that the loggers all require an extra serial port - which I don't have!

You can mechanically/electrically connect a number of external arduino tx pins to a single mega rx input pin by using isolation diodes. The mega would need to be in command control and cycle thru the request for the remote arduinos to send data.

Thanks for the suggestions.

I2C comms probably won't work, the 2nd arduino is several meters away and i2c seems to have a maximum range of about 60cm. I can't move the two devices closer.

Why is the "three records in one second" so important ? Is "now and then" not good enough ?

Ideally I'd like to be sampling at at least 5 times a second, this is one of the reasons for an 'upgrade'

Could you out-source the serial ports with another Mega board ?

Possibly, I could use the mega as a sort-of serial port multiplexer.

Just done some more googling and found this, maybe it would do the trick....
http://www.atlas-scientific.com/product_pages/components/port_connector.html

It's wonderful how powerful an internet search can be, but only if you know the keyword(s) you need. It seems that in this case 'serial port multiplexer' was the keyword!

Three records per second does not seem "busy" to me. On the contrary, it seems to be rather lazy.

Perhaps the problem lies in the way the code is organized.

Post your code.
And please use the code button </> so your code looks like this and is easy to copy to a text editor

...R

Three records per second does not seem "busy" to me. On the contrary, it seems to be rather lazy.

Post your code.

the code is enough to almost fill a mega - to big to post here.

The problem is the variability of how long a 'write' to the SD card takes, although a typical record (100 characters) might take as little as 45 ms, it occasionally takes 100 or even 200ms.

Most of the stuff the application does takes a fixed period to execute, and happens at a known interval. For instance I know that the GPS will spew out data 172ms after the last spurt, and I know that processing it will take 6ms. I also know that it takes 12ms to process altitude data and takes 4ms to update the screen. Because these timing are known and (more-or-less) constant I can code appropriately. For instance I know that I don't want start anything too time-consuming (i.e. checking for a satellite message) just before the GPS is due to spurt out data because if I do I might miss the GPS data.

The time taken for an SD write cycle is the big unknown, hence the desire to outsource it to another device.

That serial port expander is a mux. You can only listen to one serial port at a time.

We don't care about big sketches. Zip the project and attach it. The Quick Reply text field has no attach option, click the 'REPLY' button for more options.

Is something wrong with the SD card ? Do you have another one ? With less memory and faster ?
Did you do this : Don't Format SD cards with OS utilities! - Storage - Arduino Forum

I agree, three times a second isn't that busy...

Fulliautomatix:
the code is enough to almost fill a mega - to big to post here.

:o The project you described in the start post does not sound like it should fill up a Uno, let alone a Mega! Damn. Or do you use 100 instances of String or something?

So indeed, zip it or pastbin it and post it.

Is something wrong with the SD card ? Do you have another one ? With less memory and faster ?
Did you do this : Don't Format SD cards with OS utilities! - Storage - Arduino Forum

Hmmm......

Going back to the drawing board it's apparent that the problem is not with my whole application being 'busy', it's with my logger class (written by myself and unchanged for several years).

The link quoted mentions write speeds of 358 kB/sec with a 100 byte buffer.

I've written my own test routine for my logger class which records an average of 50ms to write a single, random, 100 character record. Multiply this up and I get 2000 bytes in 1 second. or 2kb/sec. Well below what I guess I should getting.

I have tried this with 3 different SD cards all formatted with the utility mentioned in the link. I guess this leaves just my code. On the plus side I seem to have narrowed the problem down to a specific library.

That is slow! Even with the default Arduino libraries it should be a lot faster. In the worst situation, you should get at least 20kb/sec.

Ok, it seems that at least part of the problem is that my logger is doing an open(), write() and close() for every single line added.

I have got the figure up much more respectable 45000 chars/sec.

I wrote the logger ages ago, and forgot that it had two mode, the first does a open,write and close on every line, and the 2 second does one open, and one close and only does a write once per line.

I did most of my testing in the fast mode, and then forget that I was using it in the 'slow' mode in my application. I believe at one point in my project the damn thing was failing so often that used the slow mode because it ensured I never lost data due to a crash.

Thanks for everyones help.