Teensy 4.0 + IRremote Library

Status
Not open for further replies.

cwynd

New member
Hello everyone,
I'm having trouble with IRsend and a Teensy 4.0. I should mention that this is my first dive into Teensy (although I have done a fair bit of Arduino and other), but I am probably doing something silly here. I had no trouble duplicating the IRrecv example program, and for example grabbed codes from 4 or 5 remotes I am hoping to replace. But I'm stuck trying to get IRsend working.
Here's details on where I've got to/what I've done so far.

* I'm using the Example Program Transmit code but with the send command:
Code:
irsend.sendNEC(0x2FD48B7, 32);
-This is a code and type (NEC) that I read from one of my existing remotes (TV on|off)
-'32' is my figuring from the other numbits examples I could find (could be wrong).

* From my reading of hardware/teensy/avr/libraries/IRremote/boarddefs.h I'm using pin 7:
Code:
// Teensy 4
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
  #define IR_USE_TIMER_FLEXPWM1 // tx = pin 7
-and I have a Wurth LED IR 940NM (#15400594A3590) being fed about 35mA via a simple MOSFET driver and pin 7.

* If I comment the IRsend code, and send a simple 1 sec square wave out of pin 7:
Code:
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  delay(1000);
  digitalWrite(7, LOW);
  delay(1000);
I can see this on a logic analyzer, and my phone camera can see the IR LED flashing - so I believe my hardware set up is working sensibly thus far. But unfortunately switching back to the example IRsend code, my phone camera does not see the LED blink, I cannot find any signal with a basic logic analyzer, and it does not work if I hold it close to the TV receiver 'eye'.

I can imagine several things I might be wrong about, and would hugely appreciate any advice or guidance as to what I might focus on next:
* My interpretation that I should be using pin 7 for Teensy 4 & IRRemote send might be wrong
* The 38kHz IRsend signal may be too fast for me to have found it so far with phone camera or analyzer (would be surprised tho) and everything is actually working, and I need to debug the IR codes I am sending
* The code I am trying to send - sendNEC(0x2FD48B7, 32) - is not valid and the IRRemote library will not process it
* Something else..

Briefly my setup is Ubuntu 18.04 desktop, Arduino IDE 1.8.12 for compile/deploy and sublime for writing code.

If I've missed any important details apologies, and please just let me know, and I would really welcome any insights from the experts!
 
In case anyone else ever ends up in this lonely place, and I might be able to help them, here's answers to some of my own questions for the record:

* My interpretation that I should be using pin 7 for Teensy 4 & IRRemote send might be wrong
-my debugging of the IRremote library code confirms it is trying to send on pin 7 for this setup.

* The 38kHz IRsend signal may be too fast for me to have found it so far with phone camera or analyzer (would be surprised tho) and everything is actually working, and I need to debug the IR codes I am sending
-my tests show that it is indeed impossible to see the IR LED sending from this code with a phone camera, the pulses are far too short (stretching by a factor of around 100 makes them "visible").

* The code I am trying to send - sendNEC(0x2FD48B7, 32) - is not valid and the IRRemote library will not process it
-this code is valid, and indeed works from other Arduino hardware.

So unfortunately something else is not working, which I've been unable to track down.
Ultimately I also needed more IO than the teensy can provide, so I've moved on to another platform (which worked 'out of the box').
 
A quick note: it is actually pin 8. I also couldn't get it to work with pin 7 so I messed around a bit until I decided to use a red LED in place of the IR led and found that the LED flashed when the IR code was transmitting on a Teensy LC but not on the T4.0. After much looking (but not much understanding!) at the code, I wondered if it was sending on a different pin. So I connected the red led to pin 8 and it lit up. Then I put the IR led on and it turned my Sony TV on and off.
It's bedtime. I'll play with it more tomorrow.

Pete
 
Thanks for the reply!
Weird about pin 7 vs 8: I added debug messages and followed the execution out of boarddefs.h into the core IRremote code far enough that I thought I had convinced myself it was really using pin 7 for the teensy 4 - pin 8 makes perfect sense though, since pin 7 seemed 'lifeless'. Also that's a great tip about replacing the IR LED with a visible LED for debugging - I really should have thought of/known that. If I can get my IO pin budget to balance I will revisit.
 
FYI 1: As expected, it also works on T4.1 on pin 8
FYI 2: As far as I can see, the macro TIMER_PWM_PIN which is set to 7 in ...\hardware\teensy\avr\libraries\IRremote\boarddefs.h is not used anywhere else in the IRremote library. It could have been set to any value and the IR Tx would still be on pin 8.

Pete
 
@el_supremo thanks so much! I just right now had a chance to try pin 8 on my Teensy 4 and confirmed it's also working for me.
I guess I didn't follow that TIMER_PWM_PIN setting far enough - a combination of my ignorance and a misleading code comment no doubt. Anyway all's good now, thank you so much again for helping :)
 
