I See In Infared


[ Previous posts on this subject are here, here, and here. ]

Installing LIRC on the Pi was a snap, but took about 30 minutes as there was an update to Raspian that needed to be downloaded.

I removed the IR receiver from the LED light’s circuit board, wired it to the Pi, followed the instructions for setting up a new receiver and remote, and pressed all the buttons asked of me by irrecord.

My /etc/lirc/lircd.conf file for the APA 1616 remote ended up looking like:

begin remote
name apa1616
 bits 16
 flags SPACE_ENC|CONST_LENGTH
 eps 30
 aeps 100
header 8953 4467
 one 563 1671
 zero 563 555
 ptrail 567
 repeat 8958 2226
 pre_data_bits 16
 pre_data 0xF7
 gap 107360
begin codes
 KEY_VOLUMEUP 0x00FF
 KEY_VOLUMEDOWN 0x807F
 KEY_POWER 0x40BF
 KEY_POWER2 0xC03F
 KEY_A 0x20DF
 KEY_B 0xA05F
 KEY_C 0x609F
 KEY_D 0xE01F
 KEY_E 0x10EF
 KEY_F 0x906F
 KEY_G 0x50AF
 KEY_H 0xD02F
 KEY_I 0x30CF
 KEY_J 0xB04F
 KEY_K 0x708F
 KEY_L 0xF00F
 KEY_M 0x08F7
 KEY_N 0x8877
 KEY_O 0x48B7
 KEY_P 0xC837
 KEY_Q 0x28D7
 KEY_R 0xA857
 KEY_S 0x6897
 KEY_T 0xE817
 end codes
end remote

After irrecord was finished, I hit keys on the remote while at the console, and letters would appear.   This is because I named the buttons KEY_A, etc.   I didn’t have to run a command to see that I was receiving IR, which was nice.

So, now that I know what the codes are, I should be able to send them to the light using LIRC’s irsend command and have it change color, right?   I tried just that.

Nothing.

Nada.

Damnit!

Okay, time to get out the oscilloscope and see what the IR receiver sends, and what the Pi sends, and make them match.   The top is the output of the IR receiver, and what we want our signal to look like.  The bottom is what the Pi is doing with its output pin.

photo  photo 1 (5)

As you’ve probably noticed, the signals are very different.   The IR receiver starts at 5V, gets pulled down to 0V for some period of time, and then is returned to 5V.   The GPIO pin starts at 0V, rises to 3.3V, but rather than staying there, oscillates at some frequency for a period of time.  Zooming in on one of the pulses, we see this:

photo 2 (5)

It turns out that these waveforms correspond to a 38KHz carrier frequency that is is a part of the IR communications spec.   The IR receiver hardware filters out the carrier.  Since that’s the signal the light expects, we need to get Linux to do the same for us.

Changing the signal from active low to active high, and from 3.3V to 5V is fairly straightforward.   We just need an NPN transistor.   We’ll use the 3.3V GPIO output to drive the base, and put 5V across the collector and emitter.  The output to our light gets wired in between the transistor and the 10kOhm resistor.

I discovered an educational program (Yenka) recently that lets you simulate simple circuits, and it’s free for non-commercial home use.   I used it to build and test my circuit, and highly recommend it for the novice circuit designer.

Transistor-Open

This diagram shows that with the transistor input (base) at 0V, there is 5V across the collector and emitter.

Transistor-Closed

And with voltage (3.3V in reality; 5V in the simulation) applied to the base, there are nearly 0V across the collector and emitter. This corresponds to inverting the output, and changing from a 3v3 signal to 5V.

This is all great, but what about eliminating the 38KHz carrier?

I got all psyched up to go modify the RPi GPIO driver for LIRC when I noticed that the existing driver had an option that can be changed at load-time.

softcarrier=0

Bless the author of that module.  I don’t have to change any code in order to turn it off.   So I made my /etc/modules file look like:

lirc_dev
lirc_rpi gpio_in_pin=14 gpio_out_pin=17 softcarrier=0

And I was off to the races.  By issuing commands on the Pi, I am now able to simulate remote control button presses, and control the light through software.

irsend SEND_ONCE apa1616 KEY_D

It doesn’t switch colors as fast as I’d like, but I can live with it.

Next: getting the IR filter off the Pi’s camera module without destroying it.

Advertisements

4 thoughts on “I See In Infared

  1. I be very interested on how you get on with your project… keep blogging away 😀 … btw you may already know you can buy a raspberry pi camera board without the infrared filter.. search for pi noir … save you the hard work while not destroying your precious thief-cam 😉

  2. Unfortunately, I’ve not had time to pick this project back up for a couple of months.

    I have a new Pi camera module (the first was destroyed while removing the IR filter) and a stereo microscope so that I can have a reasonable chance of success this time around. I also have a PIR sensor, but haven’t decided what sort of housing to put everything in.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s