create new tag
view all tags

The T-Watch 2020 sound system

The t-watch has an integrated loudspeaker which is driven by a 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:

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
used to switch between left and right channel
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 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
  • { MP_ROM_QSTR(MP_QSTR_I2S), MP_ROM_PTR(&machine_i2s_type) },
    must be included into
  • STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
    in modmachine.c
  • extern const mp_obj_type_t machine_i2s_type;
    must be included in modmachine.h
  • machine_i2s.c \
    must be added to the C sources SRC_C
    in the Makefile in order to compile the module into the MicroPython binary.
With this new MicroPython binary you should be able to
import machine.I2S

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:  

from machine import Pin,I2S
import ttgo
from axp_constants import AXP202_VBUS_VOL_ADC1,AXP202_VBUS_CUR_ADC1,AXP202_BATT_CUR_ADC1,AXP202_BATT_VOL_ADC1

watch = ttgo.Watch()
watch = watch
tft = watch.tft
power = watch.pmu
                      | AXP202_VBUS_CUR_ADC1
                      | AXP202_BATT_CUR_ADC1
                      | AXP202_BATT_VOL_ADC1, True)

print("enable power")

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.

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.

-- Uli Raich - 2021-01-25


Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2021-01-27 - UliRaich
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback