No video
Simultaneously Reading Two PWM Signals from an RC Receiver with Arduino
This is an example that demonstrates how to use Arduino to simultaneously read two RC signals (50 Hz PWM) using external interrupts.
👉Subscribe for more robotics and engineering tips:
/ @theboredrobotllc
Share this video with a friend:
• Simultaneously Reading...
Parts needed for this example:
Arduino Uno: amzn.to/3IofhnP
RC (Remote Control) Transmitter and Receiver: amzn.to/33vpvEp
Male to Male Jumper Wires: amzn.to/35ax6sl
Servo Connector: amzn.to/3rE53c9
Disclaimer: This video contains affiliate links, meaning that if you make a purchase from one of the product links, I'll receive a small commission.
Пікірлер: 36
I just realized you did what ive been trying to figure out. You made it look super easy. Funny how different problem solving is between computers and my profession. You solve by variables and interrupts where in my world the answer can always be a bigger hammer or bigger torch
@TheBoredRobotLLC
Жыл бұрын
I'm glad it helped.
Excellent video - Thanks! Consider using unsigned math on micros() it simplifies the code (no if() needed). Consider a small state machine in the inyerrupts. On a rising edge save time and on falling edge compute delta and set a new system state. Thid avoids some complications and can help clarify the interface.
@TheBoredRobotLLC
2 ай бұрын
Thanks for the advice! I also found another approach and I did that on another video as well. kzread.info/dash/bejne/f6eJro-LiZvAorw.htmlsi=HysbnLop4zBKpxot
Super helpful, thanks man
@TheBoredRobotLLC
2 жыл бұрын
Glad it helped!
Saved me a TON of time! Thank you!!! while waiting for the STM32 with its Interupatable input capture, this is not the most efficient way to do it, however to get a Atmel at this clock speed to do this so well....... hats off to you Sir!! NICE WORK. thank you again!!!
@TheBoredRobotLLC
Жыл бұрын
Glad it helped!
Your Two PWM reads via Interrupts should help many as it is not often that YT videos employ interrupts which is sad when considering real time projects lick RC devices. However, while not critical, I note that unless the receiver output is an "open collector" , the "INPUT_PULLUP" is not required. Most likely the receiver "signal" output can drive several 'TTL unit' loads. Perhaps you have seen the actual circuit of the receiver which could justify your choice. BTW, as I write this, I had ChatGPT 4.0 write this same type of code with dual reads using interrupts; I plan to compare your code and ChatGPT's code which I successfully tested.
@TheBoredRobotLLC
Жыл бұрын
Thanks for the feedback. It's just a habit from some of my other projects that I've been using "INPUT_PULLUP" for interrupts. I'd be interested to see what results you get when you compare the code to ChatGPT's code.
@thorntontarr2894
Жыл бұрын
@@TheBoredRobotLLC To save typing time and possible errors, is your code available for download?
@TheBoredRobotLLC
Жыл бұрын
@@thorntontarr2894 The blog for this video can be found here: www.theboredrobot.com/post/simultaneously-reading-two-pwm-signals-from-an-rc-receiver-with-arduino The code is posted here: github.com/TheBoredRobot/Arduino-Examples/blob/master/Dual_RC_Read.ino
@thorntontarr2894
Жыл бұрын
@@TheBoredRobotLLC Thank you, I will review and test your code vs. ChatGPT.
Thank you sir, very helpful.
@TheBoredRobotLLC
2 жыл бұрын
Thanks! I'm glad you found it useful.
sorry for my language before. But what if using nodemcu (esp8266) ? is the code still same ?
@TheBoredRobotLLC
Ай бұрын
I've never used that piece of hardware before. Just a quick google search shows that it uses a different language, so I do not believe the code will work.
How is that simultaneous reading? if it was simultaneous wouldnt that mean you can do both accelerate and turn on the joystick and it should chnage both graphs at the same time on the plotter. i need this because i read from a transmitter but one rc signal is for my left wheels and the other rc signal is for the right wheels. i can do both separately but not a the same time so i cant make my car go forward
@TheBoredRobotLLC
4 ай бұрын
You're right it is not true simultaneous reading, since Arduino isn't capable of that. However, this is a demonstration on how to avoid using pulseIn(), which blocks all other calculations while it's measuring the pulse lengths. For most applications, using timers to read multiple signals would make it "appear" as if the signals are being read at the same time. I do have an updated approach to this that seems to work better. kzread.info/dash/bejne/f6eJro-LiZvAorw.htmlsi=HRwcIhCFfLf5MpO9
@rickperalta1921
2 ай бұрын
Concurrent with interference. If both interrupts fire at the same time one will be belayed by the service time. Good catch!
how would we do this for 5 or 6 channels? We only have 2 pins we can connect to. Could you make a video on this?
@TheBoredRobotLLC
2 жыл бұрын
For more channels, you'll need a different Arduino board. Here's a link that'll show you which board has additional pins that are capable of interrupts: www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
Nice website. After reading your article it dawned on me youre using stepper motors where im using servos. I assume code would be different between the two.
@TheBoredRobotLLC
Жыл бұрын
Using servos in Arduino are much easier with the servo library. Here's a video on it: kzread.info/dash/bejne/aY5308yHkba-qrA.html
@TheOldKid
Жыл бұрын
@@TheBoredRobotLLCI'm curious if it wouldn't be easier or better using esp8266 or esp32
@TheBoredRobotLLC
Жыл бұрын
@@TheOldKid To be honest, I haven't used those two products. I would have to do a bit of research on that.
is it possible to connect 2 rc cars to a single remote and choose wether which one to control?
@TheBoredRobotLLC
2 жыл бұрын
I believe it is possible, but you would probably have to figure out a way to switch frequencies from your controller. That's not something that I have looked into before.
the generally works but the input value has some jitter????????
@TheBoredRobotLLC
Жыл бұрын
I would agree that I often seem some jitter as well. It may help to add a smoothing function to that signal.
Can't get your code to compile. Edit: Got it! was being stupid
@TheBoredRobotLLC
4 ай бұрын
I'm glad it worked!
@charliecarpenter2840
4 ай бұрын
@@TheBoredRobotLLC I wanted to hook up a 90's RC controller to a drone sim. I had a teensy to hand and so used your code repeated across 4 pins to read signals from the RC reciever, then mapped those values to joypad values using xinput. It has worked pretty well and is keeping me busy until the drone turns up so thanks!
i was searching for this from last week, thanks a lot!! your videos are very informative! and i had a doubt, can the same code or single channel be used for receiver which supports PPM and how to control 2 DC motors (which has encoder with PWM ,DIR and A&B feedback pins) using RC receiver!! (It would be great, Even if the video is about PPM and DIR pins only) thank you very much!!
@TheBoredRobotLLC
2 жыл бұрын
Thank you! I'm glad you found the videos useful. I'm not sure if the code will work on a PPC receiver. I would say try it out and tweak how you are measuring the time between pulses. Once you figure out the min and max values from your receiver you can map them to another variable and output the PWM speed on the motor. The DIR will be dictated by what value you are reading at the center point of your joystick. If you are using an Arduino Uno, you'll only get two pins for interrupts, so you won't be able to connect an encoder for two motors.