Calculate the number of serial bytes your sending: the sheer volume of data is making it impossible to get 40 readings/second through the line.
You can do several things to speed things up:
1. Go to 115K baud.
2. Shrink the data volume by formatting the A/D readings in hex (this will only help if they're > 1000 a lot of the time).
3. Buy some USB-to-serial adapters, and split the Arduinos into multiple strings. If you double the baud rate and go with two strings of 6, you should just about make your 40Hz rate. You can avoid changing your Arduino software by having the GPS drive multiple strings, and stripping the GPS data from all but one.
You might also get some improvement by increasing the I/O overlap. Change your main loop to something like this:
serial_in_not_done = 1;serial_in_not_done
for (i = 0; i < 6; i++)
is a global that gets set to 0 when the linefeed arrives in the serial input stream.pass_through_serial
() exits immediately if serial_in_not_done
is 0. Otherwise, it checks for pending serial input, passes it through to the output, and watches for the linefeed.read_analog
() reads an analog input, and formats it with something like sprintf or itoa into an appropriate spot in a buffer that holds all the readings as one string.append_my_readings
() sends the buffered readings to the serial output (with the terminating LF).
With this approach, you'll probably have all your data ready to go by the time the LF shows up in the input stream, minimizing processing delays.