PDA

View Full Version : IRremote lib on Teensy 3.0



ghost
01-07-2013, 06:02 PM
Hello everyone,

I'm trying to get the IRremote library to work on a teensy 3.0, but the examples provided with that library will not compile using Teensy 3.0 Beta 9/10 Software.
Neither Paul Stoffregen's version (http://www.pjrc.com/teensy/td_libs_IRremote.html), nor newer versions from Ken Shirriff's github (https://github.com/shirriff/Arduino-IRremote) work. I just get an error like this (trying to compile the IRrecord example):


/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRsend::mark(int)':
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:174: error: 'TCCR2A' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:174: error: 'COM2B1' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRsend::space(int)':
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:182: error: 'TCCR2A' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:182: error: 'COM2B1' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRsend::enableIROut(int)':
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:200: error: 'TIMSK2' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:210: error: 'TCCR2A' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:210: error: 'WGM20' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:210: error: 'TCCR2B' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:210: error: 'WGM22' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:210: error: 'CS20' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:210: error: 'OCR2A' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:210: error: 'OCR2B' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:226: error: 'TCCR2A' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:226: error: 'WGM21' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:226: error: 'TCCR2B' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:226: error: 'CS21' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:226: error: 'OCR2A' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:226: error: 'TCNT2' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:229: error: 'TIMSK2' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:229: error: 'OCIE2A' was not declared in this scope
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp: At global scope:
/home/ghost/sketchbook/libraries/IRremote/IRremote.cpp:258: error: expected constructor, destructor, or type conversion before '(' token

When I try the same example on an Arduino Duemilanove (ATmega328) using Arduino IDE 1.03 everything works as expected.

I'm pretty new to this whole microcontroller programming thing and whilst having done some simple projects on Arduino, I don't pretend to fully grasp what's going on behind the scenes of the Arduino IDE and what requirements have to be satisfied for a given program sketch to be ported from arduino to teensy 3 successfully. That being said, my guess here is that the IRremote library lacks a teensy 3.0 compatible "interrupt routine" (?) as is given for other *duino boards in the file IRremoteInt.h

If someone more knowledgeable could point me in the right direction and elaborate a little on what would have to be done to port the IRremote library to teensy 3, that would really be much appreciated. Thank you!

t3andy
01-07-2013, 06:34 PM
There are really two types used for the IR Remote.
The "pulse-in" which waits for the IR train of pulses and the interrupt driven.

Here is the Sparkfun "pulse-in" code snippet I got to work on the Teensy 2 and should work on the Teensy 3?


/*
SparkFun Electronics 2010
Playing with IR remote control

IR Receiver TSOP382: Supply voltage of 2.5V to 5.5V
With the curved front facing you, pin 1 is on the left.
Attach
Pin 1: To pin 2 on Arduino
Pin 2: GND
Pin 3: 5V

This is based on pmalmsten's code found on the Arduino forum from 2007:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434/0

This code works with super cheapo remotes. If you want to look at the individual timing
of the bits, use this code:
http://www.arduino.cc/playground/Code/InfraredReceivers

This code clips a lot of the incoming IR blips, but what is left is identifiable as key codes.

*/

int irPin = 5; //Sensor pin 1 wired to Arduino's pin 2
int statLED = 11; //Toggle the status LED every time Power is pressed
int start_bit = 2200; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)

void setup() {
pinMode(statLED, OUTPUT);
digitalWrite(statLED, LOW);
pinMode(irPin, INPUT);
Serial.begin(9600);
Serial.println("Waiting: ");
}

void loop() {
int key = getIRKey(); //Fetch the key

if(key != 0) //Ignore keys that are zero
{
Serial.print("Key Recieved: ");
switch(key)
{
case 144: Serial.print("CH Up"); break;
case 145: Serial.print("CH Down"); break;
case 146: Serial.print("VOL Right"); break;
case 147: Serial.print("VOL Left"); break;
case 148: Serial.print("Mute"); break;
case 165: Serial.print("AV/TV"); break;
case 149:
Serial.print("Power");
if(digitalRead(statLED) != 1) //This toggles the statLED every time power button is hit
digitalWrite(statLED, HIGH);
else
digitalWrite(statLED, LOW);
break;

default: Serial.print(key);
}

Serial.println();
}
}

int getIRKey() {
int data[12];
int i;

while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit

for(i = 0 ; i < 11 ; i++)
data[i] = pulseIn(irPin, LOW); //Start measuring bits, I only want low pulses

for(i = 0 ; i < 11 ; i++) //Parse them
{
if(data[i] > bin_1) //is it a 1?
data[i] = 1;
else if(data[i] > bin_0) //is it a 0?
data[i] = 0;
else
return -1; //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
}

int result = 0;
for(i = 0 ; i < 11 ; i++) //Convert data bits to integer
if(data[i] == 1) result |= (1<<i);

return result; //Return key number
}




From the looks of your compiler errors, timers and interrupts are trying to be re-mapped from the Arduino to the "different" ARM Teensy 3.
I believe Paul S. is still working on the interrupts for the Teensy 3.?

PaulStoffregen
01-20-2013, 03:11 PM
IRremote is now ported to Teensy 3.0

http://www.pjrc.com/teensy/td_libs_IRremote.html

nyarlathotep
05-04-2013, 10:27 AM
There is an explanation of wiring up IR remote controllers for beginners at arduino-info.wikispaces.com/IR-RemoteControl (http://arduino-info.wikispaces.com/IR-RemoteControl), which suggests wiring the output pin directly into the Arduino/Teensy pin.

My VS1838B (Chinese) (http://www.hyzt.com/manager/upimg/200987165540.pdf) likes 2.7-5.5V. So presumably this works fine if the VS1838B's VCC is wired to the Teensy's 3.3V pin. It came with a couple 10k ohm resistors though. Also, it's datasheet showed wiring up a 20k ohm resistor between it's VCC and OUT, along with a capacitor between VCC and GND and other things. The similar AX-1838HS datasheet (http://arduino-info.wikispaces.com/file/view/IR-Receiver-AX-1838HS.pdf) has almost the same diagram.

If I understand the internal wiring diagram though, these 1838 units resemble an open collector output device, except that they have an internal pull-up resistor to VCC. So OUT either connects directly to GND or pulls-up to VCC through the internal resistor, which works fine for the Teensy. Is this application diagram in the datasheet simply describing how one achieves specific line voltages different from VCC and GND on OUT or something?

nyarlathotep
05-04-2013, 05:42 PM
Alright, it works fine with no resistors used. So my only question now is : Would using some additional small resistor somewhere conserve power and/or let me power more stuff of the Teensy's 3.3 V pin? I guess the answer is yes, but probably not enough to worry about.

As the IRremote library page (http://www.pjrc.com/teensy/td_libs_IRremote.html) suggests documenting them, I'll mention that the IR Remote kit I'm using is here (http://dx.com/p/ir-remote-control-diy-kit-for-arduino-1-x-cr2025-136284) and I'll document the button codes below, oh it reports as NEC. Also, the one review there points to another discussion here (http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10696&start=45)

1x1 Power 0xFFA25D
1x2 Mode 0xFF629D
1x3 Mute 0xFFE21D

2x1 PlayPause 0xFF22DD
2x1 Reverse 0xFF02FD
2x3 Forward 0xFFC23D

3x1 Eq 0xFFE01F
3x2 Minus 0xFFA857
3x3 Plus 0xFF906F

4x1 Zero 0xFF6897
4x2 Shuffle 0xFF9867
4x3 UvSD 0xFFB04F

5x1 One 0xFF30CF
5x2 Two 0xFF18E7
5x3 Three 0xFF7A85

6x1 Four 0xFF10EF
6x2 Five 0xFF38C7
6x3 Six 0xFF5AA5

7x1 Seven 0xFF42BD
7x2 Eight 0xFF4AB5
7x3 Nine 0xFF52AD

Button held 0xFFFFFFFF

PaulStoffregen
05-04-2013, 06:04 PM
So my only question now is : Would using some additional small resistor somewhere conserve power and/or let me power more stuff of the Teensy's 3.3 V pin?

It's hard to imagine how that could help.

Can you see how impossible this question is to answer if you do not post a schematic of the proposed circuit and a link to the datasheet for this particular IR receiver?

Some IR modules recommend a low value resistor in series with the power line, and a large capacitor like 10uF or more from Vcc to GND located physically close to the module. The purpose is to filter out noise that may be present on the power line from other circuitry before it does to the sensitive analog amplifier and filters inside the module. Maybe you're seeing that circuit on the datasheet or an application note?

nyarlathotep
05-04-2013, 06:43 PM
Yup, that likely explains what they've put on both datasheets, thanks! I'll try the datasheet's recommended layout if I encounter any difficulties.

stevech
04-14-2014, 05:58 PM
My experience with IR receiver/detectors like the one being discussed:
You need really clean 3.3V power for it. I used about 100 ohms between the detector's Vin and the 3.3V bus. And a goodly bypass capacitor right on the detector's Vin and GND pins.
The detector needs a tiny amount of current from the 3.3 source.
The output is open collector, usually, so a 10K pullup is fine.
The detector has a rather high gain amplifier with a narrow-band filter front end - tuned to the IR modulation frequency. A few remotes for odd Audio/Visual use a non-standard frequency.