Teensy 4.0 - Toslink optical output

Status
Not open for further replies.

etan22

New member
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).
 
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.
 
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.
 
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.
 
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]".
minitoslink.png

* Mini TOSLINK is a smaller 3.5 mm alternative connector (https://www.amazon.com/dp/B07SL5DM5X)
 
Very pleased to say I can report spdif running here on T4 from pin 7 as well!

20200516_120839.jpg

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:
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-Tosli...e=STRK:MEBIDX:IT&_trksid=p2057872.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.
 
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
 
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;
 
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!
 
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.
 
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.

screenshot.png

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.
 
Like most details of the audio library, it's documented in the design tool.

View attachment 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.
 
Status
Not open for further replies.
Back
Top