audio input on Teensy 4.1

dragoncat

Member
I have a very basic question. I want to start by taking audio input and simply directing it to the audio output. I'm going to do more with it later but that's my starting point. I know that the output works. I have my speaker connected to pin 10 on the Teensy 4.1 and I am using this sample program to generate tonesweeps, etc: https://github.com/TeensyUser/doc/wiki/Audio-Example-using-MQS-on-Teensy-4.0-or-4.1

What I did was to define adc1 on https://www.pjrc.com/teensy/gui/index.html and then attach a patch cord to the mixer and the mixer is defined and connected to the output in the same way as the first example. Then I added that code to the first example, renumbering things to avoid duplications and to make sure it compiles.

My problem is that:

1. I don't know which pin to use for the audio input
2. If I connect adc1 directly to print, nothing happens (shouldn't that give me some serial output, even if nothing is connected to adc1 and the input is all zeros?).

I have searched online for the Teensy 4.1 pinout and I get all sorts of conflicting information.

My questions are:

Can someone please tell me which pin on the Teensy 4.1 to use for audio input?

Is it possible for anyone to provide a very simple example of audio input combined with print or any of the other tools in the "analyse" section (none of them seem to work for me)?

Please assume that I am new to this and I don't know anything about the Teensy (though I am somewhat experienced with coding in C and in real time programming), so no big words or complicated theory, please. Just an example or two to get me started would be super helpful, and please tell me which pin I can use for the audio input.

Thanks.
 
Thanks for your reply. I have now tried that pin but no luck. Reading the info, I think that might just be for Teensy 4 not 4.1. The two are very different so it is unlikely that it would happen to be the same pin.

I would like to know how to test it, so if anyone has some code with which I can do that, I could try all the possible pins for audio input and see which one works.

Thanks again.
 
The first thing is to condition the audio signal so that information about its behavior is not lost. This circuit to condition the audio signal on pin A2 of your teensy is a good start.

u4QxCso.png


Try this code:
Code:
#include <Audio.h>

AudioInputAnalog         adc1;   //    A2 pin teensy 4.1 
AudioAnalyzeFFT1024      fft1024_2;
AudioOutputI2S           i2s1;
AudioConnection          patchCord3(adc1, fft1024_2);

//#include <GDSTx.h>    //for testing with the TFT NHD FT813 5"

#define NUM_BINS 380
double Datos[NUM_BINS];

void setup()
{
  Serial.begin(9600);
  //GD.begin();            //for testing with the TFT NHD FT813 5"

  analogReadAveraging(4);
  AudioMemory(30);
  fft1024_2.windowFunction(AudioWindowWelch1024);
 
}

void loop()
{
  if (fft1024_2.available())
  {
    for (int i=0; i < NUM_BINS; i=i+1)
    {
      Datos[i] = fft1024_2.read(i)*10000;
      if (Datos[i]<=0){Datos[i]=0;}
      Serial.println(Datos[i]);
    }

  }
}
 
The first thing is to condition the audio signal so that information about its behavior is not lost. This circuit to condition the audio signal on pin A2 of your teensy is a good start.

u4QxCso.png


Try this code:
Code:
#include <Audio.h>

AudioInputAnalog         adc1;   //    A2 pin teensy 4.1
AudioAnalyzeFFT1024      fft1024_2;
AudioOutputI2S           i2s1;
AudioConnection          patchCord3(adc1, fft1024_2);

//#include <GDSTx.h>    //for testing with the TFT NHD FT813 5"

#define NUM_BINS 380
double Datos[NUM_BINS];

void setup()
{
  Serial.begin(9600);
  //GD.begin();            //for testing with the TFT NHD FT813 5"

  analogReadAveraging(4);
  AudioMemory(30);
  fft1024_2.windowFunction(AudioWindowWelch1024);
 
}

void loop()
{
  if (fft1024_2.available())
  {
    for (int i=0; i < NUM_BINS; i=i+1)
    {
      Datos[i] = fft1024_2.read(i)*10000;
      if (Datos[i]<=0){Datos[i]=0;}
      Serial.println(Datos[i]);
    }

  }
}
Thanks for the info. I have made the conditioning circuit and have connected it to the input. I get a lot of numbers on the screen, but nothing seems to change when a sound signal is directed to the input. Can you please elaborate on how to get it to work and what is supposed to happen when it is working? Thanks.
 
I just have the conditioner installed on the teeny 4.1. The audio signal comes from the PC, from a 3.5 mm output.

In the screenshot you can see the result from the serial plotter of the Arduino IDE, 4 audio-files are played simultaneously with signals of 500 Hz, 1.25 Khz, 1.6 Khz and 2.0 Khz.

test 1.jpg


This is the base noise signal
test 1_ruido.jpg
 
Last edited:
I just have the conditioner installed on the teeny 4.1. The audio signal comes from the PC, from a 3.5 mm output.

In the screenshot you can see the result from the serial plotter of the Arduino IDE, 4 audio-files are played simultaneously with signals of 500 Hz, 1.25 Khz, 1.6 Khz and 2.0 Khz.

View attachment 37053

This is the base noise signal
View attachment 37054
Thanks for the info. Mine doesn't work like that. In fact, if I connect the conditioning circuit directly to a speaker, I get no sound, whereas if I put the input directy to the speaker, I do. I have carefully checked that I made the circuit as in your diagram. Is it possible to use it without the conditioning circuit just to see if it works at all? Thanks.
 
I built the conditioner with SMD components, I didn't have a 2.2K resistor on hand, I had a 2.4K one, I don't think it affects the resulting signal too much. I used ceramic capacitors and a 3.5mm stereo adapter.

Check the wiring again, a couple of times I didn't get a response, I took some time to connect each component little by little

Acondicionador.jpg
FFT_audio.jpg


The plate is a bit crude but it works 😁
 
Last edited:
You can't drive a speaker direct from a line-level audio signal, speakers are 8 ohm, line level is 50k or 100k...

(Or do you mean a powered speaker?)

And you certainly shouldn't try to drive a speaker direct from a logic pin, that can blow up your Teensy as speakers are effectively a dead-short viewed from a microcontroller - very low impedance.
 
I built the conditioner with SMD components, I didn't have a 2.2K resistor on hand, I had a 2.4K one, I don't think it affects the resulting signal too much. I used ceramic capacitors and a 3.5mm stereo adapter.

Check the wiring again, a couple of times I didn't get a response, I took some time to connect each component little by little

View attachment 37075 View attachment 37076

The plate is a bit crude but it works 😁
Thanks for the tip. So far I'm just using a breadboard. I was using capacitors with "10" printed on them which I had assumed was 10 microfarads, but it seems that was not the case. I replaced those with 2 pairs of 22 microfarad electrolytic capactiors in series (I didn't have any 10 microfarad ones) and now at least can hear the sound.

