Pages: [1]   Go Down
Author Topic: Importing an IR protocol in IRremote library  (Read 2432 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
#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:
#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);
}

« Last Edit: October 01, 2012, 04:23:12 pm by vams » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8854
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Maine
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

* samsungIRRemote.ino (1.43 KB - downloaded 34 times.)
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8854
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Maine
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. 
Logged

Maine
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

* samsungIRRemote.ino (2.66 KB - downloaded 67 times.)
Logged

Pages: [1]   Go Up
Jump to: