Society of Robots - Robot Forum

Software => Software => Topic started by: Mad MIR on September 30, 2011, 05:21:13 AM

Title: Code needs slight mod but I have no idea how to mod it
Post by: Mad MIR on September 30, 2011, 05:21:13 AM
//NOTE: THIS HAS BEEN ON THE ADAFRUIT FORUM FOR 2 WEEKS NOW AND I DIDNT GET A SINGLE REPLY, I'LL JUST COPY PASTE IT HERE

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 (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 (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 (http://html.alldatasheet.com/html-pdf/2) ... SOP11.html



The code (from the link above):
Code: [Select]
    /* 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 [url=http://www.ladyada.net]www.ladyada.net[/url] 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.
Title: Re: Code needs slight mod but I have no idea how to mod it
Post by: joe61 on September 30, 2011, 07:31:02 AM
//NOTE: THIS HAS BEEN ON THE ADAFRUIT FORUM FOR 2 WEEKS NOW AND I DIDNT GET A SINGLE REPLY, I'LL JUST COPY PASTE IT HERE
That might be because about 30 seconds of googling would have gotten you this: http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html (http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html)

If that doesn't give you what you want, try rephrasing the question.

Joe
Title: Re: Code needs slight mod but I have no idea how to mod it
Post by: Mad MIR on October 01, 2011, 07:47:01 AM
Im really sorry I didnt know that there were libraries for this kind of stuff,
Thanks!