TTGO-T-watch-2020-Micropython-OS icon indicating copy to clipboard operation
TTGO-T-watch-2020-Micropython-OS copied to clipboard

Unable to play audio on the Lilygo T-Watch 2020 V3

Open DonvdH opened this issue 2 years ago • 10 comments

This is a great project and I really like how easy it is to add custom watch faces, apps and utils.

However, I appear to be unable to play audio on the Lilygo T-Watch 2020 V3 via the MAX98357.

I have tried various options, without succes. Also when I run misc/play_tone.py, no sound is being produced.

Is this a known issue? Or is my unit perhaps defective?

DonvdH avatar Aug 28 '23 20:08 DonvdH

Hi,

Thanks for the kind words. I have not done much with the audio and my test was on a V1 watch. I notice that on a V3 watch, the audio module is on a different power bus LDO4 as opposed to LDO3. So you would need to change the power manager line

pm.setPower(0x06, 1)

to

pm.setPower(0x03, 1)

and then it should work.

jeffmer avatar Aug 28 '23 21:08 jeffmer

Thanks a lot for your quick response!

That appears to be correct indeed. However, even with this change I'm unfortunately still not getting any sound..

Have you got any other ideas about what might be wrong?

DonvdH avatar Aug 28 '23 22:08 DonvdH

Just tried play_tone.py on a V1 - I do not have a V3 - and it worked fine.

I deleted the line import loader in boot.py and then reset the watch using machine.reset(). Then I simply ran play_tone.py from Thonny.

jeffmer avatar Aug 29 '23 16:08 jeffmer

Thank you for testing! Unfortunately this doesn't work for me.

I have contacted the supplier and they asked me to run this test firmware: https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library/blob/master/bin/2020-V3_Speaker.bin Flashed with: esptool --chip esp32 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m 0x0 2020-V3_Speaker.bin

The test firmware plays audio succesfully, so my unit isn't defective.

I am overlooking something, but I have no idea what it might be..

DonvdH avatar Sep 01 '23 14:09 DonvdH

Hey. I too have a V3 and am super pumped (https://github.com/jeffmer/TTGO-T-watch-2020-Micropython-OS/issues/1#issuecomment-1574963539) about using microphone and audio on my watch.

I somehow was not aware of the play_tone.py file so I played a bit with it.

I can report that indeed it does not work on the V3 BUT :

I tried anything and everything, changing values left and right to try to infer what's wrong. Well somehow it started making the sound (!) but I noticed that I had actually reverted to the initial code.

My conclusion is that the current file works on V3 (after modifying the pin of course) but there's something about it that is not stateless. I don't understand what I did that "reset" god knows what to a functionnal state.

Where to go from here? Any idea?

thiswillbeyourgithub avatar Sep 03 '23 14:09 thiswillbeyourgithub

Maybe try resetting the device at the start by using LD04 to power it up, then off then on again with a delay in between.

jeffmer avatar Sep 03 '23 14:09 jeffmer

Thank you both for the valuable comments.

I started thinking about the difference between the T-Watch v1 and v3, which is essentially the power domain being used.

The AXP202 datasheet mentions the following: Watch V1 uses LDO3: 200mA with Voltage from 0.7V to 3.5V and 25mV/step Watch v3 uses LDO4: 200mA Low Noise with voltage from 1.8V to 3.3V and 100mV/step

So the voltage ranges differ.

The code in drivers/axp202.py is only enabling the power domain and doesn't appear to set a voltage, it is then unclear which voltage is being used.

Sound started working after I modified init() in drivers/axp202.py to include the following:

  if VERSION == 3:
        # Set correct voltage on LDO4 to enable speaker
        # Example used from setLDO4Voltage() in https://github.com/lewisxhe/AXP202_PythonLibrary/blob/master/axp202.py
        data = self.readByte(0x28) # AXP202_LDO24OUT_VOL
        data = data & 0xF0
        data = data | 15 # Set 3300MV
        self.writeByte(0x28, data)
        self.setPower(EXTEN, 0)
        self.setPower(LD04, 0)

DonvdH avatar Sep 03 '23 23:09 DonvdH

Glad you got this to work and many thanks for the solution - I will update code to incorporate this when I get a chance. In the meantime, I have put a note in the README referencing your post.

jeffmer avatar Sep 04 '23 10:09 jeffmer

Thanks a lot @DonvdH

I've been trying for a while to get the microphone working. Would you be interested in trying to make it work? I kmow python but very little hardware.

thiswillbeyourgithub avatar Sep 04 '23 11:09 thiswillbeyourgithub

@jeffmer: Thanks. The code I included previously works well and I believe it can be integrated as it is.

To save other people some time, here is a code example to play a wav file from an online source (I'm personally fetching data from a text to speech API): import urequests from machine import I2S from machine import Pin from tempos import pm pm.setPower(0x03, 1) bck_pin = Pin(26) # Bit clock output ws_pin = Pin(25) # Word clock output sdout_pin = Pin(33) # Serial data output response = urequests.get('http://example.com/sound.wav') wavarray = bytearray() wavarray.extend(response.content) response.close() #Adjust the shift parameter to increase or decrease the volume I2S.shift(buf=wavarray, bits=16, shift=1) # Positive for left shift (volume increase by 6dB), negative for right shift (volume decrease by 6dB). audio_out = I2S(0, sck=bck_pin, ws=ws_pin, sd=sdout_pin, mode=I2S.TX, bits=16, format=I2S.MONO, rate=24000, ibuf=2048) audio_out.write(wavarray) pm.setPower(0x03, 0)

@thiswillbeyourgithub: If you open a separate issue regarding the microphone I will share my initial findings, but I don't think it will be easy because Micropython appears to be lacking PDM support and polling the pin using Python is probably not fast enough to obtain proper audio data. Circuitpython does support PDM, so perhaps this could be ported if someone would be willing to do this.

DonvdH avatar Sep 10 '23 11:09 DonvdH