SBUS.h usage best practices?

dognaught47

New member
I have 2 questions regarding how best to use SBUS.h

Is it expected that PWMServo.h is required when using SBUS.h?

The following code using SBUS.h and PWMServo.h works as expected with a Teensy 4.1 receiving sbus signals from the TBS Crossfire 8ch diversity RX. If I switch to using Servo.h, I get very strange results where I essentially can't get reliable servo movement (in this example only the servo on channel 28 will work). I found a note at the bottom of this page describing known Interrupt Latency issues with some libraries. Is this a known issue with SBUS.h? Or am I doing something wrong?


Code:
#include <PWMServo.h>
#include "SBUS.h"

#define NUM_OF_CHANNEL 8

SBUS x8r(Serial2);
uint16_t channels[NUM_OF_CHANNEL];
bool failSafe;
bool lostFrame;

PWMServo servoA;
PWMServo servoB;

void setup() {
  // put your setup code here, to run once:
   x8r.begin();
   //using standard serial port for debugging
   Serial.begin(9600);
   servoA.attach( 28 );
   servoB.attach( 29 );
   
}

void loop() {
   
  if ( x8r.read(&channels[0], &failSafe, &lostFrame ) ) {
    Serial.print("got data ch3:");
    Serial.print( channels[3] );

    int pos = channels[3] / 11;
    servoA.write( pos );
    servoB.write( pos );
    Serial.println("");
  } else {
     Serial.println("no data");
  }
  

}


Is the SBUS library that you can find through the Teensyduino Library Manager the most recent one?

While working on this project, I came across the SBUS git repository and that code seems to be different than what I get through the Teensyduino Library Manager. This got me to wondering if I should be trying to use that code instead. What's the best practice here? I tried to follow the installation instructions but I wasn't successful as it seems like there are dependancies on another library (core.h) and couldn't figure out how to put all those pieces together to produce a working library.

A big thank you to brtaylor for your excellent contribution. I'm super happy to be able to use this library and benefit from reduced latency and fewer wires in my project.
 
I just wanted to quickly point out that the correct GitHub for the SBUS library is:
https://github.com/bolderflight/sbus-arduino

We have a bunch of libraries that work together to make flight software for drones, but we use don't use Arduino for the build tooling. Libraries that seem like they would be popular with the Arduino community also get a version built for Arduino. So for SBUS we have:
* Flight software version, using vagrant/virtual box, CMake, and GCC build tooling: https://github.com/bolderflight/sbus
* Arduino version: https://github.com/bolderflight/sbus-arduino

I'll actually likely be updating the Arduino version of the SBUS library this morning to make the usage match the flight software version, which I've been slowly doing with the rest of our libraries.
 
Regarding the usage, SBUS shouldn't be doing anything with interrupts on Teensy 4.1. I would probably try printing the value of pos and see if that makes sense.
 
Regarding the usage, SBUS shouldn't be doing anything with interrupts on Teensy 4.1. I would probably try printing the value of pos and see if that makes sense.

Thanks for your response. You can see in my test code I do indeed print out pos and those numbers are reporting expected values when using Servo.h. If I replace the
Code:
if ( x8r.read(&channels[0], &failSafe, &lostFrame ) ) {
line with
Code:
if (true) {
, the servos operate correctly if I feed them hard coded positions. Regardless, I have it working with PWMServo.h so I'm happy enough with that, though it is strange that Servo.h doesn't work as expected. Thanks again for your contribution.
 
Back
Top