Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Mainport and Flexiport can be used to connect an arduino to and make use of serial communication. 

WirePortArduino
BlackGroundGround
RedVCC5V
BlueTxRx
OrangeRxTx




Examples

Simple Example

Code Block
languagecpp
themeEmacs
titleSimple Example
linenumberstrue
collapsetrue
//Library to use pins as serial port
#include <SoftwareSerial.h>

//Include a librepilot header file
#include "flightstatus.h"

//Include the LibrePilotSerial Library
#include "LibrePilotSerial.h"

//Initialize serial port
SoftwareSerial mySerial(2, 3);  // RX, TX

//Initialize LibrePilot serial connection
LibrePilotSerial lps(&mySerial);

void setup() {
  //Begin LibrePilotSerial communication
  lps.serial->begin(57600);
}

void loop() {
  
  //Request object from FC
  lps.request(FLIGHTSTATUS_OBJID);

  //Receive object from FC. This function will block until the specified object was received or it times out.
  //It returns true if a valid packet was received
  //the packet is stored in the array of the object packet union
  boolean ok = lps.receive(FLIGHTSTATUS_OBJID, FlightStatusDataUnion.arr, 200);

  //the packet data may only be accessed if the return value was true
  if(ok) {

	//the packet can be accessed in a structured manner via the data member
    if (FlightStatusDataUnion.data.Armed == FLIGHTSTATUS_ARMED_ARMED) {
      //the quad is armed, do something!
    }
  }

  delay(250);  //wait 250 ms
}

...