Unstable IR signal replication?

Posted on
  • Hi everyone!

    I'm trying to control this RGBW LED driver over IR from an Espruino Pico. I'm using the record-replay code provided in the tutorial, but it works only occasionally. Sometimes it works multiple times in a row, then nothing for another 100 attempts (spamming the command). Both the remote and the Pico generates the output 100000000111111110000001011111101 repeatedly. Below is the recorded times.

    var remoteTimes = [ 9.19055938720, 4.59480285644, 0.49400329589, 0.66375732421, 0.51665306091, 0.61249732971, 0.51975250244, 0.63776969909, 0.51999092102, 0.60963630676, 0.51832199096, 0.66399574279, 0.51784515380, 0.58650970458, 0.54264068603, 0.63991546630, 0.49114227294, 0.66661834716, 0.49209594726, 1.76048278808, 0.54454803466, 1.73950195312, 0.62084197998, 1.71089172363, 0.54550170898, 1.73473358154, 0.49304962158, 1.78909301757, 0.51975250244, 1.76239013671, 0.51879882812, 1.78813934326, 0.54359436035, 1.73664093017, 0.54454803466, 0.58555603027, 0.51689147949, 0.63896179199, 0.54836273193, 0.60939788818, 0.51784515380, 0.61225891113, 0.57125091552, 0.58460235595, 0.51879882812, 0.63800811767, 0.54550170898, 1.76048278808, 0.49591064453, 0.63610076904, 0.48923492431, 1.79100036621, 0.49018859863, 1.81484222412, 0.49114227294, 1.76525115966, 0.57220458984, 1.73377990722, 0.51593780517, 1.76620483398, 0.53882598876, 1.74140930175, 0.54454803466, 0.63610076904, 0.51879882812, 1.76239013671, 0.51784515380, 40.56835174560, 9.18006896972, 2.31838226318, 0.54264068603, 97.63717651367, 9.23538208007, 2.25925445556, 0.51975250244, 97.62954711914, 9.23728942871, 2.26211547851, 0.51784515380 ];
    
    var picoTimes = [ 9.33551788330, 4.55093383789, 0.36334991455, 0.69141387939, 0.49662590026, 0.65827369689, 0.47397613525, 0.68569183349, 0.47302246093, 0.65898895263, 0.44536590576, 0.71907043457, 0.46825408935, 0.63633918762, 0.49567222595, 0.66280364990, 0.46825408935, 0.71430206298, 0.44631958007, 1.84535980224, 0.47492980957, 1.79195404052, 0.55408477783, 1.76715850830, 0.49591064453, 1.79862976074, 0.41198730468, 1.87301635742, 0.44441223144, 1.84631347656, 0.44631958007, 1.84535980224, 0.47397613525, 1.81770324707, 0.47302246093, 0.60939788818, 0.49495697021, 0.68855285644, 0.49972534179, 0.65803527832, 0.47492980957, 0.63514709472, 0.52356719970, 0.63610076904, 0.46825408935, 0.71430206298, 0.47302246093, 1.82437896728, 0.44059753417, 0.68569183349, 0.44631958007, 1.84822082519, 0.41484832763, 1.90162658691, 0.41770935058, 1.84631347656, 0.50163269042, 1.76811218261, 0.44250488281, 1.87015533447, 0.44631958007, 1.79672241210, 0.49495697021, 0.68664550781, 0.47206878662, 1.84822082519, 0.44441223144, 41.44477844238, 8.44764709472, 2.25925445556, 0.44631958007, 99.74384307861, 7.26509094238, 2.18200683593, 0.46825408935, 99.71523284912, 7.28607177734, 2.20584869384, 0.44441223144 ];
    
    

    Pico code:

    pinMode(A5,"input_pullup");
    
    var times = [];
    /* The ID of the watch we're using to record IR. We want to
    turn it off while we transmit in case we record outselves! */
    var currentWatch;
    
    function startWatching() {
      currentWatch = setWatch(function(e) {
        // work out how long the pulse was, in milliseconds
        var pulseLen = 1000 * (e.time - e.lastTime);
        // then save it, if it was less than 1 second
        if (pulseLen < 1000) {
          times.push(pulseLen);
        } else {
          times = [];
        }
      }, A5, {repeat:true});
    }
    
    startWatching();
    
    function stopWatching() {
      clearWatch(currentWatch);
      currentWatch = null;
    }
    
    function replay() {
      //Stop timer
      if(currentWatch !== null) stopWatching();
       //Light up LED1
      digitalWrite(LED1,1);
      // Start the 38kHz square wave
      analogWrite(B8,0.9,{freq:38000});
      // Send the pulses
      digitalPulse(B9, 1, times);
      // Wait until pulsing is finished
      digitalPulse(B9, 1, 0);
      // Turn LED1 off
      digitalWrite(LED1,0);
    }
    
    

    Any suggestions?

    Thanks and best regards,
    Maarten

  • Hi Maarten,

    Sorry about that... I think I might have noticed something not behaving quite right with digitalPulse on the 1v85 firmware.

    Do you think you could try flashing the 1v84 firmware? Copy and paste http://www.espruino.com/binaries/espruino_1v84_pico_1r3_wiznet.bin into the 'advanced flash' box in the Web IDE settings.

    It's not ideal, but it might help to solve your problems for now. I'll look into this and see if I can reproduce/fix it in the mean time.

  • Hi Gordon,

    Thanks for your reply. Unfortunately the problem persists on 1v75/1v79/1v85. I just tried with another (single) led controller and it worked flawlessly. The latter outputs a steady 100000000111111110000000011111111 while the former looks like this:

    100000000111111110000001011111101
    100000000111111110000001011111101
    1
    100000000111111110000001011111101
    1
    100000000111111110000001011111101
    

    Some recordings of the same signal appears to have higher success rate than other recordings. Strange.

  • Strange - so it's the recordings that are wrong, rather than the playback?

    You could check E.getErrorFlags() - it should return [], but if there have been so many transitions that it couldn't record all of them, you'll get a message shown... I guess that could be it?

    The other thing is the code you're showing doesn't output all the codes it receives, as if there's a gap it'll delete them. You could try:

    function startWatching() {
      currentWatch = setWatch(function(e) {
        var pulseLen = 1000 * (e.time - e.lastTime);
        if (pulseLen < 1000) {
          times.push(pulseLen);
        } else {
          console.log(times); //<----- added
          times = [];
        }
      }, A5, {repeat:true});
    }
    
  • Hi Gordon,

    Thanks for your efforts. Unfortunately I wasn't able to achieve an improved success rate for my two RGBW and RGB controllers, but I had some newbie luck discovering another solution (direct wiring). I cut off the IR receiver from the controller and connected its IR-input wire directly to the Pico IR LED output pin and wired the grounds together. I then removed the line analogWrite(B8,0.9,{freq:38000}); and changed the next line to *digitalPulse(B9, 0, times);*. After this the previously recorded times works like magic: ~100% success rate. I don't need the wireless feature for this application.

  • Ahh - it's possible that you wired the IR LED around the wrong way? Then it would be on when it should be off, and vice-versa. Depending on the signal it might have explained why it worked the first time and not others.

    Glad it works reliably when connected directly though!

  • Well, the IR did work reliably with a single-color controller. Let's assume it's my hardware for now. If anyone else experience this, we'll look into it deeper.

    Cheers.

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

Unstable IR signal replication?

Posted by Avatar for Maarten @Maarten

Actions