Teensy 4.1 Pin 22 disabled by AudioOutputI2S


Active member
I'm using the Teensy 4 Rev D audio card with a Teensy4.1. The audio works well, however when I define the audio output object as AudioOutputI2S, this disables analogRead(22). As far as I can see from the RevD schematic and the pin descriptions, Pin 22 should not be touched by the AudioOutputI2S code on Teensy4.1. (It is with Teensy 3.) If I comment out the AudioOutputI2S, the analogRead again works. Is this a mistake of mine, or is there a library fault? Is there a workaround? I'm using all the other pins so cannot easily change pin. This simple code below demonstrates the problem.

#include <Audio.h>

AudioOutputI2S AudioOutPort; // Comment this line out and analogRead(22) starts working.

void setup()

void loop()
Not on my T4.1. Commented or not, analogRead(22) provides the expected values.
Ok thanks. I therefore tried it on a standalone T4.1 without shield or other hardware, and yes it works as expected. Must be a hardware thing which I'll look into.
Have you checked for solder bridges on the audio shield between pin 22 and pins 21/23?
Actually I've not connected Pin 22 to the shield, so it's not that, but it must be something similar. I think the ball is in my court again. Thanks.
I believe there is still a code problem with analog reading on Teensy4.1 Pin 22 when the AudioOutputI2S object is present. The quick standalone test I did at an earlier post showed that inputs were varying with analogRead(22) as the input voltage changed, but I had not realised that the values read were not correct. I'm now testing only on a standalone T4 with no shield. Here is the set up:
- Analog input Pin 22 is connected by 1K resistor to ground.
- Analog input Pin 38 is also connected by another 1K resistor to ground.
- There are no other connections to the Teensy, apart from the USB cable tot he PC.
Without AudioOutputI2S, both analog reads return value 0, occasionally flickering to 1. Good result.
Include the AudioOutputI2S, analog read Pin 38 remains correct, but analog read Pin22 starts randomly jumping between 0 and about 50.
The voltage on Pin 38 is 0mV with or without the AudioOutputI2S.
The voltage on Pin 22 is 0mV without the AudioOutputI2S, but jumps to 6mV with AudioOutputI2S. I know 6mV is tiny, but it does show that something is happening at Pin22 when the AudioOutputI2S is included.
The option of using a different pin creates a number of problems (PCB layout, no spare pins) so really would like to get this sorted. Both my Teensy 4.1s (one stand alone and the other on PCB with audio shield RevD) are behaving similarly. I'm using Arduino 2.3.2, Teensyduino 1.59.0.
Anyone have any thoughts?
I've simplified it down to the most basic hardware and code. I've attached a picture of the hardware I'm using and a screenshot of the code and monitor window.
Screen Shot.jpg
Did you check continuity between the right-hand sides of the resistors?
You can also run a wire between Teensy GND and pins 22 & 38 directly [unlikely, but you could have a broken resistor].

Given pin 22 is right in the middle of two I2S clocks (MCLK and BCLK) this just seems like noise, not any code issue.
I'm sure the resistors are fine, because if I comment out the AudioOutputI2S, both inputs read correctly. The 6mV issue, I agree is probably noise for the neighbouring pins. I put a CRO on Pin 22 and it's a weak waveform resembling the neighbours 21 and 23 which was probably averaged to 6mV by my multimeter.

As for connecting pins 22 and 38 directly to ground, there is a reason why I used resistors. As I suspected pin 22 is becoming an output, I didn't want to short it out. However I have now tried connecting both pins 22 and 38 to ground, and this may give us another clue (and a weird result.).

Without object AudioOutputI2S, both pins 22 and 38 read as expected, 0' and occasional 1's.

With object AudioOutputI2S included:
- If I connect only Pin 38 directly to ground, analogRead(38) gives me correct results of 0's and 1's.
- If I connect only Pin 22 directly to ground, analogRead(22) gives me random values from 0 to 18.
- If I connect both Pin 22 and Pin 38 to ground, both inputs give abnormal readings as per the monitor screenshots below.

ScreenShot 2.jpg


  • 1716631714021.png
    708.6 KB · Views: 8
Checked on a Teensy 4.1 here.
With AudioOutputI2S AudioOutPort; uncommented, it shows some noise.

With pins 22 & 38 connected to Teensy GND and to Teensy 3V3:


With AudioOutputI2S AudioOutPort; commented out, no noise is present:


Bottomline, AudioOutputI2S AudioOutPort; does not disable analogRead(22) but generates some on-chip noise.


PS: I tried pinMode(22, INPUT_DISABLE); and pinMode(38, INPUT_DISABLE); in setup(), but no change in behaviour.
PS: I tried pinMode(22, INPUT_DISABLE); and pinMode(38, INPUT_DISABLE); in setup(), but no change in behaviour.
With Teensyduino 1.59, setting the pinmode correctly is basically now built into analogRead() to avoid the old issue.
Thanks. The serial monitor displays pretty much confirm what I am seeing. Having established that Pin 22 is most likely receiving some on-chip noise, I've gone back to the original scenario I was debugging. The original case was a TMP36 3 pin temperature sensor chip, running from 3.3V, feeding it's output into Pin 22. (This is how the PCB has been laid out.) The analog value being read from pin 22 is around 210 (18C) without AudioOutputI2S, which is correct. Adding AudioOutputI2S changes the analog value to a range of random numbers between around 10 and 57, averaging around 35 (-40C). It is winter here but it's not that cold! It's hard to believe that on-chip noise could cause this, but I think I'll just have to accept that I should not have chosen an ADC input which is located between 2 high speed clocks.
Another thought. I actually only need to read the temperature (pin 22) once before the starting the audio system. (The sensor is used for pitch adjustments, as the unit will be playing along with organ pipes, which change pitch with temperature.) However the audio system seems to initialise itself at power-on. Would there be a way to stop/start the audio system, or at least the 2 offending clocks, programmatically whilst I read the pin 22?
You could use the late hook function:
// extern "C" only need if this is used in a c++ file

extern "C" void startup_late_hook(void) {
  // measure A8/pin 22 here
The Teensy's startup code will call this function right before it initializes all the C++ objects.
That's terrific. This works perfectly thank you! The behaviour with the AudioOutputI2S object is still a bit odd, but I can certainly live with the result using startup_late_hook. (And I have now read about the 3 hooks for future reference.)