joba-1 / PicoW_A2DP

Bluetooth A2DP Sink to I2S/DAC on a Raspberry Pico W
8 stars 3 forks source link

doesn't work with MAX 98357A I2S AMP #2

Open CodKid1710 opened 9 months ago

CodKid1710 commented 9 months ago

I am trying to make a pair of bluetooth headphones with the pico w and the MAX 98357A I2S AMP if anyone knows what code i should use plz tell me, I have tried both A2dp by raspi and joba, i've tried HFP HS and AG, if anyone has suggestion plz tell me

joba-1 commented 9 months ago

my suggestion is to provide details. I don’t see anything that cannot work in your general description so it must be in the details

CodKid1710 commented 9 months ago

nevermind i got it working, i needed two put into 5v, and make sure the contact points are touching. should i connect the speaker with a resistor? it is also a bit fuzzy, do you know why, could it be from contact points, the i2s, or the pico w, i am linking a video down below!

https://github.com/joba-1/PicoW_A2DP/assets/140189732/e5a7d5a1-da94-4823-bd80-07ef8ad68948

CodKid1710 commented 9 months ago

also the fuzz gets worse when you play songs with words

CodKid1710 commented 9 months ago

also sometimes it gives me a high buzz

joba-1 commented 9 months ago

the datasheet of the amp says it wants speakers with resistance of about 4-8 ohm. These are normal values for speakers. If in doubt, measure or look into the speaker datasheet. No extra resistors are required.

joba-1 commented 9 months ago

The sound should be perfect. No buzz or clicks or whatever.

These sound problems usually come from wrong i2s settings (like bit rate, sample size, pcm format)

CodKid1710 commented 9 months ago

on the back of my speaker, it 8 ohms, and 0.5W. The bit rate is set (on the pico) to 46000 i don't know the sample size, where would i change that and what should i change it to? idk what the PCM format is. either, maybe you document it (how to use the program) more, or make a youtube video about it, cause there isn't much

also this is really cool thanks for coding, creating, and publishing it

joba-1 commented 9 months ago

Do you use my code as is? I just reviewed it and cannot find how the i2s sample rate is selected. Some parameters are hardcoded and some are set dynamically by btstack and. Usually for a2dp this will result in 44100 samples/s and one sample is 2 channels of signed 16bit integers. Currently I think it is most likely an issue of hardware configuration/connection of the MAX 98357A. I have one of those so I could test here if you tell me what you did (best by also adding a photo of the pico<->max connections)

P.S.: I just commited some changes, but they are not releted.

P.P.S: I have those boards: image same? On the back it says 3W, so your speaker might not be up to full volume sine waves. Using a resistor might be safer.

joba-1 commented 9 months ago

maybe you document it (how to use the program) more, or make a youtube video about it, cause there isn't much

I'm aware the "documentation" is very sketchy, basically just minimal notes I would need to rebuild this in the future. Feel free to add what you think is missing for an "outsider". In case you are not familiar with the process: fork my repo to your github account, git clone your forked repo to your pc, make any changes locally (like comments in code or adding to the readme or whatever...), git commit and git push changes to your repo, open a pull request (github will recommend a link to do that).

CodKid1710 commented 9 months ago

i installed the latest pico sdk, and extras (from raspberry pi), compiled them with cmake version 3.27.8, installed the sub modules. downloaded your code compiled it with the same cmake version. Then i held the bootsel button on the pico w, put a flash_nuke.uf2 on to delete any previous program, after i put picow-a2dp.uf2 on the pico, i did NOT change any code.

An image of my set up 20240105_084432

flash nuke uf2 file (Compressed) flash_nuke.zip

pico w a2dp uf2 and elf file (Compressed) picow-a2dp.zip

CodKid1710 commented 9 months ago

the speaker ground wire broke, so i soldered another wire on to it, but i have tested it via a wire, and it works fine

joba-1 commented 9 months ago

You mean the speaker works, but still distorted, right? It looks like you omitted a wire for LR on the right. It is always PICO_AUDIO_I2S_CLOCK_PIN_BASE + 1, due to how pio code for i2s is implemented for the pico, so if I see this correctly on your pic. It should lead to the pico pin/hole between the green and blue cable (GP11).

I verified the board is working. Just listening to Jack White :)

image

I hear some crackling but that is due to the miserable dupont wire connection...

joba-1 commented 9 months ago

Regarding the broken speaker wire: moving solder connections quickly breaks them. I always fix the wires at the magnet with glue or tape...

My speaker has 0.5W as well. No problem with full gain and full volume so far...

joba-1 commented 9 months ago

For the optional pins SD and Gain look at tables 5 and 8 in the datasheet https://www.analog.com/media/en/technical-documentation/data-sheets/max98357a-max98357b.pdf

They select max volume and the stereo channel (or mix) you hear on the speaker

CodKid1710 commented 9 months ago

is the LR wire necessary, the max98257A is a mono amp

joba-1 commented 9 months ago

Yes it is necessary. I agree it is a bit strange at first. But it makes perfect sense if you look at page 31 of the datasheet I linked above. The amp takes a stereo stream but only takes the left or right (or a mix channel or mutes) depending on SD voltage. This way you can use 2 identical mono amps taking the same I2S stream over the same pins/wires and get stereo.

I also tried and unplugged LR. I get distorted sound...

joba-1 commented 9 months ago

Having said that, SD is probably not optional as I wrote above. See the table 5. On Page 18 it looks like it is internally pulled to ground (e.g. muted according to table 5). Better connect it to high...