This paper describes the development and hardware-in-the-loop testing of an Extended Kalman Filter (EKF) for attitude estimation. After literature review, a multimode solution to the estimation problem is introduced. It uses the sensor measurements optimally relying on the magnetic and acceleration data on the ground, and magnetic and GPS data in the air. An emergency aerial mode dealing with lost GPS data is also developed. The quaternion dynamic equations are chosen to represent system dynamics. Their special structure makes it possible to perform continuous-discrete transformation with a closed form solution of the Heun scheme. This can improve the prediction performance of the EKF. The observability of the system was examined using gridding of the state space in every modes of the filter. The computing steps of the new filter are summarized before presenting issues of implementation and testing. This article presents hardware-in-the-loop test results with simulated GPS losses. Comparison to another filter is also presented. The estimator was tested in real flights and performed as expected.