...
Mainport and Flexiport can be used to connect an arduino to and make use of serial communication.
Wire | Port | Arduino |
---|---|---|
Black | Ground | Ground |
Red | VCC | 5V |
Blue | Tx | Rx |
Orange | Rx | Tx |
Examples
Simple Example
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
//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 } |
...