IR Remote Reading Help

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Dariusrussell
 
Posts: 3
Joined: Sat Sep 29, 2012 5:06 pm

IR Remote Reading Help

Post by Dariusrussell »

I am making an IR remote, and basically making a much more complicated intervalometer as in the tutorial. Obviously my code is going to be much much different. Not to criticize, but I feel like the tutorial lacked on the bit of, how to actually interpret the code, and how to grab what you need.
I set up the IR sensor, and it worked great. I then got my signal. This is where I got confused, and a bit overwhelmed.

Here is the signal I got.

Code: Select all

Received: 

OFF 	ON
752 usec, 160 usec
52864 usec, 100 usec
29544 usec, 60 usec
35012 usec, 40 usec
80 usec, 60 usec
38872 usec, 40 usec
16248 usec, 60 usec
43388 usec, 40 usec
22332 usec, 60 usec
19840 usec, 80 usec
50776 usec, 120 usec
45440 usec, 80 usec
8876 usec, 120 usec
20232 usec, 120 usec
15168 usec, 40 usec
60 usec, 100 usec
27200 usec, 80 usec
50544 usec, 80 usec
63188 usec, 40 usec
43912 usec, 120 usec
44332 usec, 140 usec
63024 usec, 60 usec
13404 usec, 140 usec
11880 usec, 160 usec
51088 usec, 120 usec
17240 usec, 100 usec
3216 usec, 140 usec
48016 usec, 80 usec
51988 usec, 160 usec
39904 usec, 40 usec
32268 usec, 140 usec
25508 usec, 60 usec
60 usec, 100 usec
11948 usec, 80 usec
34068 usec, 60 usec
28332 usec, 160 usec
44368 usec, 40 usec
80 usec, 140 usec
8292 usec, 40 usec
60 usec, 60 usec
int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
	16, 5286,
	10, 2954,
	6, 3501,
	4, 8,
	6, 3887,
	4, 1624,
	6, 4338,
	4, 2233,
	6, 1984,
	8, 5077,
	12, 4544,
	8, 887,
	12, 2023,
	12, 1516,
	4, 6,
	10, 2720,
	8, 5054,
	8, 6318,
	4, 4391,
	12, 4433,
	14, 6302,
	6, 1340,
	14, 1188,
	16, 5108,
	12, 1724,
	10, 321,
	14, 4801,
	8, 5198,
	16, 3990,
	4, 3226,
	14, 2550,
	6, 6,
	10, 1194,
	8, 3406,
	6, 2833,
	16, 4436,
	4, 8,
	14, 829,
	4, 6,
	6, 0};


As you can see this is significantly longer...
I am extremely confused on how to put this into code, so if anyone would be willing to do maybe the first 3 or 5 sets of pulses for me, and explain what I should do for the rest. I would be so grateful. Also can anyone tell me if this IR pulse looks normal?

Here is the example code for the PulseIR sketch

Code: Select all

// This sketch will send out a canon D50 trigger signal (probably works with most canons)
// See the full tutorial at http://www.ladyada.net/learn/sensors/ir.html
// this code is public domain, please enjoy!

int IRledPin =  12;    // LED connected to digital pin 12
int buttonPin = 3;     // footswitch connected to digital #3

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the IR digital pin as an output:
  pinMode(IRledPin, OUTPUT);      
  
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH); // pullup on
  
  Serial.begin(9600);
}

void loop()                     
{
  if (! digitalRead(buttonPin)) {
    // footswitch pressed
    Serial.println("Sending IR signal");
  
    SendCanonCode();
     
    delay(3*1000);  // wait 3 seconds (* 1000 milliseconds)
  }
}

// This procedure sends a 38KHz pulse to the IRledPin 
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait
  
  cli();  // this turns off any background interrupts
  
  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds
   digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds

   // so 26 microseconds altogether
   microsecs -= 26;
  }
  
  sei();  // this turns them back on
}

void SendCanonCode() {
  // This is the code for my particular Canon, for others use the tutorial
  // to 'grab' the proper code from the remote
  
  pulseIR(2080);
  delay(27);
  pulseIR(440);
  delayMicroseconds(1500);
  pulseIR(460);
  delayMicroseconds(3440);
  pulseIR(480);

    
  delay(65); // wait 65 milliseconds before sending it again
  
  pulseIR(2000);
  delay(27);
  pulseIR(440);
  delayMicroseconds(1500);
  pulseIR(460);
  delayMicroseconds(3440);
  pulseIR(480);
}

wnc
 
Posts: 38
Joined: Tue May 08, 2012 9:16 am

Re: IR Remote Reading Help

Post by wnc »

Hi
I have gone through the phase that you encountered now. Basically the tutorial is great and complete. It gave you a lot of information for you to understand. Once you digested, you modify it to suit your application. Below is the code that I modify to suit my application. It may help your problem.
I split into two sketch to understand easily.
One is to capture the IR code.
Another is to transmit the learned code.

Here is decoding the IR signal.

Code: Select all

// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN      PIND
#define IRpin          7   // this pin number can be changed as you wish

// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20 
#define FUZZINESS 20

// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2];  // pair is high and low pulse 
uint8_t currentpulse = 0; // index for pulses we're storing

#include "ircodes.h"
void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}


  void loop(void) {
    
  int numberpulses;
   Serial.println("press a button to capture");
  numberpulses = listenForIR();
 
  Serial.print("Heard ");
  Serial.print(numberpulses);
  Serial.println("-pulse long IR signal");
printpulses(); 
    Serial.println();
    Serial.println("If you want to continue, press a button, if not, quit");
  
}

