Easy to use FrSky-library for Arduino

20111221073704890.jpgFor my Control Station project, I also started writing a bunch of decoding function for the FrSky telemetry protocol.

I have now moved those functions into their own library for Arduino. My focus while writing and expanding this library is on ease of use. There is already Arduino code available but I found that a bit complicated to integrate. With the new library, all the user needs to do, is read one char from the serial port and send it to the library via the ::update method. All the decoding is done internally. The ::update method returns 1 when a complete packet was received, otherwise it returns 0. There is (will be) a dedicated method to access every parameter. I'll also try to keep up the detailled documentation.

At the moment, the library decodes only the basic information, RX A1 & A2 ports, uplink and downlink RSSI. Additional sensors will be included as I receive the hardware (which hopefully is soon).

Find the library at GitHub.

Example use (on MEGA 2560):

#include <frsky.h>
FrSky frsky;
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
}
void loop() {
if (Serial2.available()) {
char c = Serial2.read();
if (frsky.update(c)) {
Serial.print("TX RSSI: ");
Serial.println(frsky.getLink_up());
Serial.print("Telemetry RSSI: ");
Serial.println(frsky.getLink_dn());
Serial.print("RX Voltage: ");
Serial.println(frsky.getRX_a1()*0.0517647058824);
Serial.print("A2 Voltage: ");
Serial.println(frsky.getRX_a2()*0.0129411764706);
}
}
}
E-mail me when people leave their comments –

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

Join diydrones

Comments

  • Hi Stefan,

    Great work, I looked at your code and it seems that you don't handle the bit stuffing.
    Meaning that all frame with bit stuffing are discarded because of the extra length of byte due to the bit stuffing method.

    you should update your code like that :

    char FrSky::parse_char(char c,char* msg) {
      static char bufferIndex;
      static bool msgBegin;
      static bool BitStuff;
      char result = 0;


      if (c == 0x7E) {
        if (bufferIndex == FRSKY_MSG_LENGTH) {
          bufferIndex = 0;
          result=1;
          msgBegin=false;
        }
        else if ( (bufferIndex > 0) && (bufferIndex < FRSKY_MSG_LENGTH) ) {
          bufferIndex = 0;
          msgBegin=false;
        }
        else {
          msgBegin = true;
          BitStuff = false;
        }
      }
      if(c == 0x7D) {
        Bitstuff = true;
      }
      if ( (msgBegin) && (c != 0x7E) && (c != 0x7D) ) {
        if(BitStuff == true) {
          c ^= 0x20;
          BitStuff = false;
        }
        msg[bufferIndex] = c;
        bufferIndex++;
      }


      return result;
    }

    In this way, when 0x7D is received, this byte is not added in msg[], the length is not increased and the next byte is XOR with 0x20.

    Regards,

    Olivier.

  • Can you help me a little?

    I connect arduino nano V3 to FrSky DJT through RS232 TTL level converted. I modified your sketch (attach oled display). I see telemetry on it but only first 6 packets. After it function frsky.update(c) return false.

    In oscilloscope i see - impulse still recieving.
    What the problem?

  • Hi Stefan,

    I connected an arduino mega 2560 I have a FRSKY DFT module in my transmitter and a FRSKY D8R v2 receiver. I am trying to connect the DFT to the mega 2560. in between i have a max3232 TTL from sparkfun:

    https://www.sparkfun.com/products/11189

    The program compiles perfectly and uploads. When I put the serial monitor on i get a nice page displaying the tekst wit all 0.00 values. What am I doing wrong?

    Regards,

    Jarco den Dekker

    SparkFun Transceiver Breakout - MAX3232
    The 'must have' IC for TTL/CMOS projects finally has its own breakout board! This RS232 IC is capable of running at 3V and communicating with 5V logi…
  • Thank's now are working!!

  • I use the pin0 and pin1...

    I'm nob with C and arduino...

    Thank's

  • If I disconnect my Uno from USB my serial will be free to use it? Then this must work?


    #include <FrSky.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_PCD8544.h>

    FrSky frsky;
    Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);


    void setup() {

    Serial.begin(9600);
    display.begin();
    display.setContrast(30);
    //display.clearDisplay();
    }

    void loop() {
        
        display.setTextSize(1);
        display.setTextColor(BLACK);
        display.setCursor(5,3);
       

      if (Serial.available())  {
        char c = Serial.read();
        if (frsky.update(c)) {
          display.setTextSize(1);
          display.setTextColor(BLACK);
          display.setCursor(5,3);
          display.print("TX RSSI: ");
          display.println(frsky.getLink_up());
          display.print("Telemetry RSSI: ");
          display.println(frsky.getLink_dn());
          display.print("RX Voltage: ");
          display.println(frsky.getRX_a1()*0.0517647058824);
          display.print("A2 Voltage: ");
          display.println(frsky.getRX_a2()*0.0129411764706);
         display.display();
        }
      }
    }

    Thank's

  • Thank's I try with soft serial!! 

    The connection are: FRSKY TX pin with arduino Rx pin?

    Thank's

     

  • Well, the post says "Example use (on MEGA2560)", doesn't it? :)

    The Uno has only one serial port. If you want to read the data from the TX and write via serial, you either have to use a bigger Arduino with more than one serial port or use SoftSerial.

  • No, I have a Arduino UNO. I've have been reading about but I don't know how to do with UNO only have a Serial...

    Thank's

  • Do you have a Serial2? MEGA2560?

This reply was deleted.