RC Switch, 4 Outputs on a Single RX Channel

Electronic projects that are either related to the firmwares for the 9x, or simply great for radio control applications.
Post Reply
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Here is another cool project I have been working on ;)
This one is based on another project by forum member HC1969 and here is the link to his project:

viewtopic.php?f=5&t=4611

http://rc-miskolc.emiter.hu/rc-miskolc/ ... Itemid=204

You can refer to his thread for some technical details on how this works. basically the PWM signal present on a receiver channel is converted to a binary system. Then each output is a "bit" that we can turn ON or OFF. But it is better explained on his thread.
He released his project as open source but he does build his switch and sell it on ebay. You can also find the link on his project pages.

As I said my little project is based on his idea, but while he uses a "Pic" microcontroller, I use an ATTiny45 or 85 and can switch 4 outputs. A cheap arduino board such as a pro mini can also be used. I have one of them switching 5 outputs. We could probably have even more, but that is for later ;)
This is very cool as we can switch multiple outputs using only one Channel on the receiver. Normally you would use 4 channels for switching 4 outputs. ;)

So, as many of you might know, I can't really write any code ;) :mrgreen:
But Google is our friend and I found some separate bits of code that I managed to put together, and with a great help from Mike I managed to put together some working code. Mike also wrote some of the code and helped me understand the calculation needed to make this work..

Mike, thank you so much for your time helping me on this and other projects. I wouldn't have managed this if it wasn't your great help. So THANK YOU again..

I used the arduino IDE to compile and upload the code to the ATTiny microprocessor.
Support for the ATTiny family can be installed on the arduino IDE but the procedure is slightly different depending on the version of the IDE you have installed on your machine. On recent versions this support can be installed from within the IDE itself. Please use Google to find out how to do it ;)

On this project the ATTiny is configured to work with arduino and at an internal clock speed of 8MHz. The code can be uploaded to the chip using an USBASP programmer for example, but before the bootloader has to be programmed using this same programmer. All can be done from the arduino IDE. Here is a picture of the connections between the ATTiny and the programmer:
ATTiny_ISP Connections.jpg
I have built this little project on a piece of stripboard. Actually, 2 pieces of stripboard as you can see in the pictures. One is soldered on top of the other and connected using some pins. On the first one we have the ATTiny85 microcontroller, 2 optocouplers that isolate the receiver from the switched voltage, and 2 MOSFET transistors that act as switches. The other board has the other 2 outputs.
each output can be powered by its own battery, or all can be powered by just one battery. This depends on what you need to control, and how you connect things. Its very flexible. You could for example have 2 outputs on one battery and the other 2 on another.. It is really up to you what you connect and how, as long as you respect the maximum ratings of the components you use. That is the optocoupler maximum ratings, and the MOSFET maximum ratings. I used some P-Channel MOSFETS that I had laying around from another cool project that is taking far longer than I thought it would :D They are the "IRF 9310" but you can also use some N-channel MOSFETs and change the circuit accordingly. I included also a diagram (or two) explaining how to connect N-channel transistors.
The MOSFETs should have a low gate/source voltage threshold. The ones I'm using start turning completely on at about 2 Volts. Here is the datasheet.
DS_IRF9310.pdf
(261.72 KiB) Downloaded 601 times
As I said I used some stripboard and SMD components (mostly 0805). The optocouplers "TLP621" and the ATTiny85 (ATTiny45 can also be used) are through hole components, but are soldered to the copper side of the board, after I trimmed their pins. The MOSFETs are some small SO-8, but can easily be soldered to the stripboard as on one side all the 4 pins are connected together and on the other side 3 of the pins are connected together and one (Gate) must be soldered separately.
Here are the schematics, single battery and multiple battery setups:
4 Channel RC Switch using ATTiny85 _schem.jpg
4 Channel RC Switch using ATTiny85_Multi Batt _schem.jpg

And here is how to connect some N-Channel MOSFETs instead ;)
Diff Batt_ N Channel Mosfet _schem.jpg
Single Batt_ N Channel Mosfet _schem.jpg

Now some pictures showing where all components are placed on both boards and where we must cut the copper strips.
This picture show the cuts on both boards
This picture show the cuts on both boards
Component placement on the copper side of both boards. Please note the little components named "SHUNT". That means that the tracks must be soldered together. Connect them with a solder bridge or a little piece of wire.
4 Channel RC Switch with ATTiny85_Copper.jpg
the next picture shows the jumper wires on the other side of both boards and the pins that must be soldered ONLY to one of them.
4 Channel RC Switch with ATTiny85_Top.jpg

