Futaba SBUS reverse engineered to work with Arduino

I am attempting to test compile the example code and am having an issue.
Arduino IDE 1.5.2 Board is Mega
This is the line that fails
Serial<<sBus.channels[0]<<","<<sBus.channels[1]<<","<<sBus.channels[2]<<"\r\n";

With this error:
invalid operands of types "int" and 'const char[2]' to binary 'operator<<'
sbus_example.ino: In function 'void loop()':
sbus_example:19: error: invalid operands of types 'int' and 'const char [2]' to binary 'operator<<'

I am sorry to bother you, but I am at a loss. While I have done some Arduino projects, I must confess that I am having a difficult time following even the example However, If I can get it to compile, then I will continue to plug away a figure out how this works.
Thank you for your time and efforts.
Rick Harms

In regards to my previous reply, please ignore my question on the compile error. I realized that for my project I do not need that ability. For now, I replaced it with a series of print statements to verify that I can indeed read the sbus. IT WORKED. I am ecstatic. This will become the basis for an on board mixer that I am working on. Thank you.

Hi,

is there a way to make sbus signal with your library?

Any plans to extend the library to SBUS2?

I am using the following code and I am not getting any output

#include <FUTABA_SBUS.h>
#include <Streaming.h>


FUTABA_SBUS sBus;
#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 



void setup(){
  sBus.begin();
  Serial.begin(115200);
   myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
}

void loop(){
  sBus.FeedLine();

  if (sBus.toChannels == 1){
    sBus.UpdateServos();
    sBus.UpdateChannels();
    sBus.toChannels = 0;
   Serial<<sBus.channels[0]<<","<<sBus.channels[1]<<","<<sBus.channels[2]<<"\r\n";

  }
  pos = sBus.channels[2];
  myservo.write(map(pos, 1000, 2000, 1, 180)); 

}

From what i see the if condition sBus.toChannels == 1 is never reached.

I have tried 2 different Hex investors and on a Nano and Mega, the receiver I am using is the FR Sky TFR8SB and I have the Signal line from the S.Bus port connected to the input to the Hex inverter, output of that pin to RX on Arduino. The receiver is bound to the transmitter.

If I use Serial<<sBus.failsafe_status<<" Fail safe status \r\n"; I always receive a 0 from the status.

if someone can post some working code I would appreciate it, Thanks

Please see the attached schematic that I have used for this.

That all looks fine. Do you have access to an oscilloscope or logic analyzer? Are you getting anything on the serial port? Try echoing each byte received in hex. Is your receiver 3.3v logic levels?

Hi All,

I got this working now, looks like i had a poor connection on my breadboard that was causing the issues.

Thanks for the help.

One issues i am having is detecting the s.bus signal loss or failsafe, it seams to detect for one pulse and stops, should i have this within the " if (toChannels == 1){" or out side this?

Does this have to be on the RX and TX pins or could this use other pins? I see that people are using other pins to read and write PPM signals, but does S.Bus need to be on the RX and TX?

Thanks

Yes it has to be the serial port.

I have an updated version of this code now. It is written for the mega. It will handle DSMx serial (no DSM2, but the change to DSM2 is trivial), sbus, or PWM RC signals. I may or may not get around to including a PPM decoder.

The only library required is streaming, but only because I find a bunch of printlns to be a pain to read. In addition to the obvious hardware you need a push button or toggle switch to go through the calibration process.

The way this works is you first center the sticks on your transmitter. It will output the raw values during this time. Toggle the switch. It will output the center values. Toggle again and you are in the min max calibration section. Move all the switches and sticks through their entire range. Toggle the switch a few times and it will give you info regarding the calibration.

