Sending Bits via Infrared.

Posted on
  • Hi@all,

    i recieved 2 Picos and they are great. For Project, both have to communicate together over infrared. I have tested this tutorial . Receiving tv remote signals is no problem. But i have trouble with sending data. I want to send my own data like '10001111'. How can i do this? Have anyone an idea? I hope you can help me.

    best regards
    daniel

  • Just specifying the bits is not sufficient to specify how to send it over IR - because you need to know how long the pulse for 1 vs 0 needs to be.

    Gordon's IRReceiver module works for those brands listed, and defines a 1 as something longer than 0.8ms

      code += 0|d>0.0008;
    

    Depending on what's receiving it, you may need a different value. The example further down in the tutorial explains hwo to figure that out for an unknown protocol. If you're designing both ends, you can choose whatever value you like, in that general area.

  • Hey,
    thanks for your reply. For correct understanding:

    If i use Gordon`s IRReciever (what i want), and sending a logical 1, i have to use at first:

    analogWrite(A5,0.9,{freq:38000});
    

    and than:

    digitalPulse(A6, 1, 1);
    

    and for a logical 0:

    digitalPulse(A6, 1, 0.8); //or less
    

    ?

    In my mind so i have to send '110':

    digitalPulse(A6, 1, [1,1, 0.8]);
    

    sry for my nooby question/post, but i only want to understand.

    best regards
    daniel

  • Hi Daniel,

    No problem - when you supply an array to digitalPulse, you're actually specifying [up_time,down_time,up_time,down_time,...­], and you probably want a fixed gap between pulses, so to send 110 you probably want something like:

    var gap = 0.5;
    digitalPulse(A6, 1, [1,gap,1,gap,0.6]);
    

    Note that the code checks d>0.0008, but because it's the real world the timings won't be accurate. You want to leave some leeway (maybe 0.2ms?) - so when sending a 0 maybe send 0.6 and for a 1 send 1.0.

  • Hi,

    thanks for your answer. It was very helpful. Now i tested with the follow code:

    Transmitter:

    digitalWrite(B7, 0);
    digitalWrite(A8, 1); 
    pinMode(B6,"input_pullup");
    
    setInterval(function(){
      
      var gap = 0.5;
      var pulse = [1.0, gap, 1.0, gap, 0.6, gap, 1.0];
      
      digitalWrite(LED1,1);
      
      analogWrite(A5, 0.9,{freq:38000});
      
      digitalPulse(A6, 1, pulse);
      
      digitalPulse(A6, 1, 0);
      
      digitalWrite(LED1,0);
    },1000);
    
    

    and Receiver code:

    digitalWrite(B7, 0); 
    digitalWrite(A8, 1); 
    
    require("IRReceiver").connect(B6, function(code) {
    
      console.log(code);
      
      if(code === '0010') digitalWrite(LED2, 1);
      
    });
    

    I get every time a '000' in the console and no LED will be switched on. Sometimes an '0001'. Is there way to transmit correctly or did i something wrong?

    Sry.

    best regards
    Daniel

  • Is the led the right way around?

  • Is the led the right way around?

    Nice thinking :) That's almost certainly your problem.

  • Hey,
    thanks for your really good support. The LED is connected in right way. That was the first, what i checked. But it was a really nice thinking :)
    Yesterday, i tested a little bit and solve the problem. The solution is (for me) confusing and i don`t know the technical details.

    Sending a zero:

    [1.0, gap]
    

    Sending a 1:

    [gap, 1.0]
    

    and as last bit for end of transmitting:

    [gap]
    

    If you send no 'gap' as last, it won`t be shown the string in the console.

    Complete code for sending '101001':

    digitalWrite(B7, 0); // Set B7 to GND
    digitalWrite(A8, 1); // Set A8 to 3.3V
    // Because we're not using the module, we have to manually pull up the data pin
    pinMode(B6,"input_pullup");
    
    setInterval(function(){
      
      var gap = 0.5;
    //  var pulse = [0.6, gap, 0.6, gap, gap, 2.0, gap, gap, 0.6];
        var pulse = [gap, 1.0, 1.0, gap, gap, 1.0, 1.0, gap, 1.0, gap, gap, 1.0, gap];
    
      digitalWrite(LED1,1);
      
      analogWrite(A5, 0.9,{freq:38000});
      
      digitalPulse(A6, 1, pulse);
      
      digitalPulse(A6, 1, 0);
      
      digitalWrite(LED1,0);
    },1000);
    

    best regards

  • Ok, I'm not sure I understand what's going on either!

    Do you have an oscilloscope? You could look at the signal coming out of A6 and see if it's what you expect...

  • Hey,
    i tested the other controller, on receiving data, and it is a little bit frustrating. Above, the description don`t works on this controller.

    For this pulse:

      var pulse = [0.6, gap, 1.0, gap, 0.6, gap, 1.0, gap, 1.0, gap];
    

    i get this console.log:

    1011
    

    I don`t know, where the problem is and which controller will be right....puh

    I used a normal IR LED and a vs1838b

    Sry, i don`t have an oscilloscope :(
    best regards

  • How bout 0.4 and 1.4 or something - give yourself some margin.

    I don't have equipment to monitor digitalPulse() output - this thread is making me suspicious of it, as it's just so simple in theory. I don't know how you could do that with a scope, since it's a transient signal. Maybe with one of those newfangled digital scopes....

    You've tried the LED both ways around (flipping it will invert the on time and gaps, which would also look like a signal to the receiver)

  • I think you could really do with some kind of oscilloscope - a cheap one like the 'DSO nano' would work well, or you could even rig something up using the audio jack of your PC and some resistors/capacitors.

    Assuming you are using the latest firmware (1v79) I'd be pretty sure that Espruino is doing what you tell it. On Saturday I did a Nodebots day, and someone there was using digitalPulse exactly like you have above in order to fake an IR remote signal. It worked first time.

    Also, I notice you now have an even number of array elements, which will mean that the IR LED is left ON after the pulse is sent. It could explain some bad readings?

    For instance:

    digitalPulse(pin, 1, [A,B,C,D]);
    // is the same as
    digitalWrite(pin,1);
    wait(A);
    digitalWrite(pin,0);
    wait(B);
    digitalWrite(pin,1);
    wait(C);
    digitalWrite(pin,0);
    wait(D);
    digitalWrite(pin,1); // <--- leaves the IR LED on
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Sending Bits via Infrared.

Posted by Avatar for KFK-mpg @KFK-mpg

Actions