Author Topic: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial  (Read 32391 times)

0 Members and 1 Guest are viewing this topic.

Offline EEVblogTopic starter

  • Administrator
  • *****
  • Posts: 37661
  • Country: au
    • EEVblog
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« on: August 11, 2013, 09:44:17 pm »
How to capture and reverse engineer an infrared IR code and use an Arduino or other microcontroller to replay the command.
Oscilloscope and logic analyser capture, coding, troubleshooting, tounge angle, it's all here.
In this instance Dave capture the NEC (Japanese) code from his Canon video camera remote control on the digital oscilloscope, figures out all the bits and encoding, and writes an Arduino library to replay the code back, and verifies it with his Saleae Logic logic analyser.

CODE: http://gist.github.com/EEVblog/6206934

! Private video
« Last Edit: August 11, 2013, 09:50:29 pm by EEVblog »
 

Offline HardBoot

  • Regular Contributor
  • *
  • Posts: 160
  • Country: ca
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #1 on: August 11, 2013, 11:15:43 pm »
Hmm it's simpler than I thought it'd be, I'll have to try that.
 

Offline JoannaK

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #2 on: August 11, 2013, 11:20:43 pm »
IR communication (Irda and remote control) protocols are indeed quite easy. One of the messy detail is the lack of standards among manufacturers so one may need send 10's of different codes just to turn various televisions off.

Dave: For timing, IMHO it would be more reliable and elegant to use In-chip PWM for making the 38Khz carrier frequency. I'm not sure how many lines of code it's needed for setting it up, but it should not be too hard.
 

Offline EEVblogTopic starter

  • Administrator
  • *****
  • Posts: 37661
  • Country: au
    • EEVblog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #3 on: August 11, 2013, 11:25:42 pm »
Dave: For timing, IMHO it would be more reliable and elegant to use In-chip PWM for making the 38Khz carrier frequency. I'm not sure how many lines of code it's needed for setting it up, but it should not be too hard.

Then the code isn't as portable, nor usable in chips that don't have PWM, nor as easily understandable for beginners.
 

Offline notsob

  • Frequent Contributor
  • **
  • Posts: 690
  • Country: au
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #4 on: August 12, 2013, 12:43:10 am »
Just to add a bit of info for those interested, here's a quick pointer  on RC5 and NEC data formats

http://www.vishay.com/docs/80071/dataform.pdf
 

Offline crisr

  • Contributor
  • Posts: 46
  • Country: br
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #5 on: August 12, 2013, 12:42:00 pm »
Now, that's a better approach!  :-+

Just one note: I know the code is an example, but for time-sensitive stuff, such as 38KHz carrier, and even the bits themselves, I always try to use timer interrupts, since in C it's a little bit hard to know exactly how long an instruction / function call will take, and you generally have to account for loop overhead as well. Another advantage (or the main one) of using interrupts is that your main code can continue doing other things while the ISR takes care of IR transmission.

Here's the best resource on IR protocol info: http://www.sbprojects.com/knowledge/ir/ -- check the specific protocols on the left-hand menu.
 

Offline EEVblogTopic starter

  • Administrator
  • *****
  • Posts: 37661
  • Country: au
    • EEVblog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #6 on: August 12, 2013, 12:54:48 pm »
Just one note: I know the code is an example, but for time-sensitive stuff, such as 38KHz carrier, and even the bits themselves, I always try to use timer interrupts

Hardware PWM would be better.
 

Offline casper.bang

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: dk
  • Pro SE, amateur EE.
    • BangBits
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #7 on: August 12, 2013, 01:32:20 pm »
Nice practical demonstration of DS20XX in action. I wonder how much data you are actually capable of capturing with this 14Mpts beast?! This is the sort of thing that has me looking beyond the entry level scopes.
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #8 on: August 12, 2013, 02:22:22 pm »
Two nice Ir AVR projects.

IRMP.
IRSND.

Alexander.
Become a realist, stay a dreamer.

 

Online ddavidebor

  • Super Contributor
  • ***
  • Posts: 1190
  • Country: gb
    • Smartbox AT
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #9 on: August 12, 2013, 02:55:35 pm »
There is also a tweet library but it need wifi shield
David - Professional Engineer - Medical Devices and Tablet Computers at Smartbox AT
Side businesses: Altium Industry Expert writer, http://fermium.ltd.uk (Scientific Equiment), http://chinesecleavers.co.uk (Cutlery),
 

