IR receiver code mod

Get help and show off your TV-B-Gone kit!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
MAD_mir
 
Posts: 4
Joined: Sat Sep 03, 2011 9:32 am

IR receiver code mod

Post by MAD_mir »

Hey guys, I need some help modding a short piece of code to read data from my IR receiver, i'm sure there's a very simple solution to this
thank you for reading.

I wanted to make my own TV b gone and decided to go through the tutorial (found here: http://www.ladyada.net/learn/sensors/ir ... r_commands ) first. The arduino does not pick up the signals from my IR receiver for some reason and I think the problem lies in the fact that i'm using a different IR receiver than the one in the tutorial.

Some info:
- part number on it reads: TK19 044 and TSOP 1176
- It looks like http://thinklabs.in/shop/images/tsop.jpg
- its from an old lego RCX
- 76 kHz carrier frequency ( is used by RCX)
- I found the data sheet for a very similar number (TSOP 11) but im not sure if it is for the same part, here it is: http://html.alldatasheet.com/html-pdf/2 ... SOP11.html



The code (from the link above):

Code: Select all

/* Raw IR decoder sketch!
 
 This sketch/program uses the Arduno and a PNA4602 to 
 decode IR received. This can be used to make a IR receiver
 (by looking for a particular code)
 or transmitter (by pulsing an IR LED at ~38KHz for the
 durations detected 
 
 Code is public domain, check out www.ladyada.net and adafruit.com
 for more tutorials! 
 */
 
// 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          2
 
// 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 
 
// 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
 
void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}
 
void loop(void) {
  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)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  // 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)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  pulses[currentpulse][1] = lowpulse;
 
  // we read one high-low pulse successfully, continue!
  currentpulse++;
}
 
void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
  }
}
-

I guess im going to have to mod the code but im new to the language and really have no idea how to! Can someone please help me!

Thanking you in advance, MAD_mir.

User avatar
mkanoap
 
Posts: 19
Joined: Tue Sep 16, 2008 4:01 pm

Re: IR receiver code mod

Post by mkanoap »

Assuming that datasheet is appropriate for that part, the pin outs are different than the one in the ladyada tutorial.

Adafruit:
pin1 - out
pin2 - gnd
pin3 - vcc

Your part:
pin1 - gnd
pin2 - vcc
pin3 - out

Try rewiring your circuit to change the pins around to match. i.e. move the wire for pin1 to pin 3, the wire for pin2 to pin 1, and the wire for pin 3 to pin 2.

The sample circuit in the datasheet also recommends a 100 ohm resistor instead of the 200-1000 ohm's mentioned in the tutorial, but I don't know how important that is.

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

Return to “TV-B-Gone Kit”