EasyManuals Logo

Adafruit ESP32-S3 User Manual

Adafruit ESP32-S3
263 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #178 background imageLoading...
Page #178 background image
import audiobusio
audio = audiobusio.I2SOut(board.A0, board.A1, board.A2)
tone_volume = 0.1 # Increase this to increase the volume of the tone.
frequency = 440 # Set this to the Hz of the tone you want to generate.
length = 8000 // frequency
sine_wave = array.array("h", [0] * length)
for i in range(length):
sine_wave[i] = int((math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15
- 1))
sine_wave_sample = audiocore.RawSample(sine_wave)
while True:
audio.play(sine_wave_sample, loop=True)
time.sleep(1)
audio.stop()
time.sleep(1)
Now you'll hear one second of a 440Hz tone, and one second of silence.
You can try changing the 440 Hz of the tone to produce a tone of a different pitch.
Try changing the number of seconds in time.sleep() to produce longer or shorter
tones.
I2S WAV File Playback
The second example plays a WAV file. You open the file in a readable format. Then,
you play the file and, once finished, print Done playing! to the serial console. You
can use any supported wave file().
Update your code.py to the following.
Click the Download Project Bundle button below to download the necessary libraries
and the code.py file in a zip file. Extract the contents of the zip file, open the folder
that matches your CircuitPython version, and copy the StreetChicken.wav file and the
code.py file to your CIRCUITPY drive.
Your CIRCUITPY drive should now look similar to the following image:
©Adafruit Industries Page 178 of 263

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit ESP32-S3 and is the answer not in the manual?

Adafruit ESP32-S3 Specifications

General IconGeneral
Microcontroller/ChipESP32-S3
Clock Speedup to 240 MHz
RAM512 KB
Flash Memory8MB
GPIO Pins45
DAC Channels2
Operating Voltage3.3 V
Input Voltage5 V
I2C2
I2S2
CPUXtensa LX7 dual-core
Wi-Fi802.11 b/g/n
BluetoothBluetooth 5.0

Related product manuals