Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions Docs/source/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,48 @@
Examples
========

CRSF Basic Example
IBUS Basic Example
------------------

.. literalinclude:: ../../examples/espresiff/crsf_basic/crsf_basic.ino
Atmel AVR
^^^^^^^^^

.. literalinclude:: ../../examples/atmel/ibus_basic/ibus_basic.ino
:language: cpp

RP2040
^^^^^^

.. literalinclude:: ../../examples/rp2040/ibus_basic/ibus_basic.ino
:language: cpp


Crossfire Basic Example
------------------

Atmel AVR
^^^^^^^^^

.. literalinclude:: ../../examples/atmel/crsf_basic/crsf_basic.ino
:language: cpp

RP2040
^^^^^^

.. literalinclude:: ../../examples/rp2040/crsf_basic/crsf_basic.ino
:language: cpp

SBUS Basic Example
------------------

.. literalinclude:: ../../examples/espresiff/sbus_basic/sbus_basic.ino
:language: cpp
Atmel AVR
^^^^^^^^^

.. literalinclude:: ../../examples/atmel/sbus_basic/sbus_basic.ino
:language: cpp

RP2040
^^^^^^

.. literalinclude:: ../../examples/rp2040/sbus_basic/sbus_basic.ino
:language: cpp
75 changes: 74 additions & 1 deletion Docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,81 @@ Crossfire
mySerial.begin(CRSF_BAUDRATE);
SerialIO *receiver = new crsf(mySerial);

Monitoring Communication
========================
You can monitor the communication status on certain protocols, to ensure reliability of the received channel data.

SBus
----

Serial Communication
^^^^^^^^^^^^^^^^^^^^
You can monitor the serial communication using the `getSerialConnectionStatus()` method on the `receiver` instance.
This method returns `true` if the serial communication is running without errors, otherwise it returns `false`.

.. code-block:: cpp

#include <SerialIO.h>

rc_channels_t channelData;
sbus receiver(&Serial);

// within your setup routine
receiver.begin();

// within your program loop
receiver.processIncoming();
receiver.getChannel(&channelData);

bool serialConnectionStatus = receiver.getSerialConnectionStatus();

if(!serialConnectionStatus) {
// handle failsafe of channelData
}


Radio connection
^^^^^^^^^^^^^^^^
You can monitor the radio connection of the receiver using the `getFailsafe()` method on the `receiver` instance.
The failsafe indicates when the receiver has lost connection to the transmitter.
When the failsafe is activated, the channel data might be set to predefined values or hold the last known values.

You can also monitor the quality of the connection with `getFramelost()` method on the `receiver` instance.
Usually lost frame indicates when a frame is lost between the transmitter an receiver.
Failsafe activation requires that many frames ahs been lost in a row.

.. note::
Some receivers might not provide any failsafe or frame loss information via SBus protocol.
In that case, the methods will always return `false`.

.. code-block:: cpp

#include <SerialIO.h>

rc_channels_t channelData;
sbus receiver(&Serial);

// within your setup routine
receiver.begin();

// within your program loop
receiver.processIncoming();
receiver.getChannel(&channelData);

bool failsafe = receiver.getFailsafe();
bool frameLost = receiver.getFramelost();

if(failsafe) {
// handle failsafe of channelData
}

if(frameLost) {
// handle frame lost event
}


See Also
^^^^^^^^
========
- :cpp:class:`SerialIO`
- :cpp:class:`sbus`
- :cpp:class:`crsf`
Expand Down
5 changes: 5 additions & 0 deletions examples/atmel/crsf_basic/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
compile:
platforms:
- uno
- mega2560
- leonardo
22 changes: 22 additions & 0 deletions examples/atmel/crsf_basic/crsf_basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
* @file crsf_basic.ino
*/
#include <SerialIO.h>

rc_channels_t channelData;

crsf receiver(&Serial);

void setup() {
receiver.begin();
}

void loop() {
// setup crsf receiver
receiver.processIncoming();
receiver.getChannel(&channelData);

// `channelData` now contains the latest RC channel values
// You can use them by accessing the channelData e.g. channelData.channel1 to channelData.channel16
}