void printpulses(void) {
  
  // print it in a 'array' format
  Serial.println("int IRsignal[] = {");
  Serial.println("// ON, OFF (in microseconds)");
  for (uint8_t i = 0; i < currentpulse-1; i++) {
    Serial.print("\t"); // tab
    Serial.print(pulses[i][1] * RESOLUTION , DEC);
    Serial.print(", ");
    Serial.print(pulses[i+1][0] * RESOLUTION , DEC);
    Serial.println(",");
  }
  Serial.print("\t"); // tab
  Serial.print(pulses[currentpulse-1][1] * RESOLUTION, DEC);
  Serial.print(", 0};");
}
int listenForIR(void) {
  currentpulse = 0;
 
  while (1) {
    uint16_t highpulse, lowpulse;  // temporary storage timing
    highpulse = lowpulse = 0; // start out with no pulse length
 
//  while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
       // pin is still HIGH
 
       // count off another few microseconds
       highpulse++;
       delayMicroseconds(RESOLUTION);
 
       // If the pulse is too long, we 'timed out' - either nothing
       // was received or the code is finished, so print what
       // we've grabbed so far, and then reset
       if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
         return currentpulse;
       }
    }
    // we didn't time out so lets stash the reading
    pulses[currentpulse][0] = highpulse;
 
    // same as above
    while (! (IRpin_PIN & _BV(IRpin))) {
       // pin is still LOW
       lowpulse++;
       delayMicroseconds(RESOLUTION);
       if ((lowpulse >= MAXPULSE)  && (currentpulse != 0)) {
         return currentpulse;
       }
    }
    pulses[currentpulse][1] = lowpulse;
 
    // we read one high-low pulse successfully, continue!
    currentpulse++;
  }
}
Once you get the learned signal, put it in the 'H' file as below.

Code: Select all

int sharpon[]={
      320, 1740,
	320, 720,
	320, 720,
	320, 720,
	320, 720,
	320, 720,
	320, 1740,
	320, 1740,
	320, 720,
	320, 1740,
	320, 720,
	320, 720,
	320, 720,
	320, 1740,
	320, 720,
	320, 45320,
	320, 1740,
	320, 720,
	320, 720,
	320, 720,
	320, 720,
	320, 1740,
	320, 720,
	320, 720,
	320, 1740,
	320, 720,
	320, 1740,
	320, 1740,
	320, 1740,
	320, 720,
	320, 1740,
	320, 43240,
	320, 1740,
	320, 720,
	320, 720,
	320, 720,
	320, 720,
	320, 720,
	320, 1740,
	320, 1740,
	320, 720,
	320, 1740,
	320, 720,
	320, 720,
	320, 720,
	320, 1740,
	320, 720,
	320, 45740,
      320, 1740,
     320, 720,
      320, 720,
     320, 720,
     320, 720,
     320, 1740,
     320, 720,
     320, 720,
      320, 1740,
    320, 720,
     320, 1740,
    320, 1740,
    320, 1740,
    320, 720,
    320, 1740,
    320, 0};
Next one is to utilize the above signal into you sketch.

Code: Select all

// This sketch will transmit IR signal which capture from 'sharpircode.h'
// it is working code by 14 Oct 12

#include "sharpircode.h"

const int IRledPin =  12;    // LED connected to digital pin 13

#define IRpin_PIN  PIND
#define IRpin      7 // IR receiver input pin
#define MAXPULSE 65000
#define RESOLUTION 20
uint8_t currentpulse=0; //index for pulse we're storing
uint16_t pulses[100][2]; // pair is high and low pulse

 
// The setup() method runs once, when the sketch starts
 
void setup()   {                
 
  // initialize the IR digital pin as an output:
  pinMode(IRledPin, OUTPUT);  
pinMode(13,OUTPUT);  
  
  Serial.begin(9600);
  Wire.begin();
}
 
void loop()                     
{
     if (write your argument here'){
  SendTvOn();
  digitalWrite(13,HIGH);
  delay(1000);
  digitalWrite(13,LOW);
  
     }

//------------------Transmitting IR signal------------------- 
// This procedure sends a 38KHz pulse to the IRledPin 
// for a certain # of microseconds. We'll use this whenever we need to send codes
//void pulseIR(long microsecs) {
void pulseIR(int microsecs) {
  // we'll count down from the number of microseconds we are told to wait
 
  cli();  // this turns off any background interrupts
 
  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds
   digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds
 
   // so 26 microseconds altogether
   microsecs -= 26;
  }
 
  sei();  // this turns them back on
}
//--------------------Button assignment--------------------
void SendTvOn() {
  // This is the code for Sharp TV, for others, use the tutorial
  
   for(int i=0; i<100 ; i++){
     //below code has been modified, see the original code in web site
     pulseIR(sharpon[i*2+0]);// read from learned code
     delayMicroseconds(sharpon[i*2+1]);
   }
}

I am sure you know how to attach 'H' file into your above sketch.
Good luck for your project.

WN
Last edited by adafruit_support_rick on Sun Oct 21, 2012 2:27 pm, edited 1 time in total.
Reason: edited to use code tags

Dariusrussell
 
Posts: 3
Joined: Sat Sep 29, 2012 5:06 pm

Re: IR Remote Reading Help

Post by Dariusrussell »

Thanks so much, and try emailing your way to Adafruit they might just update the tutorial once they're moved in!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”