Teensy 4.1 w/PT8211 problems

notahardwareguy

Active member
This is driving me NUTS! I have two newly acquired and assembled PT8211(s) that I am trying to pair with Teensy 4.1 boards that are no Ethernet. One is lockable and one is not. The lockable has the PT8211 in a top mount configuration. The non-lockable 4.1 is breadboard connected to the PT8211.

I can not get either of them to work. I have removed/moved all non-stock audio-library branches, so I am using the standard stock audio library. Have confirmed this is so via the compiler logs. The first program below loads fine as shown to both a 4.1 with an audioShield and one with a PT8211. It plays fine (as expected) on the Teensy with the audioShield and as just static on the Teensy with the PT8211.

I can compile and auto-load a program to either of the two 4.1 boards that are connected to PT8211(s) from Arduino and can open a monitor window just fine (like blink or anything that does NOT reference a PT8211 - or maybe not the audio.h at all?). In the below file, if I comment out the "#define", I can ONLY load a program to the Teensy once where the loader automatically loads the Hex. No com ports are available to open the monitor window. If it try to load again, I have to use the board button. If I reset to factory default I can get one auto-load but again no com port. WHAT AM I DOING WRONG?!? This is driving me NUTS! I expect it is something simple I am just not seeing so any/all help is appreciated.

This is the "basic" audioShield program. Just comment out the define at the top for the PT8211 version. I tried the stock PT8211 test programs but they don't work either so this version was to try and fine out where.

Code:
/*
  Modified demo of the audio sweep function against audioShield and PT8211...
*/

//#define AUDIOSHIELD                       // uncomment this line for audioShield test, comment this line for PT8211 test

#include <Audio.h>

AudioSynthToneSweep   myEffect;
// comment this out to use PT8211...
#ifdef AUDIOSHIELD
AudioOutputI2S        audioOutput;        // audio shield: headphones & line-out
AudioControlSGTL5000  audioShield;
#else
AudioOutputPT8211     audioOutput;        // audio shield: headphones & line-out
#endif
// The tone sweep goes to left and right channels
AudioConnection c1( myEffect, 0, audioOutput, 0 );
AudioConnection c2( myEffect, 0, audioOutput, 1 );

float t_ampx = 0.250;
int t_lox = 50;
int t_hix = 400;
float t_timex = 2.5;

void setup( void )
{
  int timeout = 10;
  Serial.begin( 9600 );
  while ( !Serial && timeout )
    {
    timeout--;
    delay( 1000 );
    }
  Serial.print( "setup (" ); Serial.print( timeout ); Serial.print( ")..." );
  AudioMemory( 2 );
#ifdef AUDIOSHIELD
  audioShield.enable( );
  audioShield.volume( 0.5 );
#endif
  Serial.println( "setup done" );
}

void loop( void )
{
  Serial.println( "AudioSynthToneSweep - loop( ) start" );
  playeffect( );
  Serial.println( "AudioSynthToneSweep - loop( ) end" );
}

void playeffect( void )
{
  Serial.println( "AudioSynthToneSweep - playeffect( ) start");

  if ( !myEffect.play( t_ampx,t_lox, t_hix, t_timex ) )
    {
    Serial.println( "AudioSynthToneSweep - begin failed" );
    while( 1 ) ;
    }
  while( myEffect.isPlaying( ) ) ;

  if ( !myEffect.play( t_ampx,t_hix,t_lox,t_timex ) ) // and now reverse the sweep
    {
    Serial.println( "AudioSynthToneSweep - begin failed" );
    while( 1 ) ;
    }
  while( myEffect.isPlaying( ) ) ;                    // wait for the sweep to end

  Serial.println( "AudioSynthToneSweep - playeffect( ) end" );
}

// eof

Here is the end of the compiler logs for the "clean" compile of the "PT8211" version:

Code:
Memory Usage on Teensy 4.1:
  FLASH: code:65564, data:9112, headers:8264   free for files:8043524
   RAM1: variables:11648, code:62584, padding:2952   free for local variables:447104
   RAM2: variables:14976  free for malloc/new:509312
Multiple libraries were found for "SD.h"
 Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
 Not used: C:\Program Files (x86)\Arduino\libraries\SD
Using library Audio at version 1.3 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio 
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI 
Using library SD at version 2.0.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD 
Using library SdFat at version 2.1.2 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat 
Using library SerialFlash at version 0.5 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SerialFlash 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire 
C:\Program Files (x86)\Arduino\hardware\teensy/../tools/teensy_post_compile -file=ToneSweep_-_PT8211.ino -path=C:\Temp\arduino_build_213802 -tools=C:\Program Files (x86)\Arduino\hardware\teensy/../tools -board=TEENSY41 -reboot -port=Port_#0004.Hub_#0002 -portlabel=hid#vid_16c0&pid_0478 Bootloader -portprotocol=Teensy 
No Teensy boards were found on any USB ports of your computer.
Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.

Again, thanks for any help.
 
I ran it here on a Teensy 4.1 with PT8211. I've uploaded about a dozen times. Haven't needed to press the pushbutton on Teensy 4.1 yet.

Robin just walked in to see what that weird sound was about, as the red audio wire you see in this photo connects to powered speaker.

pt8211.jpg

I tested with Arduino 1.8.19 and Teensyduino 1.57 running on Ubuntu 20.04. I used your code in msg #1 exactly as-is, no edits of any kind.
 
Now for some guesswork, since I don't know and can't reproduce the problem.

If I reset to factory default I can get one auto-load but again no com port. WHAT AM I DOING WRONG?!?

First, check which version of Teensyduino you have. In Arduino 1.8.x, click Help > About. In Arduino 2.0.4, click Boards Manager and search for "teensy".

Older versions did have a buffer management bug in the PT8211 code. If you're using something older than 1.57 (or 1.57.2 if on Arduino 2.0.4), update before you waste any more time!

Next, try another computer with a fresh install of Arduino & Teensyduino. It definitely works here on my machine. I'd imagine we'll hear the same results if other people try this, even if just one a Teensy 4.1 without hardware connected, it should be able to repeatedly upload by only clicking Upload in Arduino, without having the press the pushbutton.

If you have 2 computers installed with 1.57 doing the same problem (sees highly unlikely), try changing Tools > USB Type to RawHID. This will prevent Teensy from needing the serial driver and Windows will only have to use its HID driver (one of the most reliable things in Windows). Seems unlikely this will help, but it's easy to try and can rule out anything strange "Windows driver problem".
 
Thanks for the comments and suggestions. My versions are (which should be good to go per your message):

Arduino 1.8.19
Teensyduino 1.57
Teensy Loader 1.75.

I don't have a second computer but I will see if I can spin up a clean version of windows or Ubuntu in vbox to try.
 
I can compile and auto-load a program to either of the two 4.1 boards that are connected to PT8211(s) from Arduino and can open a monitor window just fine (like blink or anything that does NOT reference a PT8211 - or maybe not the audio.h at all?). In the below file, if I comment out the "#define", I can ONLY load a program to the Teensy once where the loader automatically loads the Hex. No com ports are available to open the monitor window. If it try to load again, I have to use the board button. If I reset to factory default I can get one auto-load but again no com port. WHAT AM I DOING WRONG?!? This is driving me NUTS! I expect it is something simple I am just not seeing so any/all help is appreciated.
This sounds very much like the startup bug, might be worth applying the patch linked in that thread.

Older versions did have a buffer management bug in the PT8211 code. If you're using something older than 1.57 (or 1.57.2 if on Arduino 2.0.4), update before you waste any more time!
I have removed/moved all non-stock audio-library branches, so I am using the standard stock audio library. Have confirmed this is so via the compiler logs.
It doesn't help that the Audio library version number hasn't been updated since late 2016, despite there having been hundreds of revisions in the last 7 years...

If it's the case you're using the latest Teensyduino, then it does sound like a hardware issue - maybe some good-quality images of your built-up boards would shed some light?
 
OMG just solved it! Was giving it one last go before setting up a vbox environment and remembered that I had a prior issue when I compiled a program using the Audio library with the compiler set to debug. The compiler optimization [right now] was set to "Fastest". I changed it to "Faster" and now all is working good!

I can reproduce it at will by only making that optimization change. I guess my follow up question would be can others replicate my issue if they set their compiler optimization to "Fastest"?

h4yn0nnym0u5e, I had applied that patch before but likely only to your(?) branch. I will double-check. I know your patch worked for [I believe it was] the SPDIF interfaces when I set optimization to "Debug". I will review and update. Thanks.
 
Last edited:
OK, just had time to check and the startup.c file at this location: "C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4" has this "code change":

Code:
__attribute__((optimize("O2")))					// added 20230107 to resolve issue with audio.h and compiling in Arduino with "debug" optimization whereas board boots to 7 or 9 flashes of LED and locks
FLASHMEM void reset_PFD()
{

Is another change needed elsewhere for using other compiler flags like "fastest" or "smallest"? Or should I just leave that darn flag alone?
 
“If it ain’t broke, don’t fix it” has always struck me as good advice :D

You could try doing a “portable” Arduino install and using Teensyduino 1.58 beta to see if the official fix works for you: I think the above change was a first fix, but others have come up with a more comprehensive variant which deals with a wider range of compiler options.

I don’t tend to play much with optimisation options usually, what bit me was using -Og to enable debugging.
 
Back
Top