You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Great! In terms of making it simpler/faster, what about:

    function sendTest2(data) {
         var d = digitalPulse, p=txpin;
         //20ms long training burst. Had crap results with shorter ones.
         for (i = 0; i < 20; i++) { 
            d(p,1,0.5); 
            d(p,0,0.5); 
        } 
        d(p,1,0.5); //end training burst
        d(p,0,2);   //sync
       //send 1s or 0s, and pause
        data.forEach(function(v) {
          d(p,1,v?1.3:0.7); 
          d(p,0,0.5);
        });
        // wait for finish
        d(p,1,0);
    }
    var data = [0,1,0,1,1,0,1,1];
    sendTest2(data);
    

    So:

    • keeping comments out of loops helps with speed
    • copying digitalPulse into the function and using a small variable name helps
    • by pulsing to 1 at the end, you shouldn't need the digitalWrite(0) at the end

    I'm actually really surprised you need the training pulses... Personally I'd have just sent out one long pulse at the start:

    function sendTest2(data) {
         var d = digitalPulse, p=txpin;
         d(p,1,5);
         d(p,0,0.5);
         //send 1s or 0s, and pause
        data.forEach(function(v) {
          d(p,1,v?1.3:0.7); 
          d(p,0,0.5);
        });
        // wait for finish
        d(p,1,0);
    }
    

    Then hopefully you could just detect that pulse in the receiver and use it as a 'start of frame' - I think it's just a longish burst of transmit that is needed to let the receiver get its gain set properly. It should work, but then I guess it may not :)

    About going the other way - I'm actually really considering trying to build in some simple functionality for reading radio/IR signals (effectively specifying min + max pulse widths for a start pulse, 0 and 1). That'd let it handle noise a lot better, and would mean it could go to sleep right after processing a pulse - it would massively increase battery life on the receiver end.

  • What I was told on the Arduino forum is that the the receivers autoadjust their gain towards a ~50% duty cycle, so if the training burst is a solid pulse, that causes it to crank down the gain down too much.

    About going the other way - I'm actually really considering trying to build in some simple functionality for reading radio/IR signals (effectively specifying min + max pulse widths for a start pulse, 0 and 1)

    Oh cool!

About

Avatar for Gordon @Gordon started