Now let’s look at the necessary code to transmit telemetry data from our aircraft. We have an Arduino on board the plane, connected to the telemetry port of our FrSky receiver. I used a D4R-II. The harness that plugs into the side of the receiver (at least the one supplied with mine) has red wire for the serial data coming out of the receiver – this I connected to Pin A2 of my Arduino, and a green wire for serial data into the receiver – this I connected to Pin A1.
I made the Arduino mimic the way the standard FrSky telemetry options send their data – so there’s no need for a FrSky hub on the plane – all the sensors for GPS, magnetometer, accelerometer, etc. are connected to the Arduino – the Arduino reads those sensors and then sends data to the FrSky receiver in the standard form. So if you have a transmitter such as a Taranis that understands FrSky telemetry and displays it on its screen that will work. For the extra data types that are not standard FrSky telemetry, I used the additional coding system described in part three. A Taranis doesn’t understand that data, of course, and just ignores it, – but it is still detects the standard GPS, variometer, and other data and displays that without a problem. To detect and display the additional data requires a custom Arduino decoder, as described in part three. I suppose it might be possible to create custom firmware for a Taranis to do the same, but I’ve not looked at that.
I was going to produce a cut-down version of my original code to post here, but I’m running short on time, so for those of you who wish to study it and extract the relevant parts to use in your own projects, I’m going to post my original ‘Piagma’ sketch. You can download the sketch using this link.
Piagma is a model plane autopilot I wrote that uses a Raspberry Pi for the higher-level functions of waypoint selection, steering, etc. An Arduino is used as an interface to read all the sensors, and as an interface for the Raspberry Pi. But you don’t need the Raspberry Pi for it to be useful – even without the Raspberry Pi, the Arduino reads all the sensors and sends the data back to the base station through the FrSky telemetry system. If a Raspberry Pi is present, the Arduino works as an SPI slave and the Raspberry Pi is the SPI master.
The sensors I used were a MPU6050 gyro/accelerometer, a BMP085 barometer/altimeter, a HMC5883L magnetometer, and a ‘standard’ serial data at 9600 baud GPS unit. The Arduino also decodes the CCPM data available from the FrSky receiver and drives the decoded data out to the individual servos and motor controls. One channel of CCPM data is used as an Auto/Manual switch – in the manual position the received channels from the base station are sent direct to the servos – in the auto position, the Raspberry Pi controls the servos. This means that when testing, if the autopilot goes crazy, or the Raspberry Pi crashes or stops communicating with the Arduino, then by flicking a switch on your transmitter you can take manual control.
When I get a bit more free time, I may produce a cut-down version of the Piagma Arduino sketch removing the Raspberry Pi parts to make it clearer. but maybe this post will help those of you who are keen to make progress.
I also wrote my own telemetry receiver / display / data logger for attaching to the ground station – that allows you to monitor all the telemetry data with an ordinary ‘dumb’ transmitter rather than a Taranis – that’s also Arduino based with a colour LCD screen and an SD card for data logging. If I ever get around to it, I guess I can cover that in part six or seven or whatever!