Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device.
Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
LibrePilot provides header files to use in an arduino programming environment. Using these header files, arduinos can read telemetry data via serial connection, as well as send commands via UAVTalk.
It is not mandatory to use this library, but it gives a good example for how to use the header files.
Currently supported functions:
Request Object (void request(unsigned long objId);)
Receive Object (boolean receive(unsigned long objId, byte *ret, unsigned int timeout = 100);)
Send Object (void send(unsigned long objId, byte* data, int length);)
Todo:
Handshake
Receive multiple Objects (one at a time)
...
Connect to a flight controller
Mainport and Flexiport can be used to connect an arduino to and make use of serial communication.
Wire
Port
Arduino
Wire
Port
Arduino
Black
Ground
Ground
Red
VCC
5V
Blue
Tx
Rx
Orange
Rx
Tx
Examples
Simple Example
//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
}
Arming LED
This sketch will read the FlightStatus.Armed field from the flight controller and show the arming state on the RGB LED. Green for Disarmed, blue for Arming, red for Armed.