Go Down

Topic: Futaba SBUS reverse engineered to work with Arduino (Read 99694 times) previous topic - next topic

nique

@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:
Code: [Select]

#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?

Erni

#31
Jun 25, 2014, 11:24 am Last Edit: Jun 25, 2014, 11:50 am by Erni Reason: 1
@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.

Quote
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
Code: [Select]

// 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);
 }
}


nique

Thanks Erni

It is working now! For teensy, you need other Port-Assignements. Because it is teensy-specific, the teensy-solution is here: http://forum.pjrc.com/threads/25265-Arduino-RC-library?p=48935&viewfull=1#post48935

AvengerIl

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?

AvengerIl


@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.

Quote
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
Code: [Select]

// 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..

crchisholm

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.
Charlie R Chisholm

Erni

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

Code: [Select]
https://github.com/mikeshub/FUTABA_SBUS/tree/master/FUTABA_SBUS

Quote
Should there be a cpp file that goes along with this.
Yes there is a .h file and a .cpp file like other librarys.


Erni

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



crchisholm

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.
Charlie R Chisholm

crchisholm

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.

Quote
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<<'
Charlie R Chisholm

Erni

A quote from the author in post #9 in this thread:
Quote
The library has been updated to no longer rely on the SerialPort.h library
If you are using an Arduino UNO you have to change line 12 in FUTABA_SBUS.h
from:
Code: [Select]
#define port Serial1
to
Code: [Select]
#define port Serial

crchisholm

this really does make me think I am ending up with different versions of the files than you all are.  If you look at the copy of futaba_sbus.h that I downloaded from github, it certainly does not match the statement above about not needing SerialPort any more or the changes to "line 12 in FUTABA_SBUS.h"  

Code: [Select]
//#include <SerialPort.h> must be in the main program
//port number is changed below
#ifndef FUTABA_SBUS_h
#define FUTABA_SBUS_h

#include <Arduino.h>
#include <SerialPort.h>


#define SBUS_SIGNAL_OK          0x00
#define SBUS_SIGNAL_LOST        0x01
#define SBUS_SIGNAL_FAILSAFE    0x03
#define BAUDRATE 99000
#define RXBUFFER 64
#define TXBUFFER 64
#define PORTNUMBER 1



class FUTABA_SBUS
{
 public:
 uint8_t sbusData[25];
 int16_t channels[18];
 int16_t servos[18];
 uint8_t  failsafe_status;
 int sbus_passthrough;
 int toChannels;
 void Begin(void);
 int16_t Channel(uint8_t ch);
 uint8_t DigiChannel(uint8_t ch);
 void Servo(uint8_t ch, int16_t position);
 void DigiServo(uint8_t ch, uint8_t position);
 uint8_t Failsafe(void);
 void PassthroughSet(int mode);
 int PassthroughRet(void);
 void UpdateServos(void);
 void UpdateChannels(void);
 void FeedLine(void);
 private:
 SerialPort<PORTNUMBER,RXBUFFER,TXBUFFER> port0;
 uint8_t byte_in_sbus;
 uint8_t bit_in_sbus;
 uint8_t ch;
 uint8_t bit_in_channel;
 uint8_t bit_in_servo;
 uint8_t inBuffer[25];
 int bufferIndex;
 uint8_t inData;
 //uint32_t baud = 99000;
 int feedState;

};

#endif
Charlie R Chisholm

Erni


crchisholm

My bad!   I thought I was getting the files from the location you gave me, but obviously not.  Now I has the files you suggested and made the change to line 12 as well.  I am down to one issue....

trying to use the example code (not included here, but will you it's needed) , I get an error on line 12 and because I don't at all understand the syntax of that line, I am not sure what I am being told.  The line is...

Code: [Select]

    Serial<<sBus.channels[0]<<","<<sBus.channels[1]<<","<<sBus.channels[2]<<"\r\n";


the error is....
 
Code: [Select]

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

Can you help me understand this syntax and the error that it is generating?

Sorry to be such a block head.  This is one of those cases where I am a bit over my head, but don't want to go back to the shallows.

Charlie
Charlie R Chisholm

Erni

The example are for a Mega which have more than one serial port.

You could use SoftwareSerial as suggested in reply #34 or use my test sketch that use a servo.

Code: [Select]

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

FUTABA_SBUS sBus;
Servo myservo;

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

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

Go Up