SBUS decoder, display, and wireless buddy box project

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

SBUS decoder, display, and wireless buddy box project

Post by Martin » 22 Jun 2020, 13:13



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
sbusDecode3.zip
Extended allowed frame time to 4ms to suit X-Boss receiver. Fixed some comment typos.
(16.9 KiB) Downloaded 5 times
Last edited by Martin on 23 Jun 2020, 06:56, edited 4 times in total.

User avatar
Phil_G
Posts: 413
Joined: 15 Feb 2018, 23:32
Contact:

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

Post by Phil_G » 22 Jun 2020, 13:30

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 have 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: 392
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

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

Post by Martin » 22 Jun 2020, 13:41

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: 258
Joined: 16 Feb 2018, 22:49
Location: Germany

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

Post by tiptipflyer » 22 Jun 2020, 14:24

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: 239
Joined: 16 Feb 2018, 06:19
Location: Varberg or Stockholm, Sweden

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

Post by Tobe » 22 Jun 2020, 15:17

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

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

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

Post by F2B » 22 Jun 2020, 15:53

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: 392
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

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

Post by Martin » 22 Jun 2020, 16:23

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: 413
Joined: 15 Feb 2018, 23:32
Contact:

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

Post by Phil_G » 22 Jun 2020, 16:41

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

Martin
Posts: 392
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

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

Post by Martin » 22 Jun 2020, 16:51

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: 392
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

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

Post by Martin » 22 Jun 2020, 17:15

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