Offline lgbeno

  • Frequent Contributor
  • **
  • Posts: 349
  • Country: 00
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #10 on: August 12, 2013, 06:02:35 pm »
Dave, why didn't you just open up the remote and hack the button to simulate a real button press...  Maybe use an opto :)

Sorry, couldn't resist.  Please do not take this post seriously...

Great video!




Sent from my iPhone using Tapatalk 2
 

Offline crisr

  • Contributor
  • Posts: 46
  • Country: br
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #11 on: August 12, 2013, 07:18:48 pm »
Hardware PWM would be better.

Yes, but as you said yourself, not every chip has hardware PWM, such as PIC 12F series which I normally use for such applications. But AFAIK, most common MCUs these days do have interrupts (PIC10F series being an exception; don't know about AVRs as I am not familiar with them). Code portability might still be an issue, but I think the concept would be fairly similar even between different architectures.
 

Offline casper.bang

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: dk
  • Pro SE, amateur EE.
    • BangBits
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #12 on: August 12, 2013, 07:59:44 pm »
Quote
PIC10F series being an exception; don't know about AVRs as I am not familiar with them

Even the tiniest AVR's have hardware PWM's as well as interupts.
 

Offline jnissen

  • Regular Contributor
  • *
  • Posts: 63
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #13 on: August 12, 2013, 09:08:56 pm »
Bravo! You did it right this time!  ;)
 

Offline squeakbat

  • Newbie
  • Posts: 4
  • Country: us
  • Hacking by echolocation
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #14 on: August 12, 2013, 10:54:52 pm »
For the scoped challenged (like me), a PC microphone jack works great for reverse engineering IR protocol.  It even has power (5V through a 200-ohm resister, I think) to drive the IR transistor.  To see the signal, use any audio recorder that lets you zoom in on the waveform (like Audacity).

