0

Hello i am using an arduino mkr1000 so send and IR signal using the IRremote library for mkr1000 IRremote library. I am having problems with IRsend.

First i used the IRdump example to get the data from my remote button. When i finished this i tried the IRsend example but it seems to be not working.

I temporarily replaced with a ordinary LED to show if it is really blinking, but it is not. I have tested the both the ordinary LED and IR LED that they worked.

I also think that i have wired the LED correctly according to the example

PIN 3 -> LED -> Resistor -> Ground

My circuit was further confirmed correct when i upload a sketch that makes it blink.

Basically i am trying to send a NEC 32bit signal, 0x2FD807F

but i guess they were not able to finish the library of send for mkr1000???

in this post a comment was made with a code but did not really have any detail on how to use it.

here is where i am currently at

int IR_S =  3;

void setup()
{
  pinMode(IR_S,OUTPUT);
}

void loop() {

  IR_Sendcode(0x2FD807F);
  delay(1000); 
}



void IR_Send38KHZ(int x,int bit)      //Generate 38KHZ IR pulse
{      
     for(int i=0;i<x;i++)//15=386US
     {      
          if(bit==1)
          {
         digitalWrite(IR_S,1);
           delayMicroseconds(9);
         digitalWrite(IR_S,0);
           delayMicroseconds(9);
          }
          else 
          {
         digitalWrite(IR_S,0);
           delayMicroseconds(20);
          }            
     }
}

void IR_Sendcode(uint8_t data)      // Send the data
{
   for(int i=0;i<8;i++)
    {
      if((data&0x01)==0x01)
       {
          IR_Send38KHZ(23,1);
          IR_Send38KHZ(64,0);             
       }
       else 
        {
           IR_Send38KHZ(23,1);
           IR_Send38KHZ(21,0);  
        }
      data=data>>1;
    }  
}
Jake quin
  • 738
  • 1
  • 9
  • 25

1 Answers1

2

I while i was waiting for replies i created my own code. I have finished and tested it. It should theoretically work on any arduino.

/*
  This is a code for NEC Infrared Transmission Protocol Transmitter

  NEC specifications are

    ~ Carrier Frequency is 38kHz
    
    * Logical '0' – a 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
    * Logical '1' – a 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms

    - a 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
    - a 4.5ms space
    - the 8-bit address for the receiving device
    - the 8-bit logical inverse of the address
    - the 8-bit command
    - the 8-bit logical inverse of the command
    - a final 562.5µs pulse burst to signify the end of message transmission.

  Example,
    If the code recieved from the data dump from the IRremote library is 0x2FD807F
      -0x02 is address
      -0xFD is the inverse address
      -0x80 is the command
      -0x7F is the inverse command

  THIS PROGRAM IS A BLOCKING PROGRAM
*/


#define IR 3
#define CarrierFreqInterval 11

void setup() {
  pinMode(IR, OUTPUT);
  digitalWrite(IR, LOW);
}

void loop() {
//  unsigned long start = micros();

  transmit(0x02FD807F);

//  unsigned long ends = micros();
//  unsigned long delta = ends - start;
//  Serial.println(delta);

  delay(500);
}


void transmit(uint32_t data) {
  //Function for transmiting the data

  uint32_t bitcount = 0x80000000;

  // 9ms pulse burst
  for (int i = 0; i < 355; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }


  // 4.5ms space
  delayMicroseconds(4500);



  //8bit address,adress inverse,command,command inverse
  while ( bitcount != 0b0) {
    if ((data & bitcount) == bitcount) {
      pulseHIGH();
    }
    else {
      pulseLOW();
    }

    bitcount = bitcount >> 1;
  }


  //final pulse burst
  for (int i = 0; i < 21; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }
}

void pulseHIGH() {
  // Pulse 38KHz good for a LOGIC '1'
  
  for (int i = 0; i < 21; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }
  delay(1);
  delayMicroseconds(687.5);
}

void pulseLOW() {
  // Pulse 38KHz good for a LOGIC '0'

  for (int i = 0; i < 21; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }
  delayMicroseconds(562.5);

}
Jake quin
  • 738
  • 1
  • 9
  • 25