Simultaneously Reading Two PWM Signals from an RC Receiver with Arduino

Поделиться
HTML-код
  • Опубликовано: 14 окт 2024
  • 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

  • @TheOldKid
    @TheOldKid Год назад +2

    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

  • @HyperspacePirate
    @HyperspacePirate 2 года назад +1

    Super helpful, thanks man

  • @electronscape
    @electronscape 2 года назад

    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!!!

  • @rickperalta1921
    @rickperalta1921 4 месяца назад

    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
      @TheBoredRobotLLC  4 месяца назад

      Thanks for the advice! I also found another approach and I did that on another video as well.
      ruclips.net/video/MsUL-RY8ZrY/видео.htmlsi=HysbnLop4zBKpxot

  • @TheOldKid
    @TheOldKid Год назад

    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
      @TheBoredRobotLLC  Год назад +1

      Using servos in Arduino are much easier with the servo library. Here's a video on it:
      ruclips.net/video/7ZCqjNaSXzM/видео.html

    • @TheOldKid
      @TheOldKid Год назад

      ​@@TheBoredRobotLLCI'm curious if it wouldn't be easier or better using esp8266 or esp32

    • @TheBoredRobotLLC
      @TheBoredRobotLLC  Год назад

      @@TheOldKid To be honest, I haven't used those two products. I would have to do a bit of research on that.

  • @TopoBasah
    @TopoBasah 3 месяца назад

    sorry for my language before. But what if using nodemcu (esp8266) ? is the code still same ?

    • @TheBoredRobotLLC
      @TheBoredRobotLLC  3 месяца назад

      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.

  • @thorntontarr2894
    @thorntontarr2894 Год назад

    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
      @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
      @thorntontarr2894 Год назад

      @@TheBoredRobotLLC To save typing time and possible errors, is your code available for download?

    • @TheBoredRobotLLC
      @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
      @thorntontarr2894 Год назад

      @@TheBoredRobotLLC Thank you, I will review and test your code vs. ChatGPT.

  • @fletchoutdoors161
    @fletchoutdoors161 2 года назад

    Thank you sir, very helpful.

  • @Ayesha86_
    @Ayesha86_ 6 месяцев назад

    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
      @TheBoredRobotLLC  6 месяцев назад

      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.
      ruclips.net/video/MsUL-RY8ZrY/видео.htmlsi=HRwcIhCFfLf5MpO9

    • @rickperalta1921
      @rickperalta1921 4 месяца назад

      Concurrent with interference. If both interrupts fire at the same time one will be belayed by the service time.
      Good catch!

  • @davitsargsyan600
    @davitsargsyan600 2 года назад

    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
      @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/

  • @hithishi5292
    @hithishi5292 2 года назад

    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
      @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.

  • @strayworks2722
    @strayworks2722 2 года назад

    is it possible to connect 2 rc cars to a single remote and choose wether which one to control?

    • @TheBoredRobotLLC
      @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
      @TheBoredRobotLLC  Год назад

      I would agree that I often seem some jitter as well. It may help to add a smoothing function to that signal.

  • @charliecarpenter2840
    @charliecarpenter2840 6 месяцев назад

    Can't get your code to compile. Edit: Got it! was being stupid

    • @TheBoredRobotLLC
      @TheBoredRobotLLC  6 месяцев назад +1

      I'm glad it worked!

    • @charliecarpenter2840
      @charliecarpenter2840 6 месяцев назад

      @@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!