I have tried it again with the Teensy but no luck, which brings me back to my first question. What is the input pin I should be using? I know it's A2, which I have interpreted as pin 16 on the actual board (Teensy 4.1). Is that correct?

Thanks.
 
BTW that conditioning circuit looks wrong to me, asymmetrical. Change the 2k2 to 10k as well, then the signal will be mid-rail for the ADC.
 
MarkT, already on the topic and appealing to your experience in this type of projects, then what would be the correct way to take the audio signal from one of the 3.5 mm outputs of the PC motherboard, to process it on pin A2 of a teensy 4.1 board.

Is the conditioning circuit we have talked about not complete? Is any other component needed?

Since the same circuit seems to work well for me, but not for dragoncat.
 
MarkT, already on the topic and appealing to your experience in this type of projects, then what would be the correct way to take the audio signal from one of the 3.5 mm outputs of the PC motherboard, to process it on pin A2 of a teensy 4.1 board.

Is the conditioning circuit we have talked about not complete? Is any other component needed?

Since the same circuit seems to work well for me, but not for dragoncat.
That circuit works for me now, as I said. The problem was the capacitors I am using. If I put input into that circuit, the output of the circuit connected to a speaker yields the sound as expected. I now assume that part is ok. However, the input to the Teensy 4.1 seems to be the problem now. I might just be using the wrong input pin. I would appreciate some clarification in this regard, as the pinout isn't completely clear, and not even consistent across different websites.
 
Audio input GND must be common to GND of the conditioning circuit and GND of the Teeny 4.1. The audio input to the teensy 4.1 is pin A2
 
Thanks for all the help. I am able to do what I originally wanted to start with, which is to direct the input to the output. I never got the fft output working as expected, perhaps because I don't really know how to control the serial plotter.

For anyone who might want an answer to the question I asked, the pin on the Teensy 4.1 that corresponds to the A2 pin is indeed pin 16 (since I don't think anyone actually confirmed that for me in this thread).

Even with the conditioning circuit, it's pretty noisy, but it's a start, and since I am ultimately going to use it with extremely high level signals, the noise probably doesn't matter.
 
Back
Top