Sparkfun: IR Receiver Breakout Board
Overview: 2 Wiring: 2 Code: 1, Could stil use some step by step instructions. git: 2 Demo: 2 Total: 9/10 Comments: Thanks for all the work you put into this. It turned into a bigger project than most.
Carrier Frequency: 38kHz
The picture on the left shows the physical device. This IR Receiver receives an modulated IR signal and reacts accordingly. It has filters built in to eliminate interference from ambient light, and it will not react to just any IR signal sent to it. This device needs an IR signal that is modulated as a 38kHz square wave. When it receives a modulated IR signal, it outputs a low signal. Otherwise, it outputs a high signal.
The Picture below the one on the left shows the bottom of the IR Receiver. The Receiver needs an external VDD source to power it. This VDD can be varied from 2.5V-5.5V as seen above. The middle pin is the output, and it can be read by a device such as a BeagleBone. Additionally the circuit diagram of the TSOP85338 is available below.
Sending a Signal
The TSOP85338 operates with a carrier frequency of 38kHz. That is, when the IR sensor is receiving an IR signal that is being modulated at 38kHz it outputs a logic 0. To test this operation, I hooked up an IR LED to a function generator set to a 38kHz square wave. The function generator created the carrier frequency required to the receiver to recognize it. I hooked up the VDD pin of the IR Receiver to a 5 volt source limited to 100 mA, and i hooked up the output pin to an oscilloscope. When the function generator's output was turned on, the IR Receiver's output went low, and when it was shut off again, the output value went high.
Next, the same sort of experiment was performed using a BeagleBone. The BeagleBone's built in PWM outputs can be set to act the same as the 38kHz square wave created by the function generator. How to set this up will be detailed below. The same IR LED was then hooked up to the BeagleBone's PWM output, and the PWM was set to run with a frequency of 38kHz and duty cycle of 50%. This also caused the output on the oscilloscope to read a zero when turned on.
To set up and use the PWM, I used ehrpwm1:0, which is located on pin 6 of mux gpmc_a2. gpmc_a2 is located on pin 14 of the BeagleBone, and has pin 7 of the mux enabled by default. To change the enabled pin of gpmc_a2 you must change the value stored in the file /sys/kernel/debug/omap_mux/gpmc_a2 on the BeagleBone from 7 to 6. The directory /sys/kernel/debug/omap_mux contains all of the muxes on the BeagleBone, and any one of them can be changed by writing into their respective files.
Once ehrpwm1:0 is enabled on pin 14, its frequency and duty cycle must be set. By writing 38000 into /sys/class/pwm/ehrpwm1:0/duty_freq, we can set the frequency to 38kHz, and by writing 50 into /sys/class/pwm/ehrpwm1:0/duty_cycle, we can set the duty cycle to 50%. This will result in a 38kHz squarewave on the output when /sys/class/pwm/ehrpwm1:0/run is set to 1.
Note that once a duty_cycle is set, /sys/class/pwm/ehrpwm1:0/duty_ns should be set to 0 to change the duty_freq
Reading Using Interrupts and GPIO
Receiving a signal from the TSOP85338 can be done on the BeagleBone using its gpio pins. In order to do this, the bitrate must be known initially or measured somehow. Once the bitrate is known, you can write a program that waits until an interrupt is received on a particular gpio pin that triggers on "both" edges. Essentially this will wait for the output of the TSOP85338 to change states. After it triggers, you can read the data received at intervals that match the bitrate until the message is received. This can be done for a set number of bits or until a terminating sequence occurs (user defined). Ex) if transmitting 8-bit char values, you can wait for a \0 ascii character to know that the message has been received.
If working in C, poll.h has some nice tools that can be used to create your interrupts.
This is not the best method to read the sensor with as the Operating System can get in the way of reading exactly on time
using UART or the PRU (Programmable Real-Time Unit) would prove much more efficient.
These following diagram shows how to wire the BeagleBone to reproduce my testing procedure.
Testing and Results
All measurements and tests were performed using a 5V source
To test the operation of this device, I wrote a test script for the BeagleBone that repeatedly transmits an ascii 'c' char to the IR Receiver. My code used all of the setup described above to setup a 38kHz square wave on ehrpwm1:0. I used a bitrate of 1kHz to transmit, meaning that every 1ms I toggled the PWM either on or off depending on the next bit of the 'c' I was transmitting. This involved using a usleep(1000) to wait 1ms between toggles. With an 8-bit char, that gives a character transmit rate of 125Hz (1kHz/8bits = 125Hz). While that is not particularly fast this rate allowed for accurate testing of the rise time for this device, which as can be seen in the figure below was measured on an oscilloscope to be 225us. By the measured rise time value, the maximum bit rate is around 4.4kHz.
The code used to perform this testing is available on github.com. Use the following to download it.
The above figure is the measurement taken of the TSOP38553's rise time.
In the above figure, The input to the TSOP38553 is in the red box below. It is shifting a 'c' or 0b01100011. The top section in green is the output.
DataSheet & Schematic: TSOP85338 Page on Sparkfun.com
Consumer IR: Wikipedia page on CIR