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

Thread: Teensy 4.0 - Toslink optical output

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    3

    Teensy 4.0 - Toslink optical output

    A 2015 forum thread discussed S/PDIF Toslink output with the Teensy 3.1. One of the options discussed was simply adding a red LED, connected to pin on the Teensy, with a resistor to limit brightness, and point it at the end of the fiber optic connector. I would like to try this with a Teensy 4.0 and the current audio library.

    With Teensy 4.0 what is the correct pin to use?

    My goal is to extend the Teensy 4 Audio board's 3.5mm stereo output jack into a dual analog / digital jack using a mini Toslink format plug that is also 3.5mm. (Google did this in their Chromecast Audio device).

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,220
    output_spdif (I2S used as SPDIF) : Pin 7
    - and/or -
    output_spdif2 (I2S used as SPDIF): Pin 2
    - and/or -
    output_spdif3 (SPDIF hardware): Pin 14

    Attention I have not used them for a log time and some Teensyduino versions. I hope it still works.

    The LED has to be really bright - I used a LED from a old optical mouse. It is not very reliable: You must have a mechanically stable connection, and the LED must shine straight (0 angle) into the optical cable.
    Much better is a toslink.

  3. #3
    Junior Member
    Join Date
    Jan 2020
    Posts
    3
    Thanks for the reply but no luck so far. This is what I have done.
    1) Using a Teensy 4.0 board (not 3.1) and the Teensy 4 audio board (Rev D)
    2) running Teensyduino 1.49 (Arduino 1.8.10)
    3) using software "Example > Audio > WavFilePlayer" (ran with no change and verified that song played from 3.5mm analog jack.)
    4) modified the WavFilePlayer.ino to comment out line 36 AudioOutputI2S... and uncomment line 37 AudioOutputSPDIF...
    5) tried hooking up both a regular LED and also purchased an Everlight PLT133/T8 (https://www.mouser.com/ProductDetail/638-PLT133T8) toslink transmitter. I have hooked this up with wires to the GND, 3.3V VCC, VIN to the various pins mentioned and no luck getting anything to light up.

    Given the software and hardware I'm using, should this work, and if so what pins should I use?

    Thanks.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,220
    Quote Originally Posted by etan22 View Post
    Thanks for the reply but no luck so far. This is what I have done.
    1) Using a Teensy 4.0 board (not 3.1) and the Teensy 4 audio board (Rev D)
    2) running Teensyduino 1.49 (Arduino 1.8.10)
    3) using software "Example > Audio > WavFilePlayer" (ran with no change and verified that song played from 3.5mm analog jack.)
    4) modified the WavFilePlayer.ino to comment out line 36 AudioOutputI2S... and uncomment line 37 AudioOutputSPDIF...
    5) tried hooking up both a regular LED and also purchased an Everlight PLT133/T8 (https://www.mouser.com/ProductDetail/638-PLT133T8) toslink transmitter. I have hooked this up with wires to the GND, 3.3V VCC, VIN to the various pins mentioned and no luck getting anything to light up.

    Given the software and hardware I'm using, should this work, and if so what pins should I use?

    Thanks.
    Why the audioboard ? Pins, see post before.. is the SPDIF-LED lit?
    On the PLT133, you must connect GND to GND, PLT133-VCC to 5V and PLT133-VIN to the Spdif-pin.
    Do NOT use any pin that is used by the mounted audioshield.
    You can NOT use I2s AND a Spdif that uses the same pins of I2S, of course.

  5. #5
    Senior Member
    Join Date
    Feb 2017
    Posts
    418
    I've used this board for TOSLINK in and out. It does TOSLINK <--> I2S conversion for you. So, it interfaces to the Teensy using I2S.
    https://www.amazon.com/gp/product/B0...?ie=UTF8&psc=1

  6. #6
    Junior Member
    Join Date
    Jan 2020
    Posts
    3
    First of all, thank you Frank B for your help. (also gfvalvo for your alternate hardware suggestion)

    It is working now. Using both Everlight PLT133/T8 connector and a simple 3mm red diffused LED with the Teensy 4.0 and Rev D audio board.

    I was overly focused on Pin 14 which is listed as S/PDIF out on the Teensy 4.0 pin diagram and not really understanding your comment "You can NOT use I2s AND a Spdif that uses the same pins of I2S, of course". But the correct pin to use with this hardware / software was pin 7.

    For the LED just connecting anode to pin 7 and the other leg to ground worked.

    For the PLT133/T8, VCC to either 5 or 3 volts, VIN to Pin 7, and GND to GND worked. (I had the outside legs reversed on my first round of tests, this caused the follow up question)

    What I was curious about was if I could put a red LED into the back end of the 3.5 mm stereo jack on the audio board and then use a MINI TOSLINK* connector as an alternate plug into the same jack to get digital or analog output. In my initial testing this seems to work fine. The 3mm LED slides 2-3 MM into the open back end of the audio jack and is held in place by the opening (a 5mm LED might fit better).

    While this "hack" seems to work fine, it may be as Frank B. said "Much better is a toslink [connector]".
    Click image for larger version. 

Name:	minitoslink.png 
Views:	74 
Size:	777.7 KB 
ID:	18815

    * Mini TOSLINK is a smaller 3.5 mm alternative connector (https://www.amazon.com/dp/B07SL5DM5X)

  7. #7
    Very pleased to say I can report spdif running here on T4 from pin 7 as well!

    Click image for larger version. 

Name:	20200516_120839.jpg 
Views:	62 
Size:	93.2 KB 
ID:	20126

    locked at 44.1k.The sync light on my RME babyface is blinking sometimes but the audio sounds good so far! edit: using spdif input as master clock solves the flashing light.
    Last edited by alrj; 05-16-2020 at 11:27 AM.

  8. #8
    Hi folks,
    I am also trying to get toslink to work with my teensy 4.0

    I tried the wav file example and with a standard 3.5mm jack from the audio shield outputs sound to my speaker just fine. The sample wav file on the SD card in the slot on the shield plays just fine.

    I am trying to get optical audio to work with my speaker and not having any luck.

    I tried working with the following toslink connector from ebay
    https://www.ebay.com/itm/5pcs-Toslin...72.m2749.l2649

    The LED inside the connector does light up when I wire things up
    pin 1 - GND
    pin 2 - VCC
    pin 3 - signal

    I tied connecting the signal to pin 14 on the teensy and modified the code to the following

    Code:
    // Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
    //AudioOutputI2S           audioOutput;
    AudioOutputSPDIF       audioOutput;
    //AudioOutputAnalog      audioOutput;
    //On Teensy LC, use this for the Teensy Audio Shield:
    //AudioOutputI2Sslave    audioOutput;
    No luck..

    I also tried using a bare red led and pointing that at my toslink cable input.

    With the anode connected to pin 14 the led is totally dead.

    When I connect the anode to pin 7 it does light up but if it is sending data at a high rate and flickering too fast, I'm not seeing it. To me it seems like it's solid on when getting current off of pin 7. My toslink cable pointing at the LED while connected to pin 7 doesn't get any audio off my speakers.

    I'm kind of stuck here.. Any ideas would help.

    Thanks.

  9. #9
    Senior Member
    Join Date
    Jul 2020
    Posts
    901
    Quote Originally Posted by etan22 View Post
    For the LED just connecting anode to pin 7 and the other leg to ground worked.
    No current limiting?

  10. #10
    You have to use pin 7 from what I remember : )

  11. #11
    Quote Originally Posted by alrj View Post
    You have to use pin 7 from what I remember : )
    Yes I've tried pin 7 but not getting any audio.

    Maybe I need to do something different in my sketch.

  12. #12
    Try getting the example going first would be my suggestion I think that is how I managed it first off! Then adjusted to my needs

  13. #13
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,012
    I haven't yet used S/PDIF, but the Teensy 4.x has hardware support for S/PDIF using pin 14 for the output pin and pin 15 for the input pin.

    You would need to change:
    Code:
    AudioOutputSPDIF       audioOutput;
    to:

    Code:
    AudioOutputSPDIF3      audioOutput;

  14. #14
    Quote Originally Posted by MichaelMeissner View Post
    I haven't yet used S/PDIF, but the Teensy 4.x has hardware support for S/PDIF using pin 14 for the output pin and pin 15 for the input pin.

    You would need to change:
    Code:
    AudioOutputSPDIF       audioOutput;
    to:

    Code:
    AudioOutputSPDIF3      audioOutput;
    Thanks very much! This is exactly what I needed. S/PDIF and toslink is working perfectly for me now over pin 14.

    Per your advice, changing my code to the following did the trick.

    Code:
    AudioOutputSPDIF3      audioOutput;
    I'm just wondering whether this is documented anywhere, because I would have never guessed that.

    Thanks again!

  15. #15
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,012
    Quote Originally Posted by pepsiplease69 View Post
    Thanks very much! This is exactly what I needed. S/PDIF and toslink is working perfectly for me now over pin 14.

    Per your advice, changing my code to the following did the trick.

    Code:
    AudioOutputSPDIF3      audioOutput;
    I'm just wondering whether this is documented anywhere, because I would have never guessed that.

    Thanks again!
    Well, its there but you have to know about it.

    If you go to the pinout card, you will see pins 14/15 being documented as S/PDIF out/in.

    If you go into the audio design tool (https://www.pjrc.com/teensy/gui/) and select either spdif3 input or output it will talk about it, and that it is only Teensy 4.x with pins 14/15.

    The original spidif was added for the Teensy 3 and it uses the I2S subsystem to do S/PDIF. When Teensy 4.0 came out with a second I2S, spdif2 was added.

    The forum user FrankB contributed most (or at least a lot) of the code.

  16. #16
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,220
    It really should work with any of the 3 S/PDIFs...

  17. #17
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,968
    Quote Originally Posted by pepsiplease69 View Post
    I'm just wondering whether this is documented anywhere, because I would have never guessed that.
    Like most details of the audio library, it's documented in the design tool.

    Click image for larger version. 

Name:	screenshot.png 
Views:	5 
Size:	28.8 KB 
ID:	23887

    If you click any of these 3 outputs in the left column, their documentation appears in the right side column. Scroll down to "Hardware" for the pin details.

  18. #18
    Quote Originally Posted by PaulStoffregen View Post
    Like most details of the audio library, it's documented in the design tool.

    Click image for larger version. 

Name:	screenshot.png 
Views:	5 
Size:	28.8 KB 
ID:	23887

    If you click any of these 3 outputs in the left column, their documentation appears in the right side column. Scroll down to "Hardware" for the pin details.

    Thank you all for your prompt and helpful replies. I have everything working now.

    Unfortunately I haven't spent much time with the gui tool so I missed that detail.

    The last thing I had to do was re-encode my wav files from a different bit rate to 44.1 kHz and export it as a 16 bit signed wav file.

    Without this it was skipping over all of my files.

Posting Permissions

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