Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Teensy 4.0 + IRremote Library

  1. #1
    Junior Member
    Join Date
    May 2020
    Posts
    4

    Teensy 4.0 + IRremote Library

    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!

  2. #2
    Junior Member
    Join Date
    May 2020
    Posts
    4
    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').

  3. #3
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,311
    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

  4. #4
    Junior Member
    Join Date
    May 2020
    Posts
    4
    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.

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,311
    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\boardde fs.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

  6. #6
    Junior Member
    Join Date
    May 2020
    Posts
    4
    @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

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,311
    Glad to help.

    Pete

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,812
    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •