Teensy 4.0 I2S without Audio Shield and flash memory question

Status
Not open for further replies.

MichaelMeissner

Senior Member+
I've been thinking of soldering up a prototype board for Teensy 4.0 that brings out 2 of the three SPI buses (for uncanny eyes) and also brings out sound. Now, generally I do these one-off boards where I have several connection points with the pins laid out in a standard layout and I use a custom (or standard) cable to connect to the various device. That way, I can treat the Teensy as a lego, adding and subtracting parts, but just using the cables to the breakout points, rather than the usual jumbled mess of a breadboard (even on a breadboard, I tend to use custom cut wires to go from the normal pins to the breakout points). For example, in my setup for 3.6, I have a standardized SPI pinout, and for each different display, I make a custom cable that goes from the breakout to the display, since there is a lot of variation in the pinouts on the displays).

Now, in the 3.x era, I tended to only use the prop shield to bring out the hardware DAC to the amplifier in the prop. shield and connect up a cheap mono speaker. Yeah, its not high fidelity, but for a costume prop, it is good enough.

Now, I haven't read the datasheet for the 1062 much, but at a high level, my understanding of the Teensy 4.0's sound capability is:
  • 2 separate i2s ports;
  • 1 MQSR/MQRL Mastering Quality Sound port;
  • 1 S/PDIF in/out port;
  • 31 PWM pins that with capacitors/resistors can be feed into an amplifier; (and)
  • No hardware DAC.

For the first i2s connection we have:
  • Master clock (MCLK1) on pin 23;
  • Bit clock (BCLK1) on pin 21;
  • Left/right channel clock (LRCLK1) on pin 20;
  • Input channel on pin 8;
  • 4 output channels on pins 7, 32, 9, and 6 (though as Paul mentions elsewhere, it is more complicated and some output pins can be input);

For the second i2s connection we have:
  • Master clock (MCLK2) on pin 33;
  • Bit clock (BCLK2) on pin 4;
  • Left/right channel clock (LRCLK2) on pin 3;
  • Input channel on pin 5;
  • Output channel on pin 2.

For the MQS ports we have (which conflicts with the SPI bus):
  • RIght port (MQSR) on pin 10;
  • Left port (MQSL) on pin 12.

For S/PDIF we have:
  • S/PDIF input on pin 15;
  • S/PDIF output on pin 14.

Now while it isn't listed on the pinout cards, I believe the I2S pins on the Teensy 3.2/3.5/3.6 are:
  • Master clock (MCLK) on pin 11;
  • Bit clock (BCLK) on pin 9;
  • Left/right channel clock (LRCLK) on pin 23;
  • Input pin on pin 13;
  • Two output pins on pins 22 and 15; (and)
  • The 3.5/3.6 have some alternate pins for i2s as well.

I gather there is currently no support for S/PDIF on the Teensy 4.0. But I might bring out a breakout for accessing Serial3 now and S/PDIF in the future.

For my purposes, the MQS stuff is less interesting, unless I can use just MQSL. I presume there is some ordering issues to use a display and MQSL, where I presume you have to initialize SPI first, do some magic, and then initialize MQSL. If I were to use a prop shield, I suspect I would not connect pin 12 to the prop shield and then do the magic.

So, without using the audio card, it looks like my main option for sound output is to use I2S.

I've bought one of the cheap MAX98357A i2s -> mono speaker chips, and it has the following inputs:
  • LRCLK;
  • BCLK;
  • Input (presumably connected to one of the I2S output pins);
  • Gain (various connections with resistors or floating to control sound level);
  • Shut down (if tied to ground, shuts off the MAX98357A);
  • Ground;
  • Vin (2.5-5.5v).

How do I specify in the I2S setup, which of the 4 output pins to use, or do I need to do a deep dive into the manual?

I looked at the examples in 1.47, and most of the examples assume the use of the Audio Shield, with a few using the DAC. Are there Teensy 4.0 (and 3.x) examples out there that do not use the audio shield, but instead directly connect to an I2S output chip?

Is there an example of using a SPI display and MQSL? Due to the prop shield having flash memory and an amplifier built-in, it is rather convenient to use the prop shield, but some of the pins overlap (such as pin 7 being the first I2S output pin and also the flash memory CS pin for the prop shield). But in using MQSL, I give up the ability to use flash memory from the prop shield. So I think I will move MQS off the list of possibilities.

Are there preferred pinouts to use standard cabling for I2S, S/PDIF, and MQS?

Is there a cheap SPI flash memory that connects with through hole connections that is properly tri-stated that I could use to replace the flash on the prop shield? Note, my soldering skills are not really up to SMT soldering, and most of the flash memory chips listed in the SPI flash memory page seem to be obsolete.

Does S/PDIF and MQS work with 3.3v VIN output or do they need 5v (or do they not need ground/VIN outputs)?

I assume Paul can't answer this in a public forum, but is there a timeline for the audio shield that is made directly for the Teensy 4.0 to be announced? The big problem I have with the audio shield is just the size when connected to a Teensy 4.0.

And to really press my luck, it would be nice if there where a prop shield made for the Teensy 4.0 that incorporated I2S and re-arranged the flash/led/audio enable pins to be more friendly for the 4.0.

Thanks in advance.
 
Last edited:
ToneSweep for I2S mono amplifier

To answer the question about using I2S amplifiers directly without the audio shield, it turns out to be pretty simple, as long as you use the default I2S TX (pin 7).

Here is ToneSweep modified for using I2S directly without using the audio shield. While I took the basic framework from the examples, I did run it through the audio tool, and changed the formatting to match my tastes. I've tried it on a Teensy 3.2, 3.5, and 4.0 and all worked fine (modulo the different pinouts between the Teensy 3.2/3.5 and the Teensy 4.0). I didn't have a 3.6 handy, but I have to imagine it will work just like the 3.2 and 3.5 did.

I picked up the MakerHawk MAX98357A from Amazon, and I used one of the Adafruit breadboard speakers I had laying around:

I used TeensyDunio 1.47, Arduino 1.8.9, and an official Teensy T4.0.

Code:
/*
  Demo of the audio sweep function.
  The user specifies the amplitude,
  start and end frequencies (which can sweep up or down)
  and the length of time of the sweep.

  Modified to eliminate the audio shield, and use Max98357A mono I2S chip.
  https://smile.amazon.com/gp/product/B07PS653CD/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

  Pins:		Teensy 4.0	Teensy 3.x

  LRCLK:	Pin 20/A6	Pin 23/A9
  BCLK:		Pin 21/A7	Pin 9
  DIN:		Pin 7		Pin 22/A8
  Gain:		see below	see below
  Shutdown:	N/C		N/C
  Ground:	Ground		Ground
  VIN:		3.3v		3.3v

  Gain setting:

  15dB	if a 100K resistor is connected between GAIN and GND
  12dB	if GAIN is connected directly to GND
   9dB	if GAIN is not connected to anything (this is the default)
   6dB	if GAIN is conneted directly to Vin
   3dB	if a 100K resistor is connected between GAIN and Vin.  */

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthToneSweep	tonesweep1;	//xy=102,174
AudioAmplifier		amp1;		//xy=324,172
AudioOutputI2S		i2s1;		//xy=538,168
AudioConnection		patchCord1 (tonesweep1, amp1);
AudioConnection		patchCord2 (amp1, 0, i2s1, 0);
// GUItool: end automatically generated code

const float	t_ampx	= 0.8;
const int	t_lox	= 10;
const int	t_hix	= 22000;
const float	t_timex	= 10;		// Length of time for the sweep in seconds

void setup(void)
{
  // Wait for at least 3 seconds for the USB serial connection
  Serial.begin (9600);
  while (!Serial && millis () < 3000)
    ;

  delay (3000);

  AudioMemory (2);
  amp1.gain (0.5);

  Serial.println("setup done");

  if (!tonesweep1.play (t_ampx, t_lox, t_hix, t_timex)) {
    Serial.println ("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  Serial.println ("Tonesweep up started");
  while (tonesweep1.isPlaying ())
    ;

  // and now reverse the sweep
  Serial.println ("Tonesweep down started");
  if (!tonesweep1.play (t_ampx, t_hix, t_lox, t_timex)) {
    Serial.println("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  while (tonesweep1.isPlaying ())
    ;
  Serial.println("Done");
}

void loop(void)
{
}

Here are pictures:
2019-08-30-23-32-005-teensy.jpg

2019-08-30-23-51-006-teensy.jpg


 
Last edited:
ToneSweep for MQSL, no audio shield

If you don't want to have I2S output, and don't use the main SPI bus, but want some basic output fed into an amplifier (such as the prop shield), here is the ToneSweep program rewritten to use MQSR/MQSL. Note, the ToneSweep function is mono only, so it only goes to the left channel (pin 12):

I used the Adafruit MAX98306 dual amplifier that I had lying around with two of the breadboard speakers. I used it with gain 9db, and used the 3.3v power for the amplifier:

At the upper reaches of the ToneSweep, it sounded a little funky, but for playing sounds like a costume prop, it is probably sufficient.

I tried the Audio Design Tool (https://www.pjrc.com/teensy/gui/), and it does not seem to have MQS as an output type. I took my previous example for plain I2S output and changed the outputs to MQS.

Code:
/*
  Demo of the audio sweep function.
  The user specifies the amplitude,
  start and end frequencies (which can sweep up or down)
  and the length of time of the sweep.

  Modified to eliminate the audio shield, and use MQS output.  Because of the
  use of fixed pins (10, 12), you probably cannot use the main SPI bus when you
  are using the MQS output.

  Pins:		Teensy 4.0

  MQSR:		Pin 10
  MQSL:		Pin 12

  Note, ToneSweep is mono only, so the sound will only go to MQSL.  */

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthToneSweep	tonesweep1;	//xy=102,174
AudioAmplifier		amp1;		//xy=324,172
AudioOutputMQS		mqs1;		//xy=538,168
AudioConnection		patchCord1 (tonesweep1, amp1);
AudioConnection		patchCord2 (amp1, 0, mqs1, 0);
// GUItool: end automatically generated code

const float	t_ampx	= 0.8;
const int	t_lox	= 10;
const int	t_hix	= 22000;
const float	t_timex	= 10;		// Length of time for the sweep in seconds

void setup(void)
{
  // Wait for at least 3 seconds for the USB serial connection
  Serial.begin (9600);
  while (!Serial && millis () < 3000)
    ;

  delay (3000);

  AudioMemory (2);
  amp1.gain (0.5);

  Serial.println("setup done");

  if (!tonesweep1.play (t_ampx, t_lox, t_hix, t_timex)) {
    Serial.println ("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  Serial.println ("Tonesweep up started");
  while (tonesweep1.isPlaying ())
    ;

  // and now reverse the sweep
  Serial.println ("Tonesweep down started");
  if (!tonesweep1.play (t_ampx, t_hix, t_lox, t_timex)) {
    Serial.println("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  while (tonesweep1.isPlaying ())
    ;
  Serial.println("Done");
}

void loop(void)
{
}
 
I've been thinking of soldering up a prototype board for Teensy 4.0 that brings out 2 of the three SPI buses (for uncanny eyes) and also brings out sound.

Almost snap ! 1*SPI, 2*I2S, 1*SPDIF

Doesn't use the MQS pins for which the word Medium Quality is almost fails the Trade Descriptions Act - a better term would be AM Medium Wave Quality !

WP_20190831_001[1].jpg
 
Almost snap ! 1*SPI, 2*I2S, 1*SPDIF

Doesn't use the MQS pins for which the word Medium Quality is almost fails the Trade Descriptions Act - a better term would be AM Medium Wave Quality !

I'm not sure what I'm looking at. It doesn't seem to be a board for the Teensy, as the holes are all wrong. And I can't tell where the I2S or SPI breakouts are (and S/PDIF is not yet supported). With all of those large holes, it looks like you got frustrated and took the board to the shooting range.

What I was trying to ask is are there pre-defined cables for I2S, etc. that have the pins in a certain order. For example, servos tend to use 3 pin headers with the wires in ground, voltage, data order. Trimpots, etc. tend to want ground, data, voltage instead.

I2C pins seem to be all over the map with the order of ground, voltage, scl, sda in different orders on different boards, so I tend to make custom cables that have 2 pins for power & ground, and 2 pins for scl and sda, so that I can use female headers in any order.

Likewise, it seems every SPI display I use has the pins in a different order, so I tend to break out pins in a pre-defined order, and then make custom cables for each display.

I didn't know if there were pre-defined pinouts for I2S and such.

My inclination is to use 8 pins:
  • 5v/VIN
  • 3.3v
  • ground
  • MCLK
  • BCLK
  • LRCLK
  • RX (rx from the microprocessor, tx from the device)
  • TX1 (tx from the microprocessor, rx from the device)
  • TX2 (tx from the microprocessor, rx from the device)

This way, my breakout can determine whether it wants 5v or 3.3v, and which of the 2 pins to use for input. I would have 2 way switches to decide on the power option and the tx option. I would have options on the breakout for the gain.

The mono I2S amp that I mentioned, would does not need MCLK nor RX/IN, but in having a standardized breakout order, I can attach something that needs MCLK or RX/IN in the future without re-soldering the board.
 
I'm not sure what I'm looking at. It doesn't seem to be a board for the Teensy, as the holes are all wrong.

Teensy is at the top, with a Pi4 in the middle. Pi4 doesn't do SPDIF and only has one I2S so the Teensy connects via SPI to expand it.

I'm not aware of any standard I2S connector pinouts - I use my own which you can see as the connectors under the Teensy at the top, but it's totally non-standard.

SPI is similarly a mess - one Chinese LCD supplier even has two pinouts for the same product so I have to state which one I want in writing every time I order a new batch.

Anyway definitely route MCLK on the connector - some DACs work find without it but it could limit your options later. I'd also suggest only sending +5V and then regulating and filtering this to 3.3V on the ADC/DAC board so you have a clean and accurate supply for them.
 
What I was trying to ask is are there pre-defined cables for I2S, etc. that have the pins in a certain order. For example, servos tend to use 3 pin headers with the wires in ground, voltage, data order. Trimpots, etc. tend to want ground, data, voltage instead.

I'm designing based on the FreeDSP Expansion Connector.

standard_freeDSP_expansion_header.jpg

This way, my breakout can determine whether it wants 5v or 3.3v,

I thought about adding 3.3 and 5v to the FreeDSP connector (at the end of the connector), but people on DiyAudio.com suggested not to. Some said that it wasn't reliable at low power levels, and suggested to put LDO's on the modules themselves. It has the benefit of providing some ESD protection as well.

I have been working on a Teensy to I2S bridge (Teensy Audio Breakout Board).

pcb_front.jpg

The purpose of this device is to be a development module for all things Audio with the Teensy. It exposes all the I2S lines (with I2C, not SPI), the SD card, SPDIF, USB, and has a power supply for 12v to supply each of the FreeDSP connectors. It's not complete, and it's just a concept. It's based on some schematics from a known working device with similar functionality (I2S distribution). I guess I'll share the schematic. I was planning on sharing it anyway and it might be helpful. See attached.
 

Attachments

  • Teensy_Audio_Bridge_Schematic.pdf
    270.5 KB · Views: 151
I'm designing based on the FreeDSP Expansion Connector.
Looks nice. It is probably more advanced than I would use, but I can see other people using it who want to do more than just play some pre-recorded sounds. For me, the primary motivation is things like costume props, where at times, the smallness of the whole package comes into play. What kind of batteries can be used and how long the prop will work on a single battery are other factors.

I would worry about the introduction of 12v connections in the Teensy 4.0 environment. Presumably you have another power source for that, and you protect the Teensy inputs from high voltages.
 
Looks nice. It is probably more advanced than I would use, but I can see other people using it who want to do more than just play some pre-recorded sounds.

I kinda agree, it's a little extreme. It was a good learning experience though. I'm now working on placing the chips I want to use directly onto the board, and skipping the Breakout Board altogether. It was helpful in determining all the different pins and some basic schematics to hook things up. That's why i posted the schematic. It might be helpful for audio projects. It would still be helpful for someone wishing to design a high count input/output digital mixer or processor. Especially if you use TDM...

I would worry about the introduction of 12v connections in the Teensy 4.0 environment. Presumably you have another power source for that, and you protect the Teensy inputs from high voltages.

Well the FreeDSP connector calls for it. And many opamps run on 12v, if I'm not mistaken. I think that's why they chose 12v, and expect people to lower it using LDOs on the modules. You can see some of the expansion modules here on the (not so great) FreeDSP website under IO expansions. http://freedsp.cc/#section-overview. There are a few amp modules that might help you with props that require higher volumes.

On the Dev Breakout Board it has some 12v power inputs for an external supply... Which would be needed to run a high count of modules. The project most certainly would not work on the 5v USB supply.
 
I agree 3.3V should be generated on-board using an LDO, but doing it from +12v is a bit extreme. Adding +5V to the connector seems a good idea to me, and something I always do.
 
There is a nice 8x8 analog I/O board for FreeDSP, the pcb is available from Tindie except that it's not in store right now (the seller is busy doing another FreeDSP project):

https://www.tindie.com/products/auverdion/freedspx-analogio-x8/

I guess that would work nice with the Teensy 4.0 FreeDSP motherboard, is that or the pcb desing files or gerbers at least available for public? It's not too difficult to do own design on KiCad though... The FreeDSP specs call for specific master clock frequency, 12V supply and specify the dimensions (100x80mm smallest one, with 2.5mm clearout on edges and the fixing holes 5mm from edges on every corner).
 
Status
Not open for further replies.
Back
Top