The code "GPS init "comes from marbalon,code "GPS PID contral "comes from EOSBandi .
What i do is just copy and paste them together.

EOSBandi use PI and PID controller classes , so Copy libraries folder to arduino libraries folder.
My little contribution to the code is show GPS_numSat on the status LED. Before armming, waitting until the GPS is hold , status LED will flash weakly to show the number of satellite,then brife pause,then flash agin.
when armming the board ,the home position is hold.
I calibrate MAG with the old way ,which works well on my 328 board.(itg 3205 bma020 hmc5883l bmp085).
In order to GPS init with serial port 0, in serial.pde, code must changed as follows:
Code: Select all
void SerialWrite(uint8_t port,uint8_t c){
switch (port) {
case 0: while (!(UCSR0A & (1 << UDRE0))) ; UDR0 = c; break; //ygl611 GPS init
//case 0: serialize8(c);UartSendData(); break; // Serial0 TX is driven via a buffer and a background intterupt
#if defined(MEGA) || #defined(PROMICRO)
case 1: while (!(UCSR1A & (1 << UDRE1))) ; UDR1 = c; break; // Serial1 Serial2 and Serial3 TX are not driven via interrupts
#endif
#if defined(MEGA)
case 2: while (!(UCSR2A & (1 << UDRE2))) ; UDR2 = c; break;
case 3: while (!(UCSR3A & (1 << UDRE3))) ; UDR3 = c; break;
#endif
}
}
I dont know why. Maybe alexinparis can tell me why.

Hope you guys enjoy the GPS code on 328 board.
EDIT:
These codes also works on MEAG board, change the code in config.h to this
Code: Select all
#define GPS_SERIAL 2 // should be 2 for flyduino v2. It's the serial port number on arduino MEGA