Now some pictures of my boards:
Pic 2.jpg
Pic 5.jpg
Pic 8.jpg
Pic 9.jpg
Connections.jpg
And here is the arduino code. Just compile it for the ATTiny you are using ( ATTiny 85 of 45 running at 8Mhz) using the arduino IDE.
RC_Switch_4_Outputs_ATTiny.zip
(1.72 KiB) Downloaded 843 times
Here is an example of how it should be programmed on your radio, Er9x/ERsky9x in this case:
Choose a channel. Here I have CH5..

CH5 0% HALF
+ 3% HALF (Switch) RUD
+ 6% HALF (Switch) ELE
+ 12% HALF (Switch) AIL
+ 24% HALF (Switch) GEA

These are all "ADD" mixes
You can assign any switch you want to the mixes, but the weight (%) and source (HALF) must remain unchanged.

Now go to the LIMITS menu, scroll down to CH5 and change the "SubTrim" to -100


If you are using radios with other firmware than Er9x/Ersky9x or even OpenTX You might need to find a way of doing the same programming so the radio sends exactly the same pulses.



Also a little video of it working.. Enjoy it. :D ;)

João

https://www.youtube.com/watch?v=9Y41eYw-NGk

Disclaimer: Build this project at your own risk. It works for me ;) :) I cannot be held responsible if you harm your cat or dog, or even if you blow up your entire house and end up orbiting one of Saturn's moons.. :mrgreen: :mrgreen:
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Found a picture with a mistake. Picture replaced :)
Sorry about that..
João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Cpt
Posts: 9
Joined: Tue Jun 07, 2016 12:51 am
Country: -

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by Cpt »

Hi. This is very cool.
I tried you're code today. Im using opentx on a 9xr.
But i could nerver turn off all led. Not sure wnat pint should be connected, and opentx is not using that half mix option.
However. Is it possible to redo the code using the pwm values instead? Where 1500 is the center.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

OpenTX can do that as well.
If I remember, HALF in ersky9x is the same as MAX in openTX.

No it is not possible to use the receiver channel output in its normal way and switch the 4 outputs individually..

What pin(s) don't you know how to connect?

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Cpt
Posts: 9
Joined: Tue Jun 07, 2016 12:51 am
Country: -

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by Cpt »

so far i have attached the receiver signal to pin 6 and and ground to pin 4 and power to pin 5. and four led to the remaining pins. leaving pin 1 free.

i am using ch2 (just to set it up)
and the weight is set to 0

i have added 4 mixes.

in the mixes i have done as following: source is MAX switch is (THR, ELE, AIL and GEA) all using "add" (there are 3 different options: add, multiply and replace)
the i have set the weight to all different setting,(-100, -50, +50, +100) but never seem to get all led to turn off.

User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Cpt wrote:so far i have attached the receiver signal to pin 6 and and ground to pin 4 and power to pin 5. and four led to the remaining pins. leaving pin 1 free.

i am using ch2 (just to set it up)
and the weight is set to 0
You didn't say what microcontroller are you using? an Attiny? are you using an arduino board?
i have added 4 mixes.

in the mixes i have done as following: source is MAX switch is (THR, ELE, AIL and GEA) all using "add" (there are 3 different options: add, multiply and replace)
the i have set the weight to all different setting,(-100, -50, +50, +100) but never seem to get all led to turn off.
CH5 0% HALF
+ 3% MAX (Switch) RUD
+ 6% MAX (Switch) ELE
+ 12% MAX (Switch) AIL
+ 24% MAX (Switch) GEA

You have to keep to these values, other wise IT WILL NOT WORK.
The radio is sending binary information using the channel values.. And the switch decodes that..
The switch will not understand the values you are sending.

Also don't forget to do the following:
Now go to the LIMITS menu, scroll down to CH5 and change the "SubTrim" to -100
I think in openTX is called the "Servo" menu??

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Cpt
Posts: 9
Joined: Tue Jun 07, 2016 12:51 am
Country: -

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by Cpt »

i am using the attiny85. (I used a arduino uno as isp)

i attached some picture to show my values.
but i still cant seem to get all the led to turn off.

