Skip to content

Fix(I2S example): make fix to the ESP32 I2S simple tone example #10954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some edit
  • Loading branch information
greenyleaf committed Mar 22, 2025
commit fa899cde5208708dc6bb43d40ea3612d5527f23f
13 changes: 8 additions & 5 deletions libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
2nd September 2021
Lucas Saavedra Vaz (lucasssvaz)
22nd December 2023
anonZ
anon
10nd February 2025
*/

#include <ESP_I2S.h>

// In fact, the GPIO pins are not fixed, most other pins can be used for the I2S function.
// The GPIO pins are not fixed, most other pins can be used for the I2S function.
#define I2S_LRC 25
#define I2S_BCLK 5
#define I2S_DIN 26
Expand All @@ -43,7 +43,7 @@ i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT;
i2s_mode_t mode = I2S_MODE_STD;
i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO;

const int halfWavelength = (sampleRate / frequency / 2); // half wavelength of square wave
const int halfWavelength = sampleRate / frequency / 2; // half wavelength of square wave

int32_t sample = amplitude; // current sample value
unsigned int count = 0;
Expand All @@ -70,9 +70,12 @@ void loop() {
sample = -1 * sample;
}

i2s.write(sample); // Right channel
// Right channel, low 8 bit then hight 8 bit
i2s.write(sample);
i2s.write(sample >> 8);
i2s.write(sample); // Left channel

// Left channel, low 8 bit then hight 8 bit
i2s.write(sample);
i2s.write(sample >> 8);

// increment the counter for the next sample
Expand Down