Serial monitor not working with I2S - also I2S coding help

Hi,

I am currently working on a Zero-based I2S output guitar effects pedal.


This is the circuit diagram. This doesnt include a wire that was added, linking from where Radd3/Radd4 combine, to A5 to measure the output.

When I upload the following code, there is no output to the serial monitor.

#include <I2S.h>
void setup() {
 Serial.begin(115200);
 I2S.begin(I2S_PHILIPS_MODE, 44100, 8);

if (!I2S.begin(I2S_PHILIPS_MODE, 44100, 8)) {
    SerialUSB.println("Failed to initialize I2S!");
    while (1); // do nothing
  }
  int input = 0;
  int output = 0;
  analogReference(AR_DEFAULT); // Set Reference to 3.3V (Default on Zero)
  analogReadResolution(8); // Set Bit-depth to 8 (required for use of measurement on coolterm)

  pinMode(A3, INPUT); // Set input pins
  pinMode(A5, INPUT);
  pinMode(0, LOW); // Set pin 0 to output 0V so that FS is always outputting to one side
}

void loop() {
  int input = analogRead(A3);
  int buff = 0;
   buff = I2S.available(); // I2S buffer data size 
   int I2Ssample[buff]; // Buffer 
  for (int i = 0; i <= buff; i++) {
    I2Ssample[i] = analogRead(A3); //populate buffer
  }
   I2S.write(I2Ssample, buff);
  delayMicroseconds(1);
  int output = analogRead(A5);
  Serial.println(input);
}

It is being run at 8-bit because I had been using coolterm to record the serial data, so that I could create a plot of it in MATLAB.

I know that the serial connection is fine because when I upload the following simplified sketch, I can accurately monitor the input:

#include <I2S.h>
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  analogReadResolution(16);
  I2S.begin(I2S_PHILIPS_MODE, 44100, 16);
  I2S.begin(I2S_PHILIPS_MODE, 16);
  pinMode(A3, INPUT);
  pinMode(0, HIGH);
}

void loop() {
int in = analogRead(A3);
int out = analogRead(A5);
I2S.write(in);
delayMicroseconds(10);
SerialUSB.println(out); //can be changed to monitor in
}

With this sketch, there is no audio output (output from DAC stays at around 37500/1.9V +-noise) but a measurable guitar input, implying that there is a problem with the code. But with the first sketch I cant actually diagnose where the issue is due to not having the serial monitor/plotter.

Any help with the serial monitor issue or the code would be greatly appreciated.

Thanks!

Should this be SerialUSB ?

Other than that, I got nothing.

Sorry, it should be, yes (I forgot to change it back), but it still doesnt fix it.

Maybe try this chunk as:

while (!I2S.begin(I2S_PHILIPS_MODE, 44100, 8)) {
    SerialUSB.println("Failed to initialize I2S!");
    delay (500); // do nothing
  }

Unfortunately it isnt making a difference...

How about try to isolate it more with a few lines like:

#include <I2S.h>
void setup() {
 Serial.begin(115200);
 Serial.print("A");delay(500);
 I2S.begin(I2S_PHILIPS_MODE, 44100, 8);
 Serial.print("B");delay(500);

if (!I2S.begin(I2S_PHILIPS_MODE, 44100, 8)) {
    SerialUSB.println("Failed to initialize I2S!");
    while (1); // do nothing
  }
 Serial.print("C");delay(500);
...

Or with SerialUSB or whatever...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.