From there it just outputs the values scaled to +/- 1000 (great for servo PWM signal). The aileron, rudder, and elevator will be centered at 1500. The rest of the channels will have their minimum value be guaranteed to be 1000. Pretty important to make sure minimum stick on throttle is actually the minimum command! If you have the range on the transmitter set the same IE 100% both directions it will also center the values at 1500. The purpose of centering A,E,R to 1500 is for my quad copter project so I don't have to use any trims. Hope this helps someone and I'll try to be better about keeping on top of this thread.

Pastbin link because it is too long to post on the forum:

@mikesbaker : Wow, what a job. Seams to be what I'm looking for.

I have an X8R RX from FrSky. Supports also S-Bus. Do you have any experiance with this RX? What I now is that an inverter is not needed, because FrSky works already inverted.

Well, I used your Code from GitHub. At least, the X8R is still alive.

What I have done: I have a Teensy 3.1-Board and connected there the X8R to the RX1 pin

The Code is very dummy:

#include <FUTABA_SBUS.h>
FUTABA_SBUS sBus;

void setup(){
  sBus.begin();
  Serial.begin(115200);
}

void loop(){
  sBus.FeedLine();

  if (sBus.toChannels == 1){
    sBus.UpdateChannels();
    sBus.toChannels = 0;
   Serial.print("0: ");
   Serial.println(sBus.channels[0]);
   Serial.print("1: ");
   Serial.println(sBus.channels[1]);
   delay(500);
  }
}

The Code is loaded, but the Terminal does not show anything. So, FeedLine does not recognice any changes and the if will never happen. If I do the Serial.print in the main-loop, I have an output of 1023 all time.

There may be two errors:

  • I have connected the wrong pin as teensy board seams to be different
  • FrSky-S.Bus is to different to futaba

Do you have any ideas?

@nique

I have used the library with a FrSky X8R.

It works very well, see the test sketch below for an example I use on a Mini Pro.
The only problem with that is that I can't get any debug output, so I used a 1284 board to test as it has two hardware serial ports.

FrSky works already inverted.

Yes, and therefor you need an inverter I have tried a 74hc14 or just a transistor with two resistors
Ans I use 3.3V on the Pro Mini to avoid logic level converter

// for using mini with one serial
// change SBUS.h line 12 for normal Arduino
// #define port Serial1 --for  Arduino with more than one Serial port 
// #define port Serial --for normal Arduino with one Serial port 

#include <FUTABA_SBUS.h>
#include <Servo.h> 

FUTABA_SBUS sBus;
Servo myservo;

void setup(){
  sBus.begin();
  myservo.attach(14); 
}

void loop(){
  sBus.FeedLine();
  if (sBus.toChannels == 1){
    sBus.UpdateServos();
    sBus.UpdateChannels();
    sBus.toChannels = 0;
    myservo.writeMicroseconds(sBus.channels[6]+800);
  }
}

Thanks Erni

It is working now! For teensy, you need other Port-Assignements. Because it is teensy-specific, the teensy-solution is here: PJRC (Teensy) Forum

Hi guys,

for the life of me I cannot receive the s.bus data correctly using the arduino pro mini/nano..

using real term i get the data fine, consistent etc...

0F E0 03 5F 2B C0 C7 0A 56 80 0F 7C 00 00 00 00 00 00 00 00 00 00 00 0C 00
0F E0 03 5F 2B C0 C7 0A 56 80 0F 7C 00 00 00 00 00 00 00 00 00 00 00 0C 00
0F E0 03 5F 2B C0 C7 0A 56 80 0F 7C 00 00 00 00 00 00 00 00 00 00 00 0C 00

but using the serial library mentioned here, and others, the best i can get is

0C 00 0F E0 03 5F 0F 7C 00 00 00 00 00 0F E0 C7 0A 56 00 00
00 00 0F E0 03 5F 2B 7C 00 00 00 00 00 00 0F E0 0A 56 80 00 00
00 00 0F E0 5F 2B C0 C7 00 00 00 00
0C 00 0F E0 03 80 0F 7C 00 00
00 00 0F E0 C0 C7 0A 00 00 00 0C 00 0F E0 03 5F 0F 7C 00