3 changes: 3 additions & 0 deletions examples/atmel/ibus_basic/ibus_basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ void setup() {
void loop() {
receiver.processIncoming();
receiver.getChannel(&channelData);

// `channelData` now contains the latest RC channel values
// You can use them by accessing the channelData e.g. channelData.channel1 to channelData.channel16
}

5 changes: 5 additions & 0 deletions examples/atmel/sbus_basic/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
compile:
platforms:
- uno
- mega2560
- leonardo
22 changes: 22 additions & 0 deletions examples/atmel/sbus_basic/sbus_basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
* @file sbus_basic.ino
*/
#include <SerialIO.h>

rc_channels_t channelData;

sbus receiver(&Serial);

void setup() {
receiver.begin();
}

void loop() {
// setup sbus receiver
receiver.processIncoming();
receiver.getChannel(&channelData);

// `channelData` now contains the latest RC channel values
// You can use them by accessing the channelData e.g. channelData.channel1 to channelData.channel16
}

18 changes: 18 additions & 0 deletions examples/rp2040/crsf_basic/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
platforms:
- rpipico
55 changes: 55 additions & 0 deletions examples/rp2040/crsf_basic/crsf_basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*!
* @file crsf_basic.ino
*/
/*

# Sample platformio.ini file:
# ---------------------------
[platformio]
default_envs = ws-rp2040-zero

[env:ws-rp2040-zero]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = waveshare_rp2040_pizero
framework = arduino
board_build.core = earlephilhower
monitor_speed = 115200

lib_deps =
https://github.com/Witty-Wizard/SerialIO
*/

#include <SerialIO.h>

#define CRSF_TX_PIN 0
#define CRSF_RX_PIN 1

rc_channels_t rcdata;
// On RP2040 or Arduino ESP32 you need to specify the TX and RX pins
crsf receiver(&Serial1, CRSF_RX_PIN, CRSF_TX_PIN,
true); // RP2040 requires the TX_PIN so to not hang up the mcu

void setup() {
// setup crsf receiver
receiver.begin();

Serial.begin(115200);
}

void loop() {
static unsigned long last_millis = millis();

receiver.processIncoming();
receiver.getChannel(&rcdata);

if (millis() > last_millis + 100) {
Serial.printf("RC: %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d",
rcdata.channel1, rcdata.channel2, rcdata.channel3,
rcdata.channel4, rcdata.channel5, rcdata.channel6,
rcdata.channel7, rcdata.channel8, rcdata.channel9,
rcdata.channel10, rcdata.channel11, rcdata.channel12,
rcdata.channel13, rcdata.channel14);
Serial.println();
last_millis = millis();
}
}
9 changes: 5 additions & 4 deletions examples/rp2040/ibus_basic/ibus_basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ lib_deps =

#include <SerialIO.h>

#define SBUS_TX_PIN 0
#define SBUS_RX_PIN 1
#define IBUS_TX_PIN 0
#define IBUS_RX_PIN 1

rc_channels_t rcdata;
ibus receiver(&Serial1, SBUS_RX_PIN, SBUS_TX_PIN,
// On RP2040 or Arduino ESP32 you need to specify the TX and RX pins
ibus receiver(&Serial1, IBUS_RX_PIN, IBUS_TX_PIN,
true); // RP2040 requires the TX_PIN so to not hang up the mcu

void setup() {
// setup sbus receiver
// setup ibus receiver
receiver.begin();

Serial.begin(115200);
Expand Down
18 changes: 18 additions & 0 deletions examples/rp2040/sbus_basic/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
platforms:
- rpipico
55 changes: 55 additions & 0 deletions examples/rp2040/sbus_basic/sbus_basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*!
* @file sbus_basic.ino
*/
/*

# Sample platformio.ini file:
# ---------------------------
[platformio]
default_envs = ws-rp2040-zero

[env:ws-rp2040-zero]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = waveshare_rp2040_pizero
framework = arduino
board_build.core = earlephilhower
monitor_speed = 115200

lib_deps =
https://github.com/Witty-Wizard/SerialIO
*/

#include <SerialIO.h>

#define SBUS_TX_PIN 0
#define SBUS_RX_PIN 1

rc_channels_t rcdata;
// On RP2040 or Arduino ESP32 you need to specify the TX and RX pins
sbus receiver(&Serial1, SBUS_RX_PIN, SBUS_TX_PIN,
true); // RP2040 requires the TX_PIN so to not hang up the mcu

void setup() {
// setup sbus receiver
receiver.begin();

Serial.begin(115200);
}

void loop() {
static unsigned long last_millis = millis();

receiver.processIncoming();
receiver.getChannel(&rcdata);

if (millis() > last_millis + 100) {
Serial.printf("RC: %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d",
rcdata.channel1, rcdata.channel2, rcdata.channel3,
rcdata.channel4, rcdata.channel5, rcdata.channel6,
rcdata.channel7, rcdata.channel8, rcdata.channel9,
rcdata.channel10, rcdata.channel11, rcdata.channel12,
rcdata.channel13, rcdata.channel14);
Serial.println();
last_millis = millis();
}
}
2 changes: 2 additions & 0 deletions src/SerialIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class SerialIO
bool _inverted; ///< Indicates whether the serial signal is inverted.
int _rxPin; ///< RX pin number.
int _txPin; ///< TX pin number.
uint32_t _lastPacketTime = 0; ///< Timestamp of the last received packet.
bool _connectionTimeout = false; ///< Indicates whether the connection has timed out.

/**
* @brief Perform a left shift operation on the given byte array.
Expand Down
Loading