Not quite a newb, but I'm learning as I go, and this is getting into unfamiliar territory...
My project is a multicopter flight controller. I have gotten to the point, that it is taking so long to read from the various I2C devices, that I am exceeding my 4 millisecond cycle time (250Hz) including 2ms for doing all of the calculations and sending the esc pulses. On top of that, I am adding a GPS, which is strictly serial.
I decided to split the duties between an Uno (for handling the RX inputs, calculating PID's, sending motor control signals, etc.) and a Pro Mini for reading the Gyro, Accel, Mag, Pressure, GPS, etc., data over serial and I2C.
The Pro Mini is reading data in from an Adafruit 10DOF board, via I2C and a 28 byte block of UBLOX protocol from a Neo 6M GPS, over serial. In the future, I hope to add inputs from sonic sensors.
I have the code written to read all of the sensors and I'm working on keeping the cycle time well under the maximum 4ms (even with Serial.prints in the loop, as I get setup). But, I have found that, whether I am reading data from the GPS, or not, the SoftwareSerial serial.begin(9600) consumes about 10 cycles, every 100ms (10Hz), which corresponds to the refresh rate of the GPS. The GPS data is 28 bytes read in with a while ( Serial.available() ).
- Are there ways to shorten this enormous pause, to read 28 bytes of data?
- If not, it seems the best alternative is to read the gyro and accelerometer at 250 Hz, directly with the UNO and leave the rest of the reading to the Pro Mini. How do I ensure that the Uno and Pro Mini are able to play nice, as they are both reading from the same I2C wires? And, how do I do all of this in a way that the Uno is able to read the Gyro/Accel and read the data from the Pro Mini as fast as possible?