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

  • T3
    "You can do all four servos off a single timer ;-) "
    Maybe three? Where do you see the 4th?
  • We make an I2C board with Ublox, mag and tilt sensors on it. The whole cost is probably too pricey ($195), but we have 4 boards that have non-functional magnetometers that we will offer up at a lower cost. These allow direct communication to the Ublox via I2C (3.3V serial port is broken out as well). Each unit also has an 8 channel 24 bit ADC on there and 2 axis tilt sensor. If anyone is interested, make us an offer on what it would be worth as we can't sell them as the original product as they stand now.

    Here is a link:



    Sorry if this counts as a "thread hijack" or violates posting rules, we'll delete this post if it is rude...
    I2C Navigation Board
    I2C protocol based navigation, tilt, and compass heading board
  • The I2c system only requires two resisters to pull up the bus lines. (I used 4.7k pullups) I've heard of people using the internal pull-ups within the ATMega chip instead of external resisters when you only have two devices and short bus lines. Check out the I2c stuff in the Arduino Playground area. They have a couple examples of two Arduinos talking to each other.
  • Great idea! Im planning on using a spare ardupilot v1 board thats been laying around in place of the arduino mini.May need some passives for the i2c bus?
  • Developer
    Pete, Great work! I was planning some type of I2C ArduSlave system. You have created a good starting point for my slave boards. This is an elegant solution to bi-directional ground link as well. Thanks much.
  • It looks like the UBlox5 can also do I2C through the DCC port (one way only).
  • Developer
    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.
  • A clock signal and a Data signal ! Thank to Wiki !!! http://en.wikipedia.org/wiki/I%C2%B2C
  • 3D Robotics
    I2C is a two-wire interface. You need both pins.
  • 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 !!!
This reply was deleted.