Skip to content
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

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

Open
DonvdH opened this issue Aug 28, 2023 · 10 comments
Open

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

DonvdH opened this issue Aug 28, 2023 · 10 comments

Comments

@DonvdH
Copy link

DonvdH commented Aug 28, 2023

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?

@jeffmer
Copy link
Owner

jeffmer commented Aug 28, 2023

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.

@DonvdH
Copy link
Author

DonvdH commented Aug 28, 2023

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?

@jeffmer
Copy link
Owner

jeffmer commented Aug 29, 2023

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.

@DonvdH
Copy link
Author

DonvdH commented Sep 1, 2023

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..

@thiswillbeyourgithub
Copy link
Contributor

Hey. I too have a V3 and am super pumped (#1 (comment)) 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?

@jeffmer
Copy link
Owner

jeffmer commented Sep 3, 2023

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.

@DonvdH
Copy link
Author

DonvdH commented Sep 3, 2023

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)

@jeffmer
Copy link
Owner

jeffmer commented Sep 4, 2023

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.

@thiswillbeyourgithub
Copy link
Contributor

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.

@DonvdH
Copy link
Author

DonvdH commented Sep 10, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants