IR capture device

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
User avatar
caitsith2
 
Posts: 217
Joined: Thu Jan 18, 2007 11:21 pm

IR capture device

Post by caitsith2 »

Finally built a IR remote capture device. Most specifically, the IR Widget

IR widget from top side
Image


And from bottom side
Image


I hit that one little snag, when I finally got my PCB. THe holes, where the QSE157 was supposed to go, were too small. I did work around the issue though, by surface mounting it. (2 pins on top side, 1 on bottom.) (If I order another of the PCB, I will make sure to correct that error first.)


Also, Just before I got that PCB and put it together, I made an Arduino Diecimila version. Despite the C code written, because I know how to use an AVR simulator to trace things, the timing is exactly 100 microseconds between each byte sent.

Code: Select all

#define tx_port PORTD
#define tx_bit 1
#define mode1_port PINB
#define mode1_bit 7
#define mode2_port PINB
#define mode2_bit 5
#define status_led_port PORTB
#define status_led_bit 0
#define ir_demod_port PIND
#define ir_demod_pin 2

void setup()
{
  DDRB = B01011111;
  PORTB = B00000000;
  DDRD = B00101010;
  PORTD = B00110000;
  TCCR0A = 0;
  TCCR0B = (1<<CS02)|(1<<CS01);
  TCCR1A = 0;
  TCCR1C = 0;
  TCCR1B = (1<<CS11)|(1<<CS10);
  Serial.begin(115200);
}

uint16_t time_save;

void report_time(int period)
{
  uint16_t temp = TCNT1L | (TCNT1H << 8);
  temp-=time_save;
  time_save+=temp;
  temp>>=1;
  temp|=period;
  //Serial.print(temp&0xFF,BYTE);
  //Serial.print(temp>>8,BYTE);
  Serial.println(temp,DEC);
}

void loop()
{
  int tx_data;
  int prev_count;
  int temp;
 // cli();
  while(Serial.available()==0);  //Wait for host to decide what mode to execute.
  temp = Serial.read();
  if((temp==0)||(temp=='0'))
  {
    while(1)    //Count Mode
    {
      while(Serial.available()==0);
        Serial.read();
      cli();
      //Count_First
      tx_data = TCNT0;
      do
      {
        temp = TCNT0;
      } 
      while (temp==tx_data);
      digitalWrite(8,HIGH);
      //do
      while(1) {
        //cli();
        prev_count = tx_data;
        Serial.print(tx_data,BYTE);
        //delayMicroseconds(100);
        delayMicroseconds(93);    //Make this loop exactly 100 microseconds.
        __asm__ __volatile__ ( 
        "nop\n\t"  //When I traced, the loop was exactly 99.5 microseconds.
        "nop\n\t"  //7 nops, to make the loop 99.9375 microseconds long.
        "nop\n\t"
        "nop\n\t"
        "nop\n\t"
        "nop\n\t"
        "nop\n\t"
      );
        tx_data = TCNT0;
        if(tx_data==prev_count)
        {
          __asm__ __volatile__ (
          "nop\n\t"  //And this nop makes the loop 100 microseconds long,
                         //when there is no change in counts.
      );
          digitalWrite(8,LOW);
        }
        else  
        {              //The branch to here makes 100 microseconds
                       //when the count has changed.
          digitalWrite(8,HIGH);
        }
          
        //sei();
      }// while(Serial.available()==0);
      Serial.read();
    }
  }
  else    //Time mode
  {
    while(1)
    {
       while(digitalRead(4));
       report_time(0x0000);
       digitalWrite(8,HIGH);
       while(!digitalRead(4));
       report_time(0x8000);
       digitalWrite(8,LOW);
    }    
  }

}
Arduino IR capture device on Right
Image

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

Return to “TV-B-Gone Kit”