SBUS decoder, display, and wireless buddy box project

Any old or new electronic projects on the go
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

SBUS decoder, display, and wireless buddy box project

Post by Martin »



Long-winded explanation below. Probably better to watch the (long-winded) YouTube video. :)

SBUS (or S-BUS) is a serial protocol invented by Futaba, but now supported by many R/C manufacturers. It transmits 16 normal channels, plus 2 'digital' channels (single bit, so like an on/off switch) and two bits of data for 'frame lost' and 'failsafe'.

The serial protocol is 100 kbaud, 8 data bits, even parity bit, 2 stop bits. The signal is the opposite polarity to the normal serial signals used by Arduinos and similar. A single frame of data occupies 25 bytes, and takes exactly 3 milliseconds to transmit. With most R/C systems, there are gaps between the frames, and a typical frame rate might be every 11 milliseconds, or whatever.

I wanted to decode SBUS to use a tiny Futaba compatible receiver as part of a wireless buddy box system.

I spent a long time writing a decoder that uses pinchange interrupts to detect the incoming SBUS signal. It worked but suffered from occasional parity or framing errors because the edges need to be timed accurate to 5 microseconds, and with standard Arduino code on a standard 16MHz Arduino, that can't be obtained completely reliably. The chip itself is capable, but the Arduino overhead running the millis() timer and so on means that sometimes a few microseconds of jitter cause problems. I got the program working 100% reliably using Atmel Studio instead of the Arduino IDE, but most people won't want to do that...

So I fell back on using the Arduino's serial "hardware" to receive the signal - that works perfectly, but does mean that the SBUS signal has to be inverted (using a single transistor and two resistors) to be compatible with the Arduino Rx (D0) input.

More details, circuit, sketch etc. to follow... watch this space!
Attachments
sbusDecode6.zip
Update 2023-Jan-05. Someone wanted more than 8 PPM channels. This defaults to 12, but you can edit the NUM_PPM_CHANNELS value in config.h to any value up to 18
(17.95 KiB) Downloaded 213 times
sbusDecode5.zip
Update 2022-Apr-29. Very minor bug fixes and comment improvements.
(17.59 KiB) Downloaded 289 times
sbusDecode4.zip
Update Feb 5 2021. Fixed(?) bug on channel 9. This is a later version that allows scaling from SBUS values to PPM to be more easily changed, and can also display PPM or percentages on the display. See posts on pages 2, 3, and 4 for more details.
(17.63 KiB) Downloaded 515 times
sbusDecode3.zip
Extended allowed frame time to 4ms to suit X-Boss receiver. Fixed some comment typos.
(16.9 KiB) Downloaded 455 times
Last edited by Martin on 05 Jan 2023, 21:01, edited 9 times in total.
User avatar
Phil_G
Posts: 597
Joined: 15 Feb 2018, 23:32
Contact:

Re: SBUS decoder, display, and wireless buddy box project

Post by Phil_G »

Fascinating Martin, I can see that being really useful especially as more stuff adopts sbus as a standard...

Is there anything on the ch340g you could use to invert the serial line Martin? just a thought... my 340G datasheet is a bit vague... says rs232 enable is latched which is a pity as it inverts txd

Edit: Just tried holding rs232 high, it doesnt seem to affect the txd level at all ! maybe this isnt a G

Further edit: none of the Nanos I have to hand have a G version 340

Must admit I'd never looked at the 328p baudrate generator Martin, I'd assumed it was just the fixed standard rates but I just read the usart section of the datasheet and I see now :D I didnt realise it was so programmable and could readily do odd baudrates like 100kb!

Cheers
Phil
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: SBUS decoder, display, and wireless buddy box project

Post by Martin »

Phil, the standard Arduino Serial.begin() function handles the setting of the serial parameters. You just put:

Serial.begin(100000, SERIAL_8E2);

...instead of the usual Serial.begin(9600); or whatever.

Makes it a bit trickier to use Serial for debug as the built-in Arduino IDE serial monitor doesn't like non-standard baud rates. You can use PuTTY or some other serial terminal emulator - they will work at any baud, but that means swapping back and forth between the Arduino IDE and PuTTY because they both want to use the same (Arduino) serial port.

That's why I switched to using a USBASP programmer and added the OLED display - debugging via serial was a pain. But for someone who just wants to upload the sketch, the normal Arduino USB upload works fine - you just have to remember to disconnect the serial input from the SBUS while you do it.

The Arduino system doesn't actually report parity errors (though the Atmel chip can detect them), but it doesn't really matter as what is your program going to do anyway if it sees a parity error? :lol:
User avatar
tiptipflyer
Posts: 393
Joined: 16 Feb 2018, 22:49
Location: Germany

Re: SBUS decoder, display, and wireless buddy box project

Post by tiptipflyer »

