Teensy I2S audio input

I am trying to output audio from an RN-52 to a Teensy 4.0 with an audio shield (though I’m not sure if the shield is necessary). I am running FFT on the audio and I have gotten it working (not reliably) with one speaker output from the RN-52 to the audio shield’s line in, but this only captures one channel of audio. If I connect both, the RN-52 quickly shuts down for some reason.

So I thought I2S might be the way to go. I have tried everything to think of to get the I2S connection working but I just can’t figure it out and there is no other clear guide online for how to do so, including the Teensy audio design tool. I connected the wires on the Teensy as instructed and connected them to the PCM pins in every combination but I can’t get any FFT reading.

The code I’m using that has produced FFT before but isn’t now for some reason is:

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

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=390,442
AudioAnalyzeFFT256       fft256_1;       //xy=762,463
AudioConnection          patchCord1(i2s1, 0, fft256_1, 0);
AudioConnection          patchCord2(i2s1, 1, fft256_1, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=520,292
// GUItool: end automatically generated code

const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;

void setup() {
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(12);

  // Enable the audio shield and set the output volume.
  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(myInput);
  sgtl5000_1.volume(0.5);

  // Configure the window algorithm to use
  fft256_1.windowFunction(AudioWindowHanning1024);
  //fft256_1.windowFunction(NULL);

  // Create a synthetic sine wave, for testing
  // To use this, edit the connections above
  // sinewave.amplitude(0.8);
  // sinewave.frequency(1034.007);
}

void loop() {
  float n;
  int i;

  if (fft256_1.available()) {
    // each time new FFT data is available
    // print it all to the Arduino Serial Monitor
    Serial.print("FFT: ");
    for (i=0; i<40; i++) {
      n = fft256_1.read(i);
      if (n >= 0.01) {
        Serial.print(n);
        Serial.print(" ");
      } else {
        Serial.print("  -  "); // don't print "0.00"
      }
    }
    Serial.println();
  }
}

Ultimately I just need to do FFT on Bluetooth audio. I asked about this in the other thread, but the ESP32 route seems just as difficult from my amateur perspective. That said, if you think that is easier, I’m willing to eat the cost of these boards. I just need something that works.

Thank you in advance for your guidance!

Is anything wired to the I2S input? If so, disconnect that wire

I2S can be tricky, here’s a checklist to run through/test against, see how it treats ya

The I2S output pin on the RN-52 is connected to the I2S input pin on the Teensy. Isn’t how the data gets from one to the other?

Thank you for the link to the AI response, but I’m not sure how valid it is given that I haven’t been able to find anyone else doing this thing (despite its claims to have helped dozens of people). The first few commands also seem mistaken.

S|,          // restore factory defaults

According to what I guess is the official guide (https://www.microchip.com/content/dam/mchp/documents/OTH/ProductDocuments/DataSheets/rn-bt-audio-ug-2.0r.pdf) this command routes the audio (though this is a useful hint to getting I2S output). SF,1 does a factory reset.

SP,0         // I²S master mode (RN-52 drives BCLK/LRCLK)

This seems like it will actually set the password to 0. As far as I can tell, the RN-52 is always the I2S master.

By asking a human, I was hoping to get a validated response. I know forum moderators have their work cut out for them though, so I appreciate your quick responses!

I am trying to get the I2S working using the I2S converter/amplifier I bought from you all before looping in the Teensy to make sure the RN-52 is working properly. Some of the information I stumbled on when checking the AI responses was able to produce some noise from the speaker but not music as expected, so something is happening at least. I will upload photos of the setup in a bit to see if we can figure out what’s going on.

Thank you again for your responses!

Are the ground pins connected on both devices as well?

Good question! Yes they are. It started to work thankfully, but the RN-52 keeps shutting down. I have two of the Sparkfun breakouts and they both shut down quickly, usually within 30 seconds. I don’t see any documentation about auto shutdowns and I can’t otherwise figure out what would be causing it.

Can you make a short video of the behavior and share it? Youtube links work well

Sorry for the delay! An update is below, but I am trying to get the FFT library working on an ESP32 I found that I had lying around! I appreciate the help provided here and understand that it’s kindly provided freely, but if I need more in-depth help, do you have rates?

Update for those interested:

I can connect my phone to the RN-52 module by Bluetooth just fine but whenever I try to play music, the speaker crackles and the RN-52 resets. I am powering the RN-52 through a buck converter. The buck converter I2S amplifier are directly powered from the power supply. I thought voltage drop might be an issue, but I monitored it from my multimeter and I don’t think that’s the case. I have a second RN-52 breakout that behaves the same way.

When I connect the speaker directly to the RN-52’s speaker outputs, I hear the startup tone and connection tone when I connect via Bluetooth. However, immediately when I start to play music, the RN-52 resets.

No one else is having the same problem as far as I can tell so I guess the error must be on my part.

1 Like

We don’t but sites like Fiverr, Upwork and similar probably have some folks that can help ya :smiley:

Thank you, I’ll follow up there!

I also want to say thank you again for your patient help. I can only imagine how hard it can be to answer vague, poorly structured questions over and over, but you and other people like you that run these forums are absolutely critical to opening up this area to lay people like me. This is an area I have really fallen in love with and it’s great to be able to get help when I need it!

2 Likes