Opps, I see what happened. It was pin 7 on the 1052 chip we used very early in the beta test last year. Then several pin assignments where shifted for the 1062 chip, so pins 7 and 8 would have the same serial RX and TX as on Teensy 3.x. Looks like the library never got updated or retested after that very early beta.

I've updated the web page and the source code comment (for future Teensyduino releases).
 
A different problem with IRRemote

Hello Everyone,
I have a problem using IRRemote with a Teensy 4.0. I am using the Teensy together with the audio card from PJRC to make a bespoke synth. This all works well and I have pots and switches connected which all work as expected. I decided to add an IR receiver to give me more control over the synth. However, when I tried to use the Teensy it would not compile.

Points:
- I have the latest version of IRRemote 3.03 from GitHub.
- I am using the example code from GutHub to test just the receiver.
- I tested the receiver with a spare Arduino and it works as expected.
- I only have one spare digital pin on the Teensy that I can use easily to receive and that is pin 1.
- From my limited understanding of this it looks like the Board is not defined in IRRemote. Here is the error message:

Code:
Arduino: 1.8.13 (Mac OS X), TD: 1.53, Board: "Teensy 4.0, Serial, 600 MHz, Faster, US English"

In file included from /Users/jmw/Documents/Arduino/libraries/IRremote/src/IRremoteInt.h:64:0,
                 from /Users/jmw/Documents/Arduino/libraries/IRremote/src/IRremote.h:94,
                 from /Users/jmw/Documents/Arduino/IR_Receive_Test_3/IR_Receive_Test_3.ino:47:
/Users/jmw/Documents/Arduino/libraries/IRremote/src/private/IRremoteBoardDefs.h:295:2: warning: #warning Board could not be identified from pre-processor symbols. By Default, TIMER1 has been selected for use with IRremote. Please extend IRremoteBoardDefs.h. [-Wcpp]
 #warning Board could not be identified from pre-processor symbols. By Default, TIMER1 has been selected for use with IRremote. Please extend IRremoteBoardDefs.h.

Any help would be appreciated.
Thanks,
John!

Code:
/*
   SimpleReceiver.cpp

   Demonstrates receiving NEC IR codes with IRrecv

    Copyright (C) 2020-2021  Armin Joachimsmeyer
    armin.joachimsmeyer@gmail.com

    This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.

    MIT License
*/

/*
   Specify which protocol(s) should be used for decoding.
   If no protocol is defined, all protocols are active.
*/
//#define DECODE_DENON
//#define DECODE_SHARP        // the same as DECODE_DENON
//#define DECODE_JVC
//#define DECODE_KASEIKYO
//#define DECODE_PANASONIC    // the same as DECODE_KASEIKYO
//#define DECODE_LG
//#define DECODE_NEC
//#define DECODE_SAMSUNG
//#define DECODE_SONY
//#define DECODE_RC5
//#define DECODE_RC6

//#define DECODE_BOSEWAVE
//#define DECODE_LEGO_PF
//#define DECODE_MAGIQUEST
//#define DECODE_WHYNTER

//#define DECODE_HASH         // special decoder for all protocols

// Define sensor pin
const int IR_RECEIVE_PIN = 4;

//#include <Arduino.h>

/*
   Define macros for input and output pin etc.
*/
//#include "PinDefinitionsAndMore.h"

#include <IRremote.h>

void setup() {
  Serial.begin(9600);
  // Just to know which program is running on my Arduino
  Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

  /*
     Start the receiver, enable feedback LED and take LED feedback pin from the internal boards definition
  */
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

  Serial.print(F("Ready to receive IR signals at pin "));
  Serial.println(IR_RECEIVE_PIN);
}

void loop() {
  /*
     Check if received data is available and if yes, try to decode it.
     Decoded result is in the IrReceiver.decodedIRData structure.

     E.g. command is in IrReceiver.decodedIRData.command
     address is in command is in IrReceiver.decodedIRData.address
     and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
  */
  if (IrReceiver.decode()) {

    // Print a short summary of received data
    IrReceiver.printIRResultShort(&Serial);
    if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
      // We have an unknown protocol here, print more info
      IrReceiver.printIRResultRawFormatted(&Serial, true);
    }
    Serial.println();

    /*
       !!!Important!!! Enable receiving of the next value,
       since receiving has stopped after the end of the current received data packet.
    */
    IrReceiver.resume(); // Enable receiving of the next value

    /*
       Finally, check the received data and perform actions according to the received command
    */
    if (IrReceiver.decodedIRData.command == 0x47) {
      // do something
      Serial.println("0x47");
    } else if (IrReceiver.decodedIRData.command == 0x11) {
      // do something else
    }
  }
}
 
Status
Not open for further replies.
Back
Top