That´s way above my hat, but it sounds fascinating to me. I will closely watch this space, maybe I can learn something new ( I know I am an old dog ). You never know.
Thanks for sharing Martin, all very interesting stuff.

Cheers
Frank
Tobe
Posts: 665
Joined: 16 Feb 2018, 06:19
Location: Varberg or Stockholm, Sweden

Re: SBUS decoder, display, and wireless buddy box project

Post by Tobe »

....in this forum also old grumpy dogs learns new tricks! I love it as it keeps challenging my brain and capacity
Cheers,

Tobe
User avatar
F2B
Posts: 200
Joined: 16 Feb 2018, 11:23
Location: 20 m NE of Amsterdam

Re: SBUS decoder, display, and wireless buddy box project

Post by F2B »

Another thumbs up! :D

I'm with Phil, Frank & Tobe here.
Fascinating stuff and well worth trying to understand, even little bits at a time...
F2B or not to be....
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: SBUS decoder, display, and wireless buddy box project

Post by Martin »

Phil_G wrote: 22 Jun 2020, 15:57 Is there anything on the ch340g you could use to invert the serial line Martin? just a thought... set the rs232 enable?
Possibly, if you're using a Nano, but my finished project uses a Pro Mini to keep it smaller.

I was hoping to use the even smaller 'beetle' board - the Mega32U4 board about the size of a Digispark - but unlike the ATtiny85 Digispark, the beetle doesn't have a 5V regulator: It does have a regulator on board, but it (uselessly) regulates 5V down to 3.3V - and it doesn't have a 'Raw' or 'Vin' pin.

I don't think the ATtiny85 has enough power (or sufficient clock accuracy) for this project.

The photo compares the sizes of a Nano, Pro Mini, Beetle (from which the 'tongue' can be sawn off) and the receiver. You can see why I wanted to keep the Arduino small! That receiver, by the way, can bind to Futaba or FrSky, and for FrSky it can bind to either EU or non-EU protocol transmitters (something that "real" FrSky receivers can't do - with those, you have to re-flash the receiver firmware to swap between EU and non-EU).
SBUSreceiverSize.jpg
Last edited by Martin on 22 Jun 2020, 16:42, edited 1 time in total.
User avatar
Phil_G
Posts: 597
Joined: 15 Feb 2018, 23:32
Contact:

Re: SBUS decoder, display, and wireless buddy box project

Post by Phil_G »

On the xboss receiver, right next to the sbus signal pin, is that an inverting transistor? If so you could remove it and pick up 'true' fhss from the base pad ... dont think its a reg as it looks like two visible regs above it.

xboss_ac900.jpg


Alternatively this tiny receiver
http://www.fullspeedrc.com/frsky-nano-r ... p0042.html
puts out un-inverted SBUS

Its confusing because sbus is inverted, thats part of the spec, just how it is, so when quad flyers talk about 'inverted sbus' they usually mean true serial (ie inverted inverted sbus), as it would leave the usart tx pin, with the rest condition at a logic 1 which is a standard over 50 years old. Designed to confuse but its only like RS232, thats inverted in the voltage sense wrt the usart output, always has been, so we cant really moan at Futaba :D


To my simplistic mind, a lot of strange decisions were made with the sbus spec :D
Any of us would have proposed a standard baudrate of 115200, 'true' serial level and 12-bit channels to simplify recombining (one-and-a-half-bytes per channel)

This would have needed 24 'channel' bytes instead of 22, plus header, the "digital/framelost/failsafe" byte and the footer makes a 27 byte frame. At 12 bits per serial byte thats 324 bits per frame, at 115200bps thats more data in less time than sbus (2.8ms vs 3ms). Adding another byte for 8 more switched channels is still under 3ms, and even adding 16 switched channels (348 bits per frame) would only stretch it to 3.02ms.

If they'd stuck to standards, they could have had 16 higher resolution channels and 10 switched channels instead of only two at under 3ms or or 18 at very slightly over 3ms, in an easier-to-interface format.
... and why bother with parity? ditching the parity bit would leave enough time within the 3ms for a 16-bit CRC. To me sbus is a bunch of weird decisions :D

Cheers
Phil
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: SBUS decoder, display, and wireless buddy box project

Post by Martin »

Interesting! :D My receiver has a different layout - it's the X-BOSS AC900 V2. I need to get it under my microscope and follow the track from the signal pin. The microscope can take photos so I'll post them if I find anything interesting (and possible for a mere mortal to solder to). :D
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: SBUS decoder, display, and wireless buddy box project

Post by Martin »

Thanks for that information. It's possible that my V2 receiver can switch between inverted and non-inverted. There's a section in the brief and slightly-Chinglish instructions about "RECEIVE MODE SWITCH" that I didn't understand. I'll do some tests and maybe I can remove the bulky transistor and resistors.

A few years ago, I would never have dreamed of using the adjective 'bulky' for one tiny transistor, and two 1/8 watt resistors! :lol:
Post Reply