its as if bytes being dropped,
//also tried 99 and 100k.
port0.begin(98000,SP_2_STOP_BIT | SP_EVEN_PARITY | SP_8_BIT_CHAR);

while(port0.available()<100) delay(10);

for(int i = 0; i < 100; i++)
{
sData = port0.read();

  • }*

  • for(int i = 0; i < 100; i++)*

  • {*
    serial.write(sData*);
    _
    }*

    any ideas please?

Erni:
@nique

I have used the library with a FrSky X8R.

It works very well, see the test sketch below for an example I use on a Mini Pro.
The only problem with that is that I can't get any debug output, so I used a 1284 board to test as it has two hardware serial ports.

FrSky works already inverted.

Yes, and therefor you need an inverter I have tried a 74hc14 or just a transistor with two resistors
Ans I use 3.3V on the Pro Mini to avoid logic level converter

// for using mini with one serial

// change SBUS.h line 12 for normal Arduino
// #define port Serial1 --for  Arduino with more than one Serial port
// #define port Serial --for normal Arduino with one Serial port

#include <FUTABA_SBUS.h>
#include <Servo.h>

FUTABA_SBUS sBus;
Servo myservo;

void setup(){
  sBus.begin();
  myservo.attach(14);
}

void loop(){
  sBus.FeedLine();
  if (sBus.toChannels == 1){
    sBus.UpdateServos();
    sBus.UpdateChannels();
    sBus.toChannels = 0;
    myservo.writeMicroseconds(sBus.channels[6]+800);
  }
}

you can use
#include <SoftwareSerial.h>
SoftwareSerial _serial(9,8,false);
_serial.begin(9600);

and connect pin 8 on arduino to the rx on ftdi usb...

but i cant receive sbus data.. its inverted and everything... arghh..

I've been trying to make this work and freely admit I am lost. installed the library, found the SerialPort library and installed it, now I get....

sketch_nov01a:15: error: 'class FUTABA_SBUS' has no member named 'begin'

I see the public declaration in Futaba_sbus.h, but don't see any function by that name. Should there be a cpp file that goes along with this. Not a C++ programmer so I am sure the problem is the vacant spots in my brain.

Any clarification would be greatly appreciated.

If you use the SBUS library here, you don't need any SerialPort library

https://github.com/mikeshub/FUTABA_SBUS/tree/master/FUTABA_SBUS

Should there be a cpp file that goes along with this.

Yes there is a .h file and a .cpp file like other librarys.

If your goal is to control servos via SBUS, you could uses this sketch (16.oct by mstrens)

OpenRcForum

It dosn't use any librarys and are able to control 16 servos with an Arduino

I will try the suggested library. Thanks

At present, my goal is to control several options via switches on the Taranus Tx. I can tipically derive about 4 states from each channel so being able to control many options using sbus would be great. I was using a 4 channel rx which was limited, but I also have an sbus X4R and would like to try doing everything through sbus.

More brain exercise than needs requirement.

I seem to be going backwards. I downloaded and installed the library as above, and now I get the following. It is said above that I would not need the SerialPort library, but FUTABA_SBUS.h does call that library.

In file included from sbus_example.ino:1:
C:\Users\misadmin\Documents\Arduino\libraries\FUTABA_SBUS/FUTABA_SBUS.h:41: error: ISO C++ forbids declaration of 'SerialPort' with no type
C:\Users\misadmin\Documents\Arduino\libraries\FUTABA_SBUS/FUTABA_SBUS.h:41: error: expected ';' before '<' token
sbus_example.ino: In function 'void setup()':
sbus_example:9: error: 'class FUTABA_SBUS' has no member named 'begin'
sbus_example.ino: In function 'void loop()':
sbus_example:19: error: invalid operands of types 'int' and 'const char [2]' to binary 'operator<<'