Low Cost PCB's Low Cost Components

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

0 Members and 1 Guest are viewing this topic.

Offline EEVblog

  • Administrator
  • *****
  • Posts: 24191
  • Country: au
    • EEVblog
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« on: August 12, 2013, 07:44:17 AM »
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 12, 2013, 07:50:29 AM by EEVblog »
 

Offline HardBoot

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

Offline JoannaK

  • Frequent Contributor
  • **
  • Posts: 337
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #2 on: August 12, 2013, 09:20:43 AM »
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 EEVblog

  • Administrator
  • *****
  • Posts: 24191
  • Country: au
    • EEVblog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #3 on: August 12, 2013, 09:25:42 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.
 

Offline notsob

  • Frequent Contributor
  • **
  • Posts: 611
  • Country: au
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #4 on: August 12, 2013, 10: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: 44
  • Country: br
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #5 on: August 12, 2013, 10: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 EEVblog

  • Administrator
  • *****
  • Posts: 24191
  • Country: au
    • EEVblog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #6 on: August 12, 2013, 10: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, 11: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: 2067
  • Country: gr
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #8 on: August 13, 2013, 12:22:22 AM »
Two nice Ir AVR projects.

IRMP.
IRSND.

Alexander.
Become a realist, stay a dreamer.

 

Offline ddavidebor

  • Frequent Contributor
  • **
  • Posts: 997
  • Country: it
    • Fermium LABS website
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #9 on: August 13, 2013, 12:55:35 AM »
There is also a tweet library but it need wifi shield
Davide Bortolami,
Fermium LABS srl
 

Offline lgbeno

  • Frequent Contributor
  • **
  • Posts: 334
  • Country: 00
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #10 on: August 13, 2013, 04:02:35 AM »
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: 44
  • Country: br
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #11 on: August 13, 2013, 05:18:48 AM »
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 13, 2013, 05:59:44 AM »
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

  • Contributor
  • Posts: 48
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #13 on: August 13, 2013, 07:08:56 AM »
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 13, 2013, 08:54:52 AM »
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: 337
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #15 on: August 13, 2013, 10: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

  • Frequent Contributor
  • **
  • Posts: 696
  • Country: scotland
  • Pro EE guy many years ago, now it's a hobby.
    • IanJohnston.com
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #16 on: August 13, 2013, 04:10:10 PM »
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.

 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 2301
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #17 on: August 13, 2013, 04:26:44 PM »
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, 05:25:09 PM »
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: 337
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #19 on: August 13, 2013, 06:27:49 PM »
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 14, 2013, 01:38:13 AM »
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: 201
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #21 on: August 14, 2013, 12:30:25 PM »
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: 3823
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #22 on: August 14, 2013, 05:39:39 PM »
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

  • Contributor
  • Posts: 48
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #23 on: August 15, 2013, 04:29:50 AM »

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: 2516
  • Country: au
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #24 on: August 15, 2013, 08:28:27 AM »
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