Replaying IR signals through an IR LED

Posted on
  • Hey everyone,

    I'm just getting started with espruino here. My first project is to make the lights in my room(which are currently controlled via an IR remote) controllable by the espruino.

    I have all the gear here: an espruino, an IR sensor, and an IR led. I followed the tutorial for decoding the IR signal from the remote, but I don't get a single number long number. The output is something like:

    0
    9
    9
    4
    

    or

    0
    1
    0
    1
    

    depending on the function on the remote.

    Here is what the raw times are:

    0.006740570068359375
    0.006732940673828125
    0.011264801025390625
    0.0067386627197265625
    0.00673198699951171875
    0.011066436767578125
    0.0067157745361328125
    0.0067081451416015625
    0.0112285614013671875
    0.0067043304443359375
    0.0067081451416015625
    0.01103115081787109375
    0.00671100616455078125
    0.00670528411865234375
    0.01123523712158203125
    0.006710052490234375
    0.00670337677001953125
    

    So as per the tutorial saying there are two distinct groups of numbers, it looks like my numbers split off at 0.01, so I changed it to that in the code.

    So I'm unclear if I have the correct numbers or not? Also, I'm unclear on what the next steps are to lighting the IR led programmatically. Specifically, I'm not sure how to connect the IR Led to the espruino as well as how to send the proper code to it programmatically.

    The remote is a Lutron MIR-ITFS 5 function remote. I actually found the datasheet for the remote: http://www.lutron.com/TechnicalDocumentLibrary/048158.doc if that helps anyone understand this problem a bit better

    Thanks in advance for any help continuing on here! :)

  • I just discovered this tutorial for my exact remote, but written for arduino. I've tried porting it to javascript but its not working. Presumably due to the fact that javascript doesn't have "sleep" and so the timing is probably all off. Also, the bit-wise operation is probably not correct.

    here is my port: http://pastie.org/8981359

  • That document's description of the codes doesn't look a lot like you're getting... Still, it doesn't really matter too much - you just want to replay the exact sequence that you're receiving.

    I think the issue with your code is really just that you can't make the 39kHz square wave in software in Espruino because it's not fast enough - you have to use the hardware PWM for it.

    Take a look at this tutorial - where signals are generated for a IR remote control helicopter](http://www.espruino.com/wii_remote_control_helicopter)

    You use the PWM to generate the 39kHz carrier on one pin, and then use the other pin to output the much slower data (and the LED mixes everything together). Using setTimeout for the data might work, but I'd recommend that you just use digitalPulse - which is a bit more accurate.

  • Hi Gordon,

    Thanks for your response. So I racked my brain and tried a bunch of different approaches. I think I made some progress.

    First, I noticed that the tutorial measures the length of the gap between pulses and I thought that was curious. Ie, why not the length of the pulses themselves?, particularly, because IRReceiver module seems to allow both. So I coded this up: http://pastie.org/8997007 and measured the lengths of both and saw that both the pulse gaps and pulse lengths were not consistent across a button press. Then I went back to the documentation that I linked to above and saw that command length was around 82ms. My code in the pastie above puts a line break after 82ms has been reached and I noticed a pattern.

    First, the command is repeated, which I learned is a common pattern after reading Adafruits tutorial(http://learn.adafruit.com/ir-sensor/overview)

    Then, I had the thought to divide the length of each output by the bit length of ~2ms. Depending on whether it was rising or falling dictated whether the output was a logic 1 or logic 0. By doing this, I get the binary specified in the documentation for each button. Which is awesome, because now I'm getting somewhere.

    So now I just have to create a driver to output this binary in pulse length and pulse gap lengths and I should be in business. We'll see... I have to take a break now and will report my results later.

  • Great! Thanks for the update.

    To output the bit lengths, use:

    digitalPulse(myPin, 0, timeToLowerPulseFor);
    digitalPulse(myPin, 1, timeToRaisePulseFor);
    digitalPulse(myPin, 0, timeToLowerPulseFor);
    digitalPulse(myPin, 1, timeToRaisePulseFor);
    ...
    

    digitalPulse does some magic with interrupts that makes it much more accurate for a short series pulses than setTimeout would be.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Replaying IR signals through an IR LED

Posted by Avatar for pete @pete

Actions