I2c GPS frees up Serial Port

I wanted two way communication with my airplane, and had moved the serial communication stuff to a 2nd arduino (see my prev blog) but I didn't like the way the code looked, so I reconfigured the system to have the 2nd Arduino handle the GPS and Gyro, and then use I2c to send the data to the main processor. Essentially making the GPS into an I2c device, and freeing up the main serial port for 2-way com with the ground.

This works out great. The GPS code is very static (doesn't change) so the code within the 2nd Arduino doesn't have to be updated all the time. (at all) Having the Gyro and GPS together works great - the 2nd arduino becomes an I2c GPS / Heading device that the host simply polls 5 times a second to get the current heading and location. This works better with the I2c protocol ... we're sending small blocks of data instead of the huge text based data I was trying to send around.5 times a second, the host asks the slave for 32 bytes of data. The slave returns the following data:float Gyro_Heading;float GPS_Lat;float GPS_Lon;float GPS_Altitude;float GPS_CMG;float GPS_Speed;long GPS_TimeStamp;int Gyro_Rate;int Flags;The slave takes care of reading the Gyro every 20ms, and updating the Gyro_Heading value.Every time it gets new GPS data, it updates the Gyro_Heading, which takes care of any gyro drift.This has turned out to be a much better way to organize the system. The code in the Arduino slave is static, it is essentially an I2c front-end to the GPS code. The changes to ArduPilot are now minimal. It still calls decode_gps() - which simply requests, and returns the I2c data, and now all the debugging and Serial.println stuff to and from the ground station is back in the main code and much easier to change and much more straight forward.Here's a link to the slave source code: ArduinoSlave.zipAnd another thing...The slave Arduino board started out so pretty... and then things happen.

I used the Spark-Fun XBee carrier board 'cause it said it would hook directly into 5 volt systems, and would actually tolerate up to 12volts of input. The Arduino Mini will also regulate it's own power - so I could use an external 7.4v lipo and not have to do a power supply. Yea !! The gyro gets it's +5 volt power from the Arduino Mini's regulated +5 volt pin. It draws nothing. Great - I could hook up the XBee and Arduino directly to the lipo. Very tiddy. But NO. I had all the code working on the bench, installed everything in the plane. Ready for a test flight, but ... no data coming to the ground station ?? all the lights are blinking - everybody's sending and receiving something ???Turns out the Spark Fun XBee board doesn't like talking directly to my Arduinos. Tx Signal lines are too strong. If I put a voltage divider inline, it mostly works, but with noise garbage here and there. Yuck. I hate flaky com lines. I even tried their level converter chip, but still garbage. (strange - 'cause I've used these before with great success)So I switched back to the Ladyada XBee board, but it doesn't like the 7 volt lipo. (its on board regulator gets too hot) It wants +5volts - but I don't want to pull thru the Arduino Mini's regulator - too much draw - 250 mah. So I bite the bullet and put a 5 volt regulator where the SparkFun XBee board was, and went back to the external XBee board. What a hassle.

But the connections to the system are now very tiddy. Mini Slave board has it's own power from the 7.4v lipo. GPS plugs into the Mini Slave board (and gets it's power from my 5 volt regulator) Power lines from XBee board plug into my Slave board, and also use my 5 volt regulated power. Arduino mini regulates it's own power from the lipo, and provides power for gyro. Only 3 connections to the main system. Two wires plug into Analog 4&5 for the I2c line. 2 wires plug into the TxRx pins (where the ftdi plug goes) and 1 wire plugs into a servo ground.
E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • Well - After ripping everything apart, I tried hooking up a +5 volt Arduino directly to the Spark Fun XBee board, and on my bench, with a regulated +5 volt supply, everything worked perfect. Very mysterious.
  • You can do all four servos off a single timer ;-)
  • Developer
    Nice!! i prefer this than switching to ArduPilot Mega. If i can just have one extra 16bit timer to control four servos. ;-(
  • Most impressive pete. A great write up. It would be great to provide a buildout thread on this so others could attempt. Sounds very DIYable for the others members....
  • 3D Robotics
    Nice work! But you're going to need a bigger plane ;-)
  • Very neat Pete!
    Rgrds
    Sarel
This reply was deleted.