Speaker connected directly to 4.0?

Is it possible to hook up a 2w 28mm speaker directly to the mqsr and mqsl of the teensy 4.0 alone?

I would imagine you would need an amplifier for the speaker, much like you need to do on the Teensy 3.x machines that have a real DAC port. You can buy speakers that include the amplifier such as Adafruit's Stemma speaker (https://www.adafruit.com/product/3885). That speaker has 3 wires, one you connect to 5v (or 3.3v), one to ground, and the other to MQSR or MQSL.

For example, here is a sketch that does the tone sweep on MQS and MQR. Note, I just built it with the current TeensyDunio, but I haven't run it in awhile:

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.  */

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

// GUItool: begin automatically generated code (edited by meissner afterwards).
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)
{
}
 
Thank you so much for your help!
I have a 4.0 coming in the mail in a few days so I’ll be able to test this out then.
If I was to try it without an amplifier, would I hook one speaker wire to mqsr and the other to mqsl?
Or would I choose one of them, and the other ground?
 
Or would I choose one of them, and the other ground?

Definitely use only 1 signal and connect the speaker's other wire to GND. You would only use both signals if you have 2 speakers for stereo.

I would not recommend direct connection, for 2 reasons.

#1: You need a capacitor in series with the speaker to block the DC offset, because the pin drives 0 and 3.3V, so it will have a DC offset of approx 1.65V. You'll need a large capacitance, like 470uF or more. Capacitors of that size almost always require polarity. Connect the negative lead to GND and the positive lead to the speaker.

#2: A speaker rated for 4 or 8 ohms could end up drawing much more current than the pin is capable of providing. As a safety measure, I'd start with a 150 ohm resistor in series with the speaker and capacitor. This probably won't be loud enough, as nearly all the power will dissipate in the resistor rather than the speaker. If you're feeling like some risk, try gradually reducing the resistor (on a solderless breadboard, easily done by just adding more resistors of similar value in parallel).
 
More importantly a speaker is an inductive load and could fry a pin directly from inductive kickback. Series resistance may not protect against that directly, although reducing the maximum current involved reduces the risk.

Put the MQS signals through a high current logic buffer perhaps? A low-side MOSFET driver is one possibility for this, but they usually require 5V power, not 3.3V. The remains the need for a series capacitor - you don't want a DC offset current in a speaker.
 
Back
Top