---+ The T-Watch 2020 sound system The t-watch has an integrated loudspeaker which is be driven by a [[https://cdn-shop.adafruit.com/product-files/3006/MAX98357A-MAX98357B.pdf][MAX9835a ]]PCM Input Class A Audio Power Amplifier. This system allows us to play wav files on the t-watch. The MAX9835a uses !I2S communication invented by Philips in the late 1980 ies for the transfer of digital sound samples. The protocol uses 3 signals:<br /><br /> | *signal name* | *pin name in the programs* | *GPIO used on t-watch* | *signification* | | BCLK | bck_pin | 26 | bit clock | | Din | sdout_pin | 33 | sound data | | LRCLR | ws_pin | 25 | left right clock<br />used to switch between left and right channel<br />for stereo sound | The MAX9835a is a mono decoder, taking digital sound data (we use 16 bits per sample), converts them to an analogue signals which is amplified and fed into the loudspeaker. ---++ The software We use the [[https://github.com/micropython/micropython/pull/4471][I2S driver]] developed by M. Teachman. Unfortunately this driver has not been integrated into the !MicroPython sources and a few modifications to the ESP32 port must be made to include it: * first the driver itself (machine_i2s.c) must be copied to ports/esp32 * <verbatim>{ MP_ROM_QSTR(MP_QSTR_I2S), MP_ROM_PTR(&machine_i2s_type) },</verbatim> must be included into * <verbatim>STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {</verbatim> in modmachine.c * <verbatim>extern const mp_obj_type_t machine_i2s_type;</verbatim> must be included in modmachine.h * <verbatim>machine_i2s.c \</verbatim> must be added to the C sources SRC_C<br />in the Makefile in order to compile the module into the !MicroPython binary. With this new !MicroPython binary you should be able to <verbatim>import machine.I2S</verbatim> ---++ Enabling the sound system In the t-watch the MAX9835a is powered through the AXP202 power manager and the power line to the sound chip must be enabled before using it. Here is the initialization procedure I use: <literal>from machine import Pin,I2S<br />import ttgo<br />from axp_constants import AXP202_VBUS_VOL_ADC1,AXP202_VBUS_CUR_ADC1,AXP202_BATT_CUR_ADC1,AXP202_BATT_VOL_ADC1<br /><br />watch = ttgo.Watch()<br />watch = watch<br />tft = watch.tft<br />power = watch.pmu<br />power.adc1Enable(AXP202_VBUS_VOL_ADC1<br /> | AXP202_VBUS_CUR_ADC1 <br /> | AXP202_BATT_CUR_ADC1<br /> | AXP202_BATT_VOL_ADC1, True)<br />watch.lvgl_begin()<br />watch.tft.backlight_fade(100)<br /><br />print("enable power")<br />watch.enable_audio_power()<br /><br /></literal> Mike Teachman's example programs with the power initialization added in, have been uploaded to [[https://github.com/uraich/twatch2020_firmware/tree/main/hardware/sound][https://github.com/uraich/twatch2020_firmware/tree/main/hardware/sound.]] Before running these however you should create a directory /wav on the ESP32 file system and copy the sound file https://github.com/miketeachman/micropython-esp32-i2s-examples/blob/master/wav_files/taunt-16k-16bits-mono-12db.wav to this directory. -- %USERSIG{UliRaich - 2021-01-25}% ---++ Comments %COMMENT%
This topic: IoT_Course_English
>
WebHome
>
TheT-watch2020Hardware
>
T-watchSound
Topic revision: r1 - 2021-01-25 - UliRaich
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback