Go Down

Topic: Importing an IR protocol in IRremote library (Read 2804 times) previous topic - next topic

vams

Oct 01, 2012, 08:14 pm Last Edit: Oct 01, 2012, 11:23 pm by vams Reason: 1
Hi fellow arduinians,

I need to build a remote IR controller for my TV.

I've searched and founded for the protocol:
http://lirc.sourceforge.net/remotes/samsung/AA59-00382A

I included it in the IRremote library, loaded in arduino aaaand it doesn't work.
I know there a billions of reason why it doesn't and I'd like to narrow the options.
Below there's my implementation of the protocol I found, could you please let me know if it is correct?
In particular I have no idea of what "toggle_bit_mask" means, nor what the gap is, since there is no minimum repeat value indicated.
Thanks in advance:

send function :

Code: [Select]
void IRsend::sendSamsung(unsigned long data, int nbits,int repeat){
 enableIROut(40);
 if (repeat == 0) {
 mark(SAMSUNG_HDR_MARK);
 space(SAMSUNG_HDR_SPACE);
 }
 //Invio il pre_data 0xE0E0 del protocollo http://lirc.sourceforge.net/remotes/samsung/AA59-00382A
 unsigned long pre_data = 0xE0E0;
 pre_data <<= 16;
 for (int i = 0; i < 16; i++) {
   if (pre_data & TOPBIT) {
     mark(SAMSUNG_ONE_MARK);
     space(SAMSUNG_ONE_SPACE);
   }
   else {
     mark(SAMSUNG_ONE_MARK);
     space(SAMSUNG_ZERO_SPACE);
   }
   pre_data <<= 1;
 }
 //Ora trasmetto il mio segnale
 data = data << (32-nbits);
 for (int i = 0; i < 16; i++) {
   if (data & TOPBIT) {
     mark(SAMSUNG_ONE_MARK);
     space(SAMSUNG_ONE_SPACE);
   }
   else {
     mark(SAMSUNG_ONE_MARK);
     space(SAMSUNG_ZERO_SPACE);
   }
   data <<= 1;
 }
 //aggiungo il trail
 mark(SAMSUNG_PTRAIL);
}


mark-space times :
Code: [Select]

#define SAMSUNG_HDR_MARK 4764
#define SAMSUNG_HDR_SPACE 4703
#define SAMSUNG_ONE_MARK 573
#define SAMSUNG_ONE_SPACE 1663
#define SAMSUNG_ZERO_SPACE 534
#define SAMSUNG_PTRAIL 556
#define SAMSUNG_GAP 48962


and finally the sketch :

Code: [Select]
#include <IRremote.h>

IRsend irsend;

void setup()
{
 Serial.begin(9600);
 pinMode(13,OUTPUT);
}

void loop() {
 digitalWrite(13,HIGH);
 for(int i=0;i<3;i++) {
 irsend.sendSamsung(0x20DF, 16,i); // Sony TV power code
 delay(45);
 }
 digitalWrite(13,LOW);
 delay(500);
}



johnwasser

Code: [Select]

  int pre_data = 0xE0E0;
  pre_data <<= 16;


If you take a 16-bit integer and shift it left 16 bits the results will be 0.  Probably not what you wanted.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

vams

thanks, that has been modified, now is "unsigned long" instead of "int"

vams

Ok, I managed to get this things work.
I post here the solution in case someone had to do the same thing:

It was wrong to not send the header when repeating the signal, so the code now is :
Code: [Select]
void IRsend::sendSamsung(unsigned long data, int nbits,int repeat){
  enableIROut(38);

  mark(SAMSUNG_HDR_MARK);
  space(SAMSUNG_HDR_SPACE);
  //Invio il pre_data 0xE0E0 del protocollo http://lirc.sourceforge.net/remotes/samsung/AA59-00382A
  unsigned long pre_data = 0xE0E0;
  pre_data <<= 16;
  for (int i = 0; i < 16; i++) {
    if (pre_data & TOPBIT) {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ONE_SPACE);
    }
    else {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ZERO_SPACE);
    }
    pre_data <<= 1;
  }
  //Ora trasmetto il mio segnale
  data = data << (32-nbits);
  for (int i = 0; i < 16; i++) {
    if (data & TOPBIT) {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ONE_SPACE);
    }
    else {
      mark(SAMSUNG_ONE_MARK);
      space(SAMSUNG_ZERO_SPACE);
    }
    data <<= 1;
  }
  //aggiungo il trail
  mark(SAMSUNG_PTRAIL);
  space(48962);  //gap
}


note that i moved the gap here from the sketch.

It was a pointbreak find this legend to read lirc files : http://winlirc.sourceforge.net/technicaldetails.html
And I suggest also reading the blog of the library's creator, just google IRremote library and you should find him.

If I may help someone with this kind of project let me know, and thanks to johnwasser for finding that mistake

philG

I would like to try this out on my Samsung.  I created a sketch from this code and get a compilation error.  "no void IRsend::sendSamsung(unsigned int, int ,int ) member function declared in iRsend".  Is there a special place that function should reside?

johnwasser


I would like to try this out on my Samsung.  I created a sketch from this code and get a compilation error.  "no void IRsend::sendSamsung(unsigned int, int ,int ) member function declared in iRsend".  Is there a special place that function should reside?


You have to add it to the IRremote library, in both IRremote.h and  IRremote.cpp.  You might as well add it to keywords.txt, too.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

philG

Oh, right.  I have it compiling now. I think the code assumes  that the LED will be driven directly off the pin.  I plan to use an NPN driver so I will have to invert the output.  I'm not sure is that can be done easily in the PWM setup.  Thanks for the help John. 

philG

OK, this works fine.   I was not sure why there was a loop around the send command since there is a repeat count parameter.  I added defines for all the useful commands and built a sequence of commands that turns on the TV and sets the source to the DTV STB.

I am wondering why I can't find the hex codes for the DTV RC65 remote anywhere.  Is there some legal issue?

Go Up