3.2 vs 4.0 + propshield

derplecbob

Active member
I used to use the 3.2 plus the prop shield to run some addressable leds, send audio to a 2w mini speaker, and use the giro-scope inside the propshield. Can I do this all with the 4.0 + propshield since 3.2s are out of stock?
 
I used to use the 3.2 plus the prop shield to run some addressable leds, send audio to a 2w mini speaker, and use the giro-scope inside the propshield. Can I do this all with the 4.0 + propshield since 3.2s are out of stock?

You can do everything but audio directly. The Teensy 4.0 does not have a DAC (digital to analog conversion) pin that the 3.2 used to emit audio directly. But the Teensy 4.0/4.1 does have the MQSR (pin 10) and MQSL (pin 12) pins that can do audio with some code changes.

Note, you likely will not be able to access the flash memory in the prop shield, due to the SPI pins being used.

Here is a version of the ToneSweep example that uses MQSL/MQSR:

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)
{
}

Given the prop shield only does mono, you should pick whether you want to use MQSL or MQSR for the audio stream. You would need to run a wire from either pin 10 or pin 12 to the DAC pin that the Teensy 3.2 uses in the back of the Teensy.
 
Thank you so much for your help!
What will not being able to access the slash memory on the propshield do?

In theory, if you don't use the feature nothing. Note, given how pins 11 and 13 are used for the LED lights already, if you wanted to use the flash memory on a Teensy 3.2, you would have to be rather careful to go between using the flash memory and using the LEDs. Given how pins 10 and 12 are used for MQSR/MQSL, it would be much harder to switch both the pins from LED/sound to SPI and back again.
 
Sorry I have not played with propshield in awhile, so I would go by MichaelMeissner advise.

But was wondering things like are you using Neopixels or DotStar (AP102).
If I remember correctly the propshield has only a Mono AMP on it. So if it were me, I would experiment
with what was shown above.

But see if I could restrict the Audio to only pin 10 and not use pin 12. Not sure if Audio library when using MQ... can limit, but if not, you can probably just try to do an SPI.begin after the Aduio is setup...

That leaves you with a sort of standard setup like T3.2. That is:
For Dotstar leds and memory.

You have to control pins 6 and 7 as SPI CS pins. So when you wish to address the memory you assert the memory CS(6 low, 7 high), and when doing stuff to LEDS (6 high, 7 low)

But again this should be reasonably straight forward as long as you don't need pin 12 for the Audio
 
Sorry I have not played with propshield in awhile, so I would go by MichaelMeissner advise.

But was wondering things like are you using Neopixels or DotStar (AP102).
If I remember correctly the propshield has only a Mono AMP on it. So if it were me, I would experiment
with what was shown above.

But see if I could restrict the Audio to only pin 10 and not use pin 12. Not sure if Audio library when using MQ... can limit, but if not, you can probably just try to do an SPI.begin after the Aduio is setup...

That leaves you with a sort of standard setup like T3.2. That is:
For Dotstar leds and memory.

You have to control pins 6 and 7 as SPI CS pins. So when you wish to address the memory you assert the memory CS(6 low, 7 high), and when doing stuff to LEDS (6 high, 7 low)

Many years ago, I did experiment with the propshield, neopixels, and SPI displays. I needed to use code to switch the pins from SPI mode to normal mode. KurtE suggested the code that I applied in this case:

Code:
      if (do_spi_reserve)
	{
	  // beginTransaction prevents SPI bus conflicts
	  // We need to reset 11 & 13 to being digital pins
	  // https://forum.pjrc.com/threads/46640-Neopixels-with-SPI-transactions-on-prop-shield-working-with-ST7735-SSD1351-displays
	  SPI.beginTransaction (SPISettings(24000000, MSBFIRST, SPI_MODE0));

	  if (pin_spi_p)
	    pinMode (pin_neopixel, OUTPUT);

	  if (pin2_spi_p)
	    pinMode (pin_neopixel2, OUTPUT);

	  // Doing uncanny eyes, we need a slight delay after doing the beingTransaction so that the first LED doesn't glitch
	  if (do_spi_delay)
	    delay (do_spi_delay);
	}

and the code to change from neopixel mode back to SPI mode:

Code:
      if (do_spi_reserve)
	{
	  // allow other libs to use SPI again
	  SPI.endTransaction ();

#if PROCESSOR_TEENSY_3_X || PROCESSOR_TEENSY_LC
	  if (pin_spi_p)
	    {
	      volatile uint32_t *reg = portConfigRegister (pin_neopixel);
	      *reg = PORT_PCR_MUX (2);
	    }

	  if (pin2_spi_p)
	    {
	      volatile uint32_t *reg = portConfigRegister (pin_neopixel2);
	      *reg = PORT_PCR_MUX (2);
	    }

#elif PROCESSOR_TEENSY_4_x
	  if (pin_spi_p || pin_spi2_p)
	    Serial.println ("Need to add Teensy 4.0 transaction support");
#endif

	}

As you can see, I had only done this for the Teensy 3.x processors. I don't know if you need similar code to switch between MQS* mode and normal mode.
 
Yeah I am using neopixle leds

Just to be clear, the issue is using the SPI devices with MQSR/MQSL and with the neopixel level shifters. If you don't use either the flash memory on the propshield or use an external SPI display, then it should be fine.

If you alternate between using the neopixel LEDs and using a SPI device, it could be done on the 3.x Teensys by explicitly switching between the two states. I haven't tried the code in a long time, and as the comments say, I've never tried it on the Teensy 4.x. KurtE might be able to weigh in on whether the code will work on the Teensy 4.x boards.

But if you add MQSL/MQSR on the Teensy on the mix, it becomes more complex, since you now have to switch pins 11/13 between SPI mode and normal mode, and you have to swap pins 10/12 between SPI mode and MQS* mode. It may be doable, but it may take some time to investigate the library internals to find the right bits to set.

If you are controlling an external display, an alternative is to use SPI1 for the display. On the Teensy 4.0, you will need to solder pads 26 and 27 underneath the Teensy to bring out SPI1 pins. On the Teensy 4.1, the SPI1 pins are in the standard pins brought out. If you wanted to use the flash memory on the prop shield, an alternative is to use a Teensy 4.1 and solder a flash memory chip underneath the Teensy.

So, it is simplest just not to use SPI devices with the propshield.

Alternatively, there are other ways to proceed:

If you are just playing certain songs/sounds, you could hook up a DFPlayer (or clone). These are off board audio processors that either have a built-in micro SD card reader and/or flash memory, and you can control the device from the Teensy. The official DFPlayer for micro SD cards has an amplifier for mono built-in, so you would just have to add the speaker, and hook it up to the Teensy:


Alternatively, you could get a I2S to mono speaker board to use for doing sound:


You would need to hook it up to the I2S pins (20, 21, 7) or I2S2 pins (3, 4, 2) to control it, and change your audio device.

Instead of using the propshield for neopixels, you could use a 74AHCT125 (or other alternatives, depending on your soldering skills):


It occurs to me, that an alternative might be to use the Teensy LC instead of the Teensy 3.2. Now, the LC has a lot less memory than the 3.2, and doing sound is more restricted on it, but the LC is still available. If you only use one pin for neopixels, the LC has a built-in level shifter for pin A3, so you wouldn't need to use the converters that the prop shield provides.
 
Last edited:
Back
Top