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.zip

And 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.

Views: 4962

Comment by Sarel P. Wagner on October 8, 2009 at 12:12pm
Very neat Pete!

3D Robotics
Comment by Chris Anderson on October 8, 2009 at 12:13pm
Nice work! But you're going to need a bigger plane ;-)
Comment by Peter Meister on October 8, 2009 at 2:32pm
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....

Comment by Jordi Muñoz on October 8, 2009 at 3:08pm
Nice!! i prefer this than switching to ArduPilot Mega. If i can just have one extra 16bit timer to control four servos. ;-(
Comment by Angus Peart on October 8, 2009 at 3:21pm
You can do all four servos off a single timer ;-)
Comment by Pete Burnight on October 8, 2009 at 4:10pm
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.
Comment by Jason Larocque on October 8, 2009 at 6:02pm
I wasn't aware that ArduPilot had the I2C capability ! Why do you use 2 ports ? (Analog 4&5 ) One Input and one Output ? Nice work by the way ! I'll try the same thing with my extra ArduPilot !!!

3D Robotics
Comment by Chris Anderson on October 8, 2009 at 6:08pm
I2C is a two-wire interface. You need both pins.
Comment by Jason Larocque on October 8, 2009 at 6:27pm
A clock signal and a Data signal ! Thank to Wiki !!! http://en.wikipedia.org/wiki/I%C2%B2C

Comment by Jordi Muñoz on October 8, 2009 at 8:33pm
Yes i2C is a low speed bus and you can hook up to 128 devices using only two wires.

Yes you can control 4 servos using one timer but is very noisy. Other important interrupts make the servos tiny bit unstable, if you connect a servo on the throttle output of arduino you will see a tiny glitch, but you can't tell when you use a motor controller.


You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2018   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service