Arduino - Extend the number of servos supported by a Rx

Electronic projects that are either related to the firmwares for the 9x, or simply great for radio control applications.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

I was looking for a device in order to extend the number of servos controlled by a D4R-II or a X4R receiver (and optionnaly a X6R or X8R receiver)
It requires a CPPM and a SBUS decoder.
The SBUS signal is available on all X serie Frsky receivers and contains informations on 16 servos even if the receiver does not have connectors for 16 servos..
CPPM signal is available on e.g. Frsky D4R_II receiver and can be used to control up to 8 servos instead of 4.

There are already several hardware/software that can be used to control servos based on a SBUS and/or a CPPM signal.
Among the available products I found the following:
- Frsky SBUS to PWM decoder : http://www.frsky-rc.com/product/pro.php?pro_id=74
Cheap, small but :
- It controls only 4 servos (so 2 devices are required if you want to control 8 servos)
- Some servos can't be used because PWM signals are generated every 9 ms instead of about 20 ms
- It does not decode CPPM signal so it can't be used to expand a D4R-II receiver
- this device : http://www.fpvmodel.com/rmilec-high-pre ... _g478.html
Cheap, convert in all directions, can control up to 16 servos but size is quite big.

As alternative, I would like to share a small program I wrote to be used on an Arduino pro mini running at 16 mhz.
I limited the number of controlled servos to 8 in order to keep the device small.
This software detects automatically the type of signal (SBUS or CPPM) so the same device can be used with both types of receiver without reloading another firmware.
In case of CPPM, it generates the channels 1 up to 8.
In case of SBUS, it generates or the channels 1 up to 8 or the channels 9 up to 15 depending on a jumper (setting Arduino pin Tx to ground or not). So it can be used to expend a X6R or a X8R receiver.

In the tests I made, I did not notice any jitter on the servos.
In order to achieve this result, only 1 interrupt is used. Even the internal Arduino interrupts are disabled.

I also designed a PCB having the same size as Arduino pro mini that supports 8 servo connectors, a connector for the battery and a cable to the RX (to be connected on SBUS or CPPM).
This PCB has to be put on top of the Arduino keeping the device quite small (2 X 3.5 cm).
If there are demands, I can let produce a few batches of this PCB.

The cost of this device is very low (about 5 euro) because it requires only:
- an Arduino pro mini
- a servo cable
- some 3 row pin headers
- 10 resistors + 1 transistor
- a PCB.

Here in attachement the program (open source) to be used on the Arduino.

All comments are welcome.
Attachments
CPPM_SBUS.rar
(9.31 KiB) Downloaded 977 times

User avatar
ddano007
Posts: 41
Joined: Thu Nov 13, 2014 8:40 pm
Country: Slovakia
Contact:

Re: Arduino - Extend the number of servos supported by a Rx

Post by ddano007 »

Hi, great thanks for Your project, that`s, what I was exactly looking for my FrSky D4R-II receivers :D
Just one qeustion: if I want to use MiniPro pins 2 to 9 for output, it is only necessary to modify
prg here:
...
DDRB |= 0b00010011 ;// set PB0, PB1, PB4 as output
// DDRC |= 0b00001110 ;// set PC1 to PC3 as output
DDRD |= 0b01111100 ;// set PD2 to PD6 as output


PORTB &= 0b11101100 ;// set PB0, PB1, PB4 to 0
// PORTC &= 0b11110001 ;// set PC1 to PC3 to 0
PORTD &= 0b10000011 ;// set PD2 to PD6 to 0
...
? Or somewhere else?
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

ddano007 wrote:Hi, great thanks for Your project, that`s, what I was exactly looking for my FrSky D4R-II receivers :D
Just one qeustion: if I want to use MiniPro pins 2 to 9 for output, it is only necessary to modify
prg here:
...
DDRB |= 0b00010011 ;// set PB0, PB1, PB4 as output
// DDRC |= 0b00001110 ;// set PC1 to PC3 as output
DDRD |= 0b01111100 ;// set PD2 to PD6 as output


PORTB &= 0b11101100 ;// set PB0, PB1, PB4 to 0
// PORTC &= 0b11110001 ;// set PC1 to PC3 to 0
PORTD &= 0b10000011 ;// set PD2 to PD6 to 0
...
? Or somewhere else?
You have to modify some other lines too. If you want, I can explain it later or send you directly the right code.
Still, please note that arduino pin 8 is the only one that can be use in order to get the cppm signal coming from a D4R-II.
So pin 8 can't be used to control a servo.
If you want to control 8 servos, you have to select one more arduino pin on top of pins 2,3,4, 5, 6, 7, 9.
As said in the general explanation on top of the published code, you can select an extra pin between pin 12, A0, A1, A2 and A3.
It is even possible to select other pins like Tx.
I think only pins 8 can't be used to control a servo.
It is better to avoid pins 10, 11 and 13 if you want to make some debug. Pin 13 is already used by the led.
Rx pin is used but only for Sbus; so you could use it if you plan to connect your arduino only to a CPPM signal (e.g. D4R-II).
So, Tx pin and some other Analog pins could be used too.


I think the easier is to say me which extra pin you want to use and I can write the code.
If you prefer, I can explain the other lines that you must modify.

You can see in attachment some pictures of a PCB I made for this project.
The PCB on those pictures can be used to control 7 servos. When I made it, I had first not found a way to put all components for 8 servos and 7 servos where enough for my needs.
I have a few of those PCB and I can send some to you if you want (and some component too).
In the mean time, I also designed a new PCB that can support 8 servos but I have not ordered them to a supplier. So, I can only send the dawing (in eagle software)

Let me know how I can help you.
Attachments
IMG_1079[1].JPG
IMG_1078[1].JPG
IMG_1077[1].JPG
IMG_1076[1].JPG
User avatar
ddano007
Posts: 41
Joined: Thu Nov 13, 2014 8:40 pm
Country: Slovakia
Contact:

Re: Arduino - Extend the number of servos supported by a Rx

Post by ddano007 »

Super, Your offer is interesing for me, I`m not qualified to sent PMs, please contact me at ddano007@gmail. com. Thanks.
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

Thanks for the work and sharing your code!

I'm trying to get this working with a DJI Lightbridge, with DBUS, which is supposed to be the same or similar to SBUS. I have it connected to the Rx pin with an inverter but the LED stays off. I've tried with both an UNO (328p) and 5V mini (168p).

The DBUS is working fine with another camera gimbal that supports SBUS, do you know if there are differences and if it would cause it not to work?

Thanks

mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

NUTSgoWEEE wrote:Thanks for the work and sharing your code!

I'm trying to get this working with a DJI Lightbridge, with DBUS, which is supposed to be the same or similar to SBUS. I have it connected to the Rx pin with an inverter but the LED stays off. I've tried with both an UNO (328p) and 5V mini (168p).

The DBUS is working fine with another camera gimbal that supports SBUS, do you know if there are differences and if it would cause it not to work?

Thanks
I do not know the exact specifications of DBUS. I did not find any useful info the web.
Perhaps there are some differences e.g. in refresh rates.
The code I shared was tested with a Sbus signal generated by an X8R Frsky receiver. I think this Rx generates the SBUS frame once every 9 ms.

Perhaps you can run my code in debug mode and add comments to see where it does not work as expected with a DBUS signal.

I do not have a DJI Lightbrdge; so I can't make the test myself. Sorry for this.
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

Okay, I've got debug mode set up now, It says:
Commenced device-under-test debugging!
start of check for CPPM

Then nothing else happens

I'm looking at the signal on a scope and it appears there are frames every 14ms, that are 3ms long. I've attached a scope capture, unfortunately I don't have a logic analyzer so it's hard to tell but it looks like there is around 34 bytes per frame.

Image

Image
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

Thanks for the feed back.
Based on the messages in DEBUG mode, it seems that Arduino enters a function in order to check if the signal is CPPM or SBUS but it never exits this function.
In fact this function measures the number of pulses during an enlapsed time but if the number of pulses is 0 (or very low) then it consider that the signal is not (yet) available and it just continue to wait.

This situation could occur if you did not connect the (non inverted) signal to arduino pin 8 (the one used to detect the pulses).
Before I continue to look for other bugs, please check if you connected the signal on pin 8 and let me know.

I see 2 solutions:
- the first one is to continue to use the automatic detection CPPM/SBUS: then please connect the non inverted signal to arduino pin 8 (and the inverted signal to pin rx like you already did)
- the second one is to force the arduino to work in SBUS. In this case, it is not required anymore to connect the signal to arduino pin 8 but then you have to change the software in the following way:
In the function "setup()", replace line
checkForCPPM() ; // search for pulses in order to detect CPPM or SBUS
by this line
CPPM_SBUS_Type = 2 ; // SBUS

Please let me know if this help.
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

Okay, you were right, I did not have the non-inverting signal to pin 8. Here is what I get now:

Code: Select all

Commenced device-under-test debugging!
start of check for CPPM
End of check for CPPM; type =2
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
UART: 8
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
UART: 8
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
UART: 8
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
SBUS_Error: 0 ch1: 24240Servo1: 15760
I let it running a while and occasionally I get UART: C instead of 8

I captured one of the frames manually from the scope, here is what I got:
EDIT: Figured out I did this wrong, I wasn't including the parity bit and start/stop bits

Code: Select all

F0 60 06 20 E0 4E A5 69 7E ED 65 C6 00 64 0E 08 E0 00 62 0E 04 E0 06 80 E1 0E 02 E0 06 40 E0 8E 01 E3 06 00
[/s]
Here is the correct capture:

Code: Select all

F0 00 20 40 A5 97 ED 5C 00 40 08 01 00 20 02 00 80 10 02 00 40 08 01 30 00
According to this: http://developer.mbed.org/users/Digixx/ ... d-by-mbed/
The start and stop bytes are right, then there is 34 data bytes instead of the usual 30? I'm having trouble figuring out the information in that link. Hopefully your debug errors provide you some useful information. Thanks again for the code and helping debug!
Looks like I have the right number of bytes now so I'm not sure what's wrong
Last edited by NUTSgoWEEE on Fri Jan 16, 2015 12:02 am, edited 2 times in total.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

I am surprised that you got 34 bytes.
Normally the SBUS frame contains 25 bytes (starting with F0 and ending with 00.
When you decode the frame, did you take into account that 1 byte contains
- 1 startbit
- 8 bits
- 1 parity bit (this is unusual)
- 2 stopbits (instead of 1 usually).


The fact that there are some UART codes (8 or C) could be the result of running in debug mode.

I suggest that you stop the debug mode and that you check (with the scope or a servo) if the Arduino generates the 8 PWM signals as expected.
Does the led blink as expected now?
Please take care that Arduino select the channels being used to generate the signal based on a jumper that is present or not.
I could easily change the program to avoid this jumper if you want. Then Arduino would always generate the same channel.
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

Sorry about that, I just edited my post because I did the bytes wrong, here is the bytes I got including the start/parity/stop bits:

Code: Select all

F0 00 20 40 A5 97 ED 5C 00 40 08 01 00 20 02 00 80 10 02 00 40 08 01 30 00
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

Yes, you are right! Turning off debug mode the LED is now blinking slowly, I will check the PWM outputs when I get the scope set up again. Thank you!
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

I am still having some issues. The LED is blinking slowly (once per second), and there is a PWM signal on the output pins but the signal is always 10% duty cycle high and does not change with the radio inputs.

I reset the arduino with the Lightbridge off (no SBUS signal) and when I turn the Lightbridge on (and the SBUS starts), the LED starts blinking and the PWM signal starts but none of the channels appear to be right or change with radio inputs.

If I disconnect the SBUS signal with the arduino still running, the LED keeps blinking and the PWM outputs are still the same.

If I try in debug mode, the LED never blinks and I get the same error output as before.

I worked through the bytes I captured and it looks like the channels are correct best I can tell, but the flag byte reads 00110000b - I'm wondering if maybe the SBUS and DBUS flags are different and it is tripping up the code?

Also I have tried with both the TX pin tied to ground, floating, and tied to 5V with no different results.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

NUTSgoWEEE wrote:I am still having some issues. The LED is blinking slowly (once per second), and there is a PWM signal on the output pins but the signal is always 10% duty cycle high and does not change with the radio inputs.
If LED is blinking slowly, it seems that Arduino can recognise valid SBUS frames.
What are the exact width of the PWM signals.
Normally when the TX sent 0 on a channel, the high part of the pulse should be about 1.5 ms and the lower part should be 18.5ms (20-1.5)
When Tx sent 100% on a channel, the high part should be about 2 ms and the lower part should be 18 ms.
When Tx sent -100% on a channel, the high part should be about 1 ms and the lower part should be 19 ms.
So the width of the high part should vary between 1 and 2 ms depending on the value sent by Tx
NUTSgoWEEE wrote: I reset the arduino with the Lightbridge off (no SBUS signal) and when I turn the Lightbridge on (and the SBUS starts), the LED starts blinking and the PWM signal starts but none of the channels appear to be right or change with radio inputs.
The fact that LED and PWM starts when lightbridge is on is the expected behaviour.
NUTSgoWEEE wrote: If I disconnect the SBUS signal with the arduino still running, the LED keeps blinking and the PWM outputs are still the same.
This is the expected behaviour. Arduino keep the latest valid SBUS frame.
NUTSgoWEEE wrote: If I try in debug mode, the LED never blinks and I get the same error output as before.
I presume it means that the LED is (nearly) always ON. This means that Arduino detect SBUS frame errors. Based on my experience, I expect that those errors are the result of running in debug mode. In debug mode, Arduino sent characters to debug are has not always enough time to collect all the SBUS signal.
I could eventually change the program in order to sent only the error codes (if any).
NUTSgoWEEE wrote: I worked through the bytes I captured and it looks like the channels are correct best I can tell, but the flag byte reads 00110000b - I'm wondering if maybe the SBUS and DBUS flags are different and it is tripping up the code?
Arduino does not use the flag byte.
Arduino only controls that a frame is valid: first byte is F0 and last one is 00, there are no delay (more than 3 ms) between 2 bytes between first ansd last byte, there is a delay (at least 3 ms) between last byte and next first byte.
When a frame is valid, the data bytes are stored and converted into pulse width.

Question: Do you see any change in the bytes decoded with the scope when you move the stick on the Tx?
If the values decoded with the scope change, then the PWM should change too.
NUTSgoWEEE wrote: Also I have tried with both the TX pin tied to ground, floating, and tied to 5V with no different results.
Please take care that Arduino reads the Tx pin only at start up.
So if you change the level on the Tx pin while Arduino is running, it will not detect it.
Please take care not to tie Tx pin to ground while programming the Arduino. So the sequence should be:
- remove the jumper to program the Arduino
- after arduino is programmed, install the jumper if you want to get Channels 1...8 as output.
- restart Arduino


Take care that when the jumper is not installed, Arduino will output channel 9..16.
So if you make tests with no jumper, it is important to program some mixers on your TX in order to get changes on channels 9...16 when you move sticks/pots/switches.

I expect that your issues are coming from this.

If you want getting channel 1...8 when there is no jumper, just let me know. It is a very simple change in the program.

Still, if does not work, let me know.
If required, I coul ddevelop a special test version that should only read several frames and report them in debug mode. Then we should be sure about what is read by the Arduino.
cass3825
Posts: 6
Joined: Sun Jan 18, 2015 1:11 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by cass3825 »

mstrens,

Nicely written sketch! Very well documented and easy to follow.

I am very interested in purchasing several of your 8-ch boards and components. Let me know the cost plus shipping to the USA.

Thanks!
Billy
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

@cass3825
Thanks for your interest for this project.

I can send you some boards and part of the components.

Still note that, as said earlier in this tread, the PCB I have made currently supports max 7 servos (and not 8).
If you really want 8 servos, you would have to use another PCB design. I can send you the design for 8 servos (in eagle format) and you could let it be produced by a PCB manufactrr.
It is possible to let produce about 20 PCB for about 10$ + shipping cost in China.

Please also note, that I made a small mistake in my own PCB (the one for 7 servos). To fix this mistake, it requires to cross 2 wires (Tx and Rx) between the Arduino and the PCB. it also requires a wire between the SBUS signal and the Arduino pin 8. Thoses 3 wires are not required if you plan to convert only a CPPM signal (e.g. from a D4R-II) and are not using the SBUS signal.
If you are interested in the PCB I have, here are the cost:
- 4.5 € shipping cost (= BelgianPost) (up to 100 gr)
- 0.5 €/ PCB
- 1 € / set of 8 pin headers (X 3) + 1 transistor.
I do not have Arduino and resistors (size = 0805) , so best would be to order them directly e.g. from ebay.

Let me know if you are interested in the PCB I have (7 servos) or if you just want the design for the PCB for 8 servos.
Michel
cass3825
Posts: 6
Joined: Sun Jan 18, 2015 1:11 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by cass3825 »

Michel,

My project requires all 8 channels. Can you pm or email the Eagle .brd file

Regards,
Billy
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

cass3825 wrote:Michel,

My project requires all 8 channels. Can you pm or email the Eagle .brd file

Regards,
Billy
Here in attachment the eagle files for a 8 servos board (to be associated with an Arduino pro mini).
The resistors between Arduino pins and servos are not critical. I have seen schemas using values from 100 ohm up to 1k ohm. I expect that 470 ohm would be good.
The 2 resistors for the inverter are also not critical. Values about 2.2 k ohm should be OK.
The transistor is a 2N2222 in SMD format.

If you want that I generate the gerber files asked by most PCB manufacter, just let me know.
Attachments
SBUS_1e.rar
(23.54 KiB) Downloaded 398 times
cass3825
Posts: 6
Joined: Sun Jan 18, 2015 1:11 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by cass3825 »

Thank you Michel! Boards and components have been ordered. I will let you know how they turn out!
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

Thank you for all the information, it is helpful.
mstrens wrote:Please take care that Arduino reads the Tx pin only at start up.
So if you change the level on the Tx pin while Arduino is running, it will not detect it.
Please take care not to tie Tx pin to ground while programming the Arduino. So the sequence should be:
- remove the jumper to program the Arduino
- after arduino is programmed, install the jumper if you want to get Channels 1...8 as output.
- restart Arduino
I've followed this, and I am using a servo now on the output signals and it recognizes the signal (servo holds a position) but it does not change with input from the Tx.
mstrens wrote: If LED is blinking slowly, it seems that Arduino can recognise valid SBUS frames.
What are the exact width of the PWM signals.
Normally when the TX sent 0 on a channel, the high part of the pulse should be about 1.5 ms and the lower part should be 18.5ms (20-1.5)
When Tx sent 100% on a channel, the high part should be about 2 ms and the lower part should be 18 ms.
When Tx sent -100% on a channel, the high part should be about 1 ms and the lower part should be 19 ms.
So the width of the high part should vary between 1 and 2 ms depending on the value sent by Tx
I've tried all outputs. The outputs are all level high for 1.52ms and low for 18.6ms (period of ~20ms) on the scope.
mstrens wrote: Question: Do you see any change in the bytes decoded with the scope when you move the stick on the Tx?
If the values decoded with the scope change, then the PWM should change too.
Yes, the DBUS signal changes some of the bytes on the scope when moving the Tx sticks - I have not manually decoded multiple frames but I'm certain it is working as I have a gimbal controller that is reading the DBUS and have disconnected it from the gimbal and to the arduino (with inverter) without powering down.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

@NUTSgoWEEE
Sorry if it does noet work as expected.

I also just see that I made a mistake in the explanations I provided in a previous thread:
I said : Take care that when the jumper is not installed, Arduino will output channel 9..16.
It should be : Take care that when the jumper is not installed, Arduino will output channel 1..8.

On my side I tested once more the software and it works good with a X8R Frsky receiver.

I am currently preparing another version of the software that should allow for debugging.
This special debug version will print out groups of 10 frames of 25 bytes being read. It will print the raw data and the converted 16 channels (in usec).
I will send you this debug version when I tested it.
Thanks for your collaboration.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

@NUTSgoWEEE
please find here a new version that should help debugging.
In this version, when DEBUG and DEBUGSBUS are both #defined (it is by default the case in the attached version), Arduino should send to the PC (using the termina) several groups of 10 lines of data.
Each line of data should contains:
- 25 bytes read from the SBUS; bytes are displayed in Hexadecimal; first byte on the line should normally be F (or 0F), last byte should be 0 (or 00)
- " - " as separator
- 16 decimal values, each value represents the number of clock cycles needed for each channel (from channel 1 up to 16); So dividing the values by 16 should give you the number of usec of each pulse.

It is "normal" that you got an UART error bewteen 2 groups of 10 lines of data. It is because, after fast buffering 250 bytes read from SBUS, Arduino has to make some conversion and has to send the data to the PC .
During this job, Arduino can't read fast enough the UART and so it lost some bytes. This should only occurs in debug mode.
In order to resynchronise Arduino with SBUS, this version of Arduino wait for a delay of at least 3 msec without any SBUS trafic before filling his 250 bytes buffer again.

Please note the the purpose of this debug version is only to check the data received on the SBUS.
This version (when running in debugsbus mode) does not generate the PWM pulses and so can't control the servos.
It should allow you to check if you get group of 25 bytes, if first byte is 0F, last byte is 00 and if the data read on the SBUS really change when you move the sticks/switches on TX side.

Let me know if you get the expected results
Attachments
CPPM_SBUS.rar
(10.2 KiB) Downloaded 393 times
NUTSgoWEEE
Posts: 13
Joined: Tue Sep 10, 2013 1:20 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by NUTSgoWEEE »

mstrens - I wanted to update you because you've helped me troubleshoot so much. I ended up writing some code on an Arduino Mega to decode the DBUS (and troubleshoot using multiple serial ports) so I can now use it on a mini or custom board. It's not quite as elegant as yours because it uses all arduino functions, but I don't require controlling servos so it will work for me. Again, thank you for helping me troubleshoot, I learned a lot from your code about sbus and was able to write one myself :)
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

@NUTSgoWEEE
Thanks for your feedback.
If you think that there is something wrong with my code, could you try to explain where I made a mistake.So, I can correct the code and it would help other users.
Based on remarks from another user, I just found a bug about the jumper to select between channels 1-8 and channels 9-16 in SBUS mode. I will fix it soon.
nigelsheffield
Posts: 308
Joined: Fri Nov 08, 2013 9:56 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by nigelsheffield »

Nice work, I might have to. Make one or 2 of these!
A couple of simple questions
Probably too early to tell but would this be reliable and precise enough to use for controlling the aircraft? Or is it best to stick to things like gimbals for now at least?
How much to post a board or 2 to the UK and would you have any of the components to supply?
Thanks
Nigel.
akkuschrauber
Posts: 57
Joined: Wed Sep 12, 2012 5:06 pm
Country: -
Location: Dortmund
Contact:

Re: Arduino - Extend the number of servos supported by a Rx

Post by akkuschrauber »

As I told, for me the code works, but without the reading if a jumper on TX is set, so only drawback is to switch from ch1-8 to ch9-16 without reflashing ...
But as you said, I'll wait to get the next code to test ...
Thank you for your work and time :D
Ironie: read [Wikipedia.de] http://de.wikipedia.org/wiki/Sarkasmus
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

nigelsheffield wrote:Nice work, I might have to. Make one or 2 of these!

How much to post a board or 2 to the UK and would you have any of the components to supply?

Nigel.
I can propose you 2 options:
1) I send you some PCB that can be use to control 7 servos and part of the components (the transistor to invert the SBUS signal and optionally 3 row pin headers at 90°). I do not have enough resistors but any values between 100 and 1000 ohm should work (in 0805 size). See photo above in this thread.
2) I send you, free of charge, just a PCB drawing(in eagle) that supports 8 servos and you order the PCB to manufacter. Cost is about 10 € for about 20 PCB in China.

Important note: the PCB I can send (option 1) supports only 7 channels. It is in fact a first version with some drawback (see copy of a mail to another user).
The PCB has also not been foreseen to support a jumper (in order to select between channel 1-8 and channel 9-16 for SBUS without having to reprogram the arduino)
This old PCB requires some minor changes to the software. I can easily deliver the code that works with this first version of PCB.

Those are minor drawbacks that does not exist with the new PCB version.
I have no PCB to deliver for the new version, I can only give the design (and schematic).

If you are interested in the PCB I have, here are the cost:
- 4.5 € shipping cost (= BelgianPost) (up to 100 gr)
- 0.5 €/ PCB
- 1 € / set of 8 pin headers (X 3) + 1 transistor.
I do not have Arduino and resistors (size = 0805) , so best would be to order them directly e.g. from ebay.

L

Here copy of a mail I sent to another user that explain a little more:
1) Initially the PCB was designed only to decode SBUS signal from a X serie receiver.
It was not foreseen for a CPPM signal from a D serie receiver. So the PCB has no direct connection to Arduino pin 8 (which is the only one that can be used by the software in order to decode CPPM signal).
In fact if you use only the device with a D4R-II, this is not an issue because you can route you servo cable in order to solder the CPPM signal directly to Arduino pin 8 while ground and positive are soldered to the foreseen pins on PCB.
If you plan to use the device with an X serie Rx too, then you would have to add a wire between PCB Sbus signal and Arduino pin 8.

2) there is small mistake in the PCB when used with Sbus.
In order to decode SBUS, the PCB has 3 pins for a servo cable. The Sbus signal is connected to an inverter (made on PCB with 2 resistors and 1 transistor) before going to Arduino. The inverted signal has to be connected to arduino pin" Rx" in order to let Arduino decode the Sbus signal.
I had planned to use the Arduino pin Tx to control the servo nr 7.
Still I made an error in the PCB and I inverted the positions of the Rx and Tx connections compare to the Arduino pins.
If you use the device only with a D serie receiver, this is not an issue at all because the inverter is not needed and it is easy to let the software control servo nr 7 on the Arduino pin Rx (instead of Tx). This is what I did for my device.
If you want to use the device for both type of receivers then you have to mount the inverter on the PCB and you have to invert the Tx/Rx wires between PCB and Arduino. In this case the software has to control servo 7 on pin Tx.
nigelsheffield
Posts: 308
Joined: Fri Nov 08, 2013 9:56 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by nigelsheffield »

Thanks I will have a think , need to decide if 7 ch will be enough, probably will be....
I did not realize it was so cheap to have boards made!
so for 10 euro 20 boards can be made? wow , what about postage on that?
Will you be getting the 8 ch board made sometime? I am in no rush.
Thanks again. Great work.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by mstrens »

I ordered my PCB at "Smart prototyping".
Shipping cost for 10 board 5 X 5 cm (it is possible to set 2 devices per board) is 4.42 $ (and the PCB are 9.9 $).
The quality was good.

I do not plan currently to order the PCB for 8 servos (because the first one with 7 is ok for me).
Still I recently sent the newer PCB design to someone on this forum that has ordered PCB.

Perhaps you can get ask him some of his PCB if you prefer.
nigelsheffield
Posts: 308
Joined: Fri Nov 08, 2013 9:56 pm
Country: -

Re: Arduino - Extend the number of servos supported by a Rx

Post by nigelsheffield »

Thanks,
I will decide how many I may need and then go from there , its just for my own use so I won't really need 20 boards! :shock:
My surface mount soldering skills are poor but I could probably manage, any plans to make a board available already populated with transistor and resistors?
I think there is a potential market for this type of board , especially one with the arduino part built on and ready programmed , like you said at start there is the rmilec 16ch s.bus decoder or the 4ch frsky offering but a nice small 8ch s.bus decoder is what is often needed.

Post Reply

Return to “General RC Electronic Projects and Discussion”