2nd Arduino adds 2-way Com with Ground

I wanted two way communication with my aircraft, but when the GPS is running, the Arduino board only has 1 side of its single serial port available, so I added another Arduino Mini to provide 2-way communication between my ground station and the aircraft.The additional board consists of a 5 volt Arduino Mini Pro, with a ATMega 328 chip running at 16 mHz, and a Spark Fun 5 volt carrier board for the XBee. That's it. I had to move my Gyro to this new board, cause I used I2c to link the main ArduPilot board with my new "com" board, and I2c uses the Analog Pins 4 & 5 for communication. (I had my gyro on analog 4&5)

It takes three wires to connect to the ArduPilot board - SDA, SCL and Ground. The two I2c wires go to Analog pins 4 and 5 on the ArduPilot board. Ground plugs into an open servo socket. I used a separate 7.4v lipo battery to power the new Arduino and the XBee. (the XBee 900 XSC draws 250 mah during transmission)

The code changes within ArduPilot were very minimal. I used the Wire Library for I2c. It's not efficient, but it's easy to use. It uses blocking reads, which means your code is sitting around waiting for the data to arrive back, instead of being able to go about your business until an interrupt tells you your data is ready. I'll improve this later.All of my downlink data (data going to the ground station) is isolated within the print_data() function - so making the changes was easy. I used the PString library to mimic the Serial.print calls, so code that used to look like:Serial.print(",CRS:");Serial.print(ground_course);Serial.print (",SPD:");Serial.print(ground_speed);Serial.print(",CRT:");Serial.print(climb_rate);Now looks like:theStr.print(",CRS:");theStr.print(ground_course);theStr.print (",SPD:");theStr.print(ground_speed);theStr.print(",CRT:");theStr.print(climb_rate);Wire.beginTransmission(4); // transmit to our I2c slave Arduino (ID=4)Wire.send(theStr);Wire.endTransmission();The slave Arduino takes all I2c data it receives from the master and transmits it out it's serial port to the XBee where it continues thru space to the ground station.// This is the interrupt routine in the slave Arduino that gets called every time// the master sends out some data.void master_has_sent_us_data (int howMuch){byte slen=0;while (Wire.available() > 0){RxBuffer[slen] = Wire.receive();if (slen < MAX_BUF_INDEX) slen++;}RxBuffer[slen] = 0; // terminating zero for c-stringSerial.println(RxBuffer); // Send to Ground Station via XBee}// -------------------Reading the Gyro is easy. It's actually an analog gyro, but now the main software reads it like it's an I2c gyro. Every 20ms the main loop calls:Wire.requestFrom(4, 4); // request 4 bytes from our slave device #4if (Wire.available() >= 4){gyro = (Wire.receive() << 8) + Wire.receive(); // read 2 bytes as an IntvRef = (Wire.receive() << 8) + Wire.receive();}// -----So for about $40, and a couple hours wiring, I get another serial port, 4 more analog ports (2 of the 6 are used for I2c) 13 more digital lines, and a bunch of horsepower (that pretty much goes un-used) But it's cool - and I really wanted the two way com between the aircraft and the ground. Now I have it. Cheers.
E-mail me when people leave their comments –

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

Join diydrones

Comments

  • II haven't done it yet ,but it's on my list. Time Division Multiplexing. You would need to build a simple 1 ch multiplexer. Control it with a spare digital pin. The time would be shared between the gps and the Tx of the x-bee. Then you need to sync the print_data wit the gps. I tried this sync part. I think this could work. I timed the data transmissions with a scope. I saw ~54 ms for the gps, plus the print time( i need to measure this) it's probably no more than 200 ms total. That leave 800ms to send data from the gcs. I don't know if this would work with the u-blox, but I think it would with the 406.
  • I like this system. We implimented two way also, and we didnt go with a second Arduino because of cost (we are trying to build a swarm), but this opens up ports and you get to leave your I2C line open
  • Till the new ArduPilot is out you might consider an Arduino Mega. Or the cheaper, smaller Seeeduino Mega. It'll give you everything you have now except the extra computing power, and you dont need the added complexity of having the two arduinos talk to eachother. I'm ended up going with a Mega over the current ArduPilot specifically because I wanted that extra serial port for two way communications.
  • 3D Robotics
    Great work! Needless to say, this functionality will be built into ArduPilot Mega, which has the advantage of four serial ports. It is, as you say, very handy!
  • Admin
    Excellent work Peter.

    Regards,
    TCIII
This reply was deleted.