thanks for trying to help me out, at this point i am guessing that it simply wont work the same way on opentx.
Attachments
20160607_141810.jpg
20160607_141838.jpg
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Remove the first mix on CH2 just in case. The one with the aileron stick.

Did you modify the code?

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Also what receiver and how did you connect to it? Did you connect the switch to channel 2?
but i still cant seem to get all the led to turn off.
Do the others turn ON and OFF when you move the switches?

Did you progamm the correct fuses on the ATiny85? This means, did you burn the bootloader to the ATtiny from the arduino IDE?

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Cpt
Posts: 9
Joined: Tue Jun 07, 2016 12:51 am
Country: -

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by Cpt »

THANK YOU :D i finally got it working...
the problem was that i didnt burn the bootloader. i had to look around a while before i found that option.

I want to use this for my Fun Cub rc plane.

i have already found a nice code for the light, but the problem that i was having was that i couldent turn off all light, it only allowed me to turn on and off landinglight.

now i need to find out how to past this code into that other one.... gulp!!!

i might post the other code here, so that some of you can help me with it, (the code is already made ready for attiny85 pins) it just need the option to turn off all light.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Good that is working.. Yes, the bootloader only changes the fuses anyway. Not a real bootloader :)
Your problem was that the attiny was working at 1Mhz and the code is for a 8Mhz clock..

I don't understand what is your other code supposed to do?

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Cpt
Posts: 9
Joined: Tue Jun 07, 2016 12:51 am
Country: -

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by Cpt »

my other code is for beacon, flashing and other light effects. to make the lights look like the real planes..
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Ahh, ok. now I understand.. You want to integrate the effects in the switch code.. Good idea if you use it for only for that.. :)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Cpt
Posts: 9
Joined: Tue Jun 07, 2016 12:51 am
Country: -

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by Cpt »

https://github.com/hasbridge/arduino-rc ... av-led.ino

there you can see the code that i want to use.

as you can see. one setting is already made to turn off the "landinglight" but there is no option to turn off the rest of the lights.

if you have any spare time, you could try to modify it to make a second option to turn off all light, or even a option to turn off individual lights/pins.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

I don't understand what you mean.. the code to switch the lights ON or OFF is already on the switch code.. That is what the code already does. Turns pins ON and OFF ;)

I'm not a coder :mrgreen: I also do copy and paste :) And most of the times Mike ends up helping with the code, or even writing the code completely, see the first post where I thank him for helping with the project.. I am still learning too. :)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Cpt
Posts: 9
Joined: Tue Jun 07, 2016 12:51 am
Country: -

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by Cpt »

sorry for the late reply.
I think you misunderstood my previous post, your switch code is working perfect.
but i don't know where or how to paste it into the code that is in the link in my previous post.

is this mike guy also on this forum ? i might ask him to help me out too ;)
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Mike develops Er9x and Ersky9x, and many others things related to them..
Yes he is on this forum :)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
ThompsonJim
Posts: 70
Joined: Thu Aug 30, 2018 10:42 pm
Country: Australia

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by ThompsonJim »

Joao,
Thanks for alerting me to this thread of yours.
I will read it as soon as I get some time.
My first thoughts are, is it possible to use an Arduino nano board for this?
(Maybe not).

Jim.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by jhsa »

Yes it is, or an arduino Pro-mini

I just had another look at the schematic I posted for using N-Channel Mosfets, and although I might have tested them I think there might be a problem. They might not turn completely ON. The P-Channel Mosfets will work. That is what I have built for myself..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
ThompsonJim
Posts: 70
Joined: Thu Aug 30, 2018 10:42 pm
Country: Australia

Re: RC Switch, 4 Outputs on a Single RX Channel

Post by ThompsonJim »

Joao,

I also am not a code writer and not about to become one any day soon. I already have a life!
So in order for me to consider this project for my extra servo needs, I would like to have access to open source code to flash (preferably) arduino nano.
I have them in stock already.
Is there code available for sharing already for a nano?

I am about ready to abandon the logical switch arrangement suggested for me over here: viewtopic.php?f=101&t=11921

In the 5 or 6 hours I have wasted trying to get that mix to work, I could have wired and flashed several arduino nanos. Or I could have reversed a servo (took about 20 minutes when I did the second elevator one).

Thanks for the thread.

Jim.

Post Reply

Return to “General RC Electronic Projects and Discussion”