When I did my Arduino-driven IR remote, I used one timer to generate the carrier, which is fed to another timer to generate interrupts at the pulse period.  The Arduino library doesn't support any of this, of course, and the code was super messy in the end.  (Timer 0 is used for timing by the library internally, and repurposing it messes up calls like delay().)  So, Dave's way is great as long as it works.  (My code had to do other things in the mean time so couldn't block sending the IR sequence.)
— Ellen
 

Offline JoannaK

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #15 on: August 13, 2013, 12:32:37 am »
Dave: For timing, IMHO it would be more reliable and elegant to use In-chip PWM for making the 38Khz carrier frequency. I'm not sure how many lines of code it's needed for setting it up, but it should not be too hard.

Then the code isn't as portable, nor usable in chips that don't have PWM, nor as easily understandable for beginners.

And apparently it would not be possible to implement with basic Arduino without some 3rd party libhraries. Apparently there are no easy way to set PWM speed for analog outputs, and the alternative (tone command) does not have options for setting the the frequency (38KHz) high enough for carrier.  :palm:

Ah well.. we allays have 555.s ..  >:D
 

Offline IanJ

  • Supporter
  • ****
  • Posts: 1580
  • Country: scotland
  • Full time EE biz & Youtuber
    • IanJohnston.com
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #16 on: August 13, 2013, 06:10:10 am »
Hi all,

Related.........For anyone wanting to Rx/Tx IR on the Arduino and using multiple protocols (NEC, Sony, RC5, RC6), I used Ken Shirrif's IR code library on one of my own projects.

http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html

Contains detailed explanation & usage.

Ian.

Ian Johnston - Manufacturer of the PDVS2mini & author of the free WinGPIB app.
Website & Online Shop: www.ianjohnston.com
YT Channel (electronics repairs & projects): www.youtube.com/user/IanScottJohnston, Twitter (X): https://twitter.com/IanSJohnston
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #17 on: August 13, 2013, 06:26:44 am »
Quote
it would not be possible to implement with basic Arduino without some 3rd party libhraries.
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...
 

Offline squeakbat

  • Newbie
  • Posts: 4
  • Country: us
  • Hacking by echolocation
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #18 on: August 13, 2013, 07:25:09 am »
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...

I totally agree that the tutorial is at just the right level.

About programming the hardware directly, that's at little harder than just reading the datasheet because certain things interact badly with the library.  For example, timer 0 is used for internal time keeping, so it can't be reprogrammed to generate the IR carrier (or not easily anyway).  And you wouldn't know this without reading the source.

I'm not at all criticizing the Arduino.  It's not meant for programming the AVR from scratch.  At the same time, the source is freely available and not too hard to read and modify.  So it's a reasonable compromise: fairly easy to use without locking out low-level features.

The same goes for the hardware.  It works out of the box, and is at the same time easily hackable:  schematics are available, and the two-layer board is easy to modify.
— Ellen
 

Offline JoannaK

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #19 on: August 13, 2013, 08:27:49 am »
Quote
it would not be possible to implement with basic Arduino without some 3rd party libhraries.
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

I have never used Arduinos myself (started coding on C64 era, with HC11 were first embedded), so it's not (yet) 100% clear to me how much the user is allowed to mess outside of the official sandbox.

Quote
There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...

Ok, so it's hackable for those who can and want to. And it's really difficult to blame a platform that 10€ price point.

 

Offline sagdahl

  • Contributor
  • Posts: 26
  • Country: se
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #20 on: August 13, 2013, 03:38:13 pm »
Brilliant video again.
You are the champ!
That, that is, is. That, that is not, is not. Is that it? It is!
 

Offline mjkuwp

  • Supporter
  • ****
  • Posts: 259
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #21 on: August 14, 2013, 02:30:25 am »
I like the video!

 I made an IR repeater using Arduino except that I set up and used the timers my own way.  The Arduino environment will not stop you doing things your own way; one just has to understand that some functions will break.  I looked at Ken Shirriff's stuff closely but did my own thing mainly for the sake of learning.

I used Timer0 for timing slow functions - such as holding a pin low for 4 seconds to reboot my PC.
I used Timer 2 in PWM mode to create the 38khz carrier frequency

totally disabled Timer1

so delay() probably doesn't work and millis() doesn't work.  I don't like those Arduino functions anyway so I don't mind those breaking.


 

Offline Stonent

  • Super Contributor
  • ***
  • Posts: 3824
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #22 on: August 14, 2013, 07:39:39 am »
Quote
it would not be possible to implement with basic Arduino without some 3rd party libhraries.
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

I have never used Arduinos myself (started coding on C64 era, with HC11 were first embedded), so it's not (yet) 100% clear to me how much the user is allowed to mess outside of the official sandbox.

Quote
There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...

Ok, so it's hackable for those who can and want to. And it's really difficult to blame a platform that 10€ price point.

It's still basically C++ but there are standard things that the Arduino software includes that shield you from having to do a lot of the setup routines. It also assumes you're running the chip at 16MHz so there's no issues there.

Also you can still program the AVR chip using Atmel Studio but you have to make sure your code matches your clock speed otherwise things will not run at the right speed.

I haven't written anything too complex yet but I did successfully convert one Arduino sketch to standard C in Atmel Studio. The first time it ran too slow but I realized I had the clock set wrong, just another 10 seconds and a recompile and everything was great.
The larger the government, the smaller the citizen.
 

Offline jnissen

  • Regular Contributor
  • *
  • Posts: 63
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #23 on: August 14, 2013, 06:29:50 pm »

I have never used Arduinos myself (started coding on C64 era, with HC11 were first embedded), so it's not (yet) 100% clear to me how much the user is allowed to mess outside of the official sandbox.


I was in the same boat a few years ago and just picked one up. Amazed at how easy the platform was. I was used to old school assembler and getting your hands dirty with code and hardware. I still do that from time to time as needed. The tools support a huge amount of shared knowledge with the various libraries and code examples. My son actually turned me onto the Arduino after I gave him about 1% chance of being successful designing an LCD enabled tachometer. He got his proto working in two days! Made a believer of me!
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2797
  • Country: au
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #24 on: August 14, 2013, 10:28:27 pm »
I've used the Arduino boards as a project proof of concept.  I'd probably not use one in a sold product, but they are perfectly fine for R&D.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf