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

Thread: Teensy 4.0 without shield

  1. #1
    Junior Member
    Join Date
    Mar 2020
    Posts
    2

    Teensy 4.0 without shield

    I'm gonna do a project on DSP and I found that out that arduinos just aren't cut for the job. Teensy is a great replacement since it even shares the same IDE. However, I couldn't find much mention of teensy 4.0 on the audio library, other than some commits on github.. Does it work with it? Does it have a DAC? Or do I need a separate shield? Thanks!

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    No Teensy 4 does not have a DAC, you'll need to use one of the 3.x boards or additional chips https://forum.pjrc.com/threads/57208...l=1#post212602.

  3. #3
    Junior Member
    Join Date
    Mar 2020
    Posts
    2
    Quote Originally Posted by potatotron View Post
    No Teensy 4 does not have a DAC, you'll need to use one of the 3.x boards or additional chips https://forum.pjrc.com/threads/57208...l=1#post212602.
    Well, now I'm starting to like the idea of getting a rev D audio adapter board. Oh well, guess I'll have to save up some more money to get the touchscreen.

    Edit: also, another question. Is there anything in the audio library that the 4.0 can't do? I get the lack of DAC but what about instructions that it uses?
    Last edited by otaviomad; 03-01-2020 at 03:10 AM.

  4. #4
    Senior Member
    Join Date
    Dec 2015
    Posts
    167
    I believe at the moment USB audio isn't implemented. There might be more but that's just the one I've run up against.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    It has all instructions.

    You can use the MQS outputs. Not as good as a DAC, but if you don't need high quality it's ok.
    For small speakers quite good.

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,849
    Quote Originally Posted by Frank B View Post
    It has all instructions.

    You can use the MQS outputs. Not as good as a DAC, but if you don't need high quality it's ok.
    For small speakers quite good.
    Note, if you use MQS, you won't be able to use the main SPI bus because the MQSL pin is on pin #12 (MISO), and the MQSR pin is on pin #10 (primary CS pin). SPI buses are typically used for displays. You can use either the second or third SPI buses, but you will need to solder some wires to pads under the Teensy (the second SPI bus pads are easier to solder to than the pads for the third SPI bus).

    As I said in the article quoted above are other options to getting the revision D audio shield. One is the PT8211 board that PJRC sells, though the cost of shipping will overwhelm cost of the board, and it is useful to pick up if you are getting something else at the same time:


    For mono sounds, you can get I2S amplifiers that hook up to a single small speaker:


    For stereo sounds you can get this board instead. Like the audio shield, this board does not include amplification for speakers (headphones you can just plug into the socket):


    To use any of the I2S boards mentioned above, you will need to modify the example scripts to remove references to the sgtl5000 which is on the audio shield, but not on the cheaper boards.

    Here is the ToneSweep example:

    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:		5v		5v
    
      Other I2S2 pins not used by the Max98357A device:
    
      MCLK		Pin 23		Pin 11
      VOUT		Pin 8		Pin 13
    
      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.
    
      SD setting (documentation from the Adafruit board)
    
      This pin is used for shutdown mode but is also used for setting which channel
      is output. It's a little confusing but essentially:
    
      * If SD is connected to ground directly (voltage is under 0.16V) then the amp
        is shut down
    
      * If the voltage on SD is between 0.16V and 0.77V then the output is (Left +
        Right)/2, that is the stereo average.
    
      * If the voltage on SD is between 0.77V and 1.4V then the output is just the
        Right channel
    
      * If the voltage on SD is higher than 1.4V then the output is the Left
        channel.
    
        This is compounded by an internal 100K pulldown resistor on SD so you need
        to use a pullup resistor on SD to balance out the 100K internal pulldown.
    
      Or alternatively, use the HiLetgo PCM5102 I2S IIS Lossless Digital Audio DAC
      Decoder which provides stereo output:
      https://smile.amazon.com/gp/product/B07Q9K5MT8/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1  */
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioSynthToneSweep	tonesweep;		//xy=99,198
    AudioMixer4		mixer2;			//xy=280,253
    AudioMixer4		mixer1;			//xy=280,175
    AudioOutputI2S		i2s;			//xy=452,189
    
    AudioConnection		patchCord1(tonesweep, 0, mixer1, 0);
    AudioConnection		patchCord2(tonesweep, 0, mixer2, 0);
    AudioConnection		patchCord3(mixer2, 0, i2s, 1);
    AudioConnection		patchCord4(mixer1, 0, i2s, 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
    
    // Do a sweep in both directions, enabling or disabling the left/right speakers
    void do_sweep (int i)
    {
      int do_left  = (i & 1) != 0;
      int do_right = (i & 2) != 0;
      float gain   = (do_left && do_right) ? 0.5f : 1.0f;
    
      Serial.printf ("Sweep up,   left = %c, right = %c\n",
    		 (do_left)  ? 'Y' : 'N',
    		 (do_right) ? 'Y' : 'N');
    
      mixer1.gain (0, do_left  ? gain : 0.0f);
      mixer2.gain (0, do_right ? gain : 0.0f);
    
      if (!tonesweep.play (t_ampx, t_lox, t_hix, t_timex)) {
        Serial.println ("ToneSweep - play failed");
        while (1)
          ;
      }
    
      // wait for the sweep to end
      while (tonesweep.isPlaying ())
        ;
    
      // and now reverse the sweep
      Serial.printf ("Sweep down, left = %c, right = %c\n",
    		 (do_left)  ? 'Y' : 'N',
    		 (do_right) ? 'Y' : 'N');
    
      if (!tonesweep.play (t_ampx, t_hix, t_lox, t_timex)) {
        Serial.println("ToneSweep - play failed");
        while (1)
          ;
      }
    
      // wait for the sweep to end
      while (tonesweep.isPlaying ())
        ;
    
      Serial.println ("Sweep done");
    }
    
    void setup(void)
    {
      // Wait for at least 3 seconds for the USB serial connection
      Serial.begin (9600);
      while (!Serial && millis () < 3000)
        ;
    
      AudioMemory (8);
      Serial.println ("setup done");
    
      for (int i = 1; i <= 3; i++)
        do_sweep (i);
    
      Serial.println ("Done");
    }
    
    void loop (void)
    {
    }
    And here is an example using ToneSweep with 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	tonesweep;		//xy=99,198
    AudioMixer4		mixer2;			//xy=280,253
    AudioMixer4		mixer1;			//xy=280,175
    AudioOutputMqs		mqs;			//xy=452,189
    
    AudioConnection		patchCord1(tonesweep, 0, mixer1, 0);
    AudioConnection		patchCord2(tonesweep, 0, mixer2, 0);
    AudioConnection		patchCord3(mixer2, 0, mqs, 1);
    AudioConnection		patchCord4(mixer1, 0, mqs, 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
    
    // Do a sweep in both directions, enabling or disabling the left/right speakers
    void do_sweep (int i)
    {
      int do_left  = (i & 1) != 0;
      int do_right = (i & 2) != 0;
      float gain   = (do_left && do_right) ? 0.5f : 1.0f;
    
      Serial.printf ("Sweep up,   left = %c, right = %c\n",
    		 (do_left)  ? 'Y' : 'N',
    		 (do_right) ? 'Y' : 'N');
    
      mixer1.gain (0, do_left  ? gain : 0.0f);
      mixer2.gain (0, do_right ? gain : 0.0f);
    
      if (!tonesweep.play (t_ampx, t_lox, t_hix, t_timex)) {
        Serial.println ("ToneSweep - play failed");
        while (1)
          ;
      }
    
      // wait for the sweep to end
      while (tonesweep.isPlaying ())
        ;
    
      // and now reverse the sweep
      Serial.printf ("Sweep down, left = %c, right = %c\n",
    		 (do_left)  ? 'Y' : 'N',
    		 (do_right) ? 'Y' : 'N');
    
      if (!tonesweep.play (t_ampx, t_hix, t_lox, t_timex)) {
        Serial.println("ToneSweep - play failed");
        while (1)
          ;
      }
    
      // wait for the sweep to end
      while (tonesweep.isPlaying ())
        ;
    
      Serial.println ("Sweep done");
    }
    
    void setup(void)
    {
      // Wait for at least 3 seconds for the USB serial connection
      Serial.begin (9600);
      while (!Serial && millis () < 3000)
        ;
    
      AudioMemory (8);
      Serial.println ("setup done");
    
      for (int i = 1; i <= 3; i++)
        do_sweep (i);
    
      Serial.println ("Done");
    }
    
    void loop (void)
    {
    }
    Last edited by MichaelMeissner; 03-10-2020 at 12:33 PM.

  7. #7
    Junior Member
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    8
    You can buy at futurlec https://www.futurlec.com/Others/PT8211pr.shtml
    It cost $0,45 + $5 shipping. So that is cheaper i think.
    And on teensy 4 you can use the second i2s port by using AudioOutputPT8211_2
    This second port is pin2pin compatible with the pt8211 so its really easy PCB routing check my picture https://github.com/manicken/teensy4....518_211540.jpg

Posting Permissions

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