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

chat #10

Open
visualapproach opened this issue Jul 11, 2017 · 187 comments
Open

chat #10

visualapproach opened this issue Jul 11, 2017 · 187 comments

Comments

@visualapproach
Copy link
Owner

put your comments or questions here

@visualapproach
Copy link
Owner Author

Check the cables extra carefully that comes with the BT Module! Red and black power wires may or may not be reversed. I've seen both...

@rysatko
Copy link

rysatko commented Oct 17, 2017

Hello Thomas.
First of all I would like to thank you for your work. This is awesome project.
I tried to make my own dongle (for now only AUX-in, CSR8645 is on the way from china). But I managed to work it only once - both SAT and CD-CHGR. Then it showed SAT ERROR and since that time my HU850 (with 6CD built in) does not recognize it. I tried all your SW versions and also SW from Vincent, but no luck. Could you please go through the troubleshooting with me? When I open serial monitor, it tells only "Calling HU" and then plain lines only. After uploading Vincents SW it tells "not in sync".
HW side should be fine. I measured all connections several times and everything is OK.

@visualapproach
Copy link
Owner Author

Hi and thank you for joining!
My first guess would be the power supply. The car electric power is very noisy and that can cause problems. I had some communication errors too when I switched from using the RUN wire as power supply to using 12v from the cigarette lighter. It was solved by NOT using the cig lighter as a GND-point, but using the shielded cable's shield. See picture below. The reason I didn't use RUN is that it couldn't deliver enough amps for my project. At least not consistantly. In the pic below I haven't included protection against backpowering. It can be done with a resistor and a transistor (see master thread) or several other ways. I really recommend the ground loop isolator also. It is worth the money (I think 20 €-ish)!

csr8645_v2

@rysatko
Copy link

rysatko commented Oct 17, 2017

For now my HW is built exactly iaw the drawing in master thread. So I am taking +12V from RUN and it is grounded by pin #2. Plus I added 8205 voltage regulator because the regulator on my chinese Arduino seems a bit crappy and I measured only 2V on the 5V pin. So I hope that the solution is so easy as you suggest. I will let you know asap. :)
Btw. ground loop isolator is also on the way.

@visualapproach
Copy link
Owner Author

Fingers crossed :-)
I think you could try to power it with a powerbank via USB. (Easier than resoldering stuff for a test)

I wonder if it's the voltage regulator or if RUN is not coping...

@rysatko
Copy link

rysatko commented Oct 17, 2017

So it is connected to the lighter socket. But no change for now. I am taking my computer to the car and we will see..

@rysatko
Copy link

rysatko commented Oct 17, 2017

Nothing again. HU does not recognize it. :(

@visualapproach
Copy link
Owner Author

Ok... did you try driving the arduino from the computer ONLY? (Disconnect 12v cig and 12v RUN, and connected GND through DIN cable)

@visualapproach
Copy link
Owner Author

Do you get any text except "calling HU"? If not then I suspect the main init sequence is not performed successfully. Maybe it doesn't pull the busy line low enough? And confirm your arduino is 5v 16MHz. The 3.3v 8 MHz won't do. It might be helpful if you post some pics on your device.

@rysatko
Copy link

rysatko commented Oct 17, 2017

I am sure, that it is 5V arduino. As I told you, it worked for 2 days. I can see text "calling HU" in serial monitor. Now I am going to desolder GND and take it to car again, this time powered from powerbank only.

@visualapproach
Copy link
Owner Author

Ok. It can be really frustrating and take a lot of time finding what's causing the trouble. But since it has worked something must have happened. Which means it is not likely software. So either something broke physically or electronically. Several times I have been certain it was a bug in my program, but it always ended up beeing a loose wire, or bad ground or similar. It's difficult to say what's wrong in your case and all I can offer at this point is some generic recommendations:
-check voltages and resistances with a multimeter (like is 12v OK even when under load? Same for 5v. Is GND resistance to HU chassi almost 0 Ohms? Recheck DIN connector, it's prone to bending and in a tight space there is a risk of shorts.
-make another visual inspection of the cables. Look for shorts or open circuits in the cables and under/over the PCB.
-do not use extremely long wires/cables.
-when in doubt, reduce to simplest possible circuit and check functionality. (only arduino, powered from battery)
-get a couple of beers and sleep on it. Repeat this step if necessary.

@rysatko
Copy link

rysatko commented Oct 17, 2017

The last step would be the best :D
No succes with power only from USB. Only "conn" or "calling HU" messages.
To go through hints you gave me:

  • Resistances checked, everything is fine. Voltages not yet, only on table when powering it from 12V PC power source - was ok. Bending of DIN is not my case, because I am trying it with HU pulled from dashboard.
  • I have done inspection for shorts with ohm meter - ok
  • Longest wire is approx 0,5m cable to DIN and 1,5m audio cable (does not matter)

Maybe I can try to buy another Arduino and try it again.

When I think about it, I have bought AUX/USB/Bluetooth box from china and I also had issues with it. Sometimes it worked, but mostly not. This was why I wanted to build my own. Maybe my HU constantly has its days. :/

@visualapproach
Copy link
Owner Author

Yes maybe it's the HU, I have a 650 myself. No play in the HU connector? If you wiggle it I mean. Anyways, you should see almost 5 v on the data/busy/clk-lines at the arduino side when you measure, and 12 v on RUN. If you don't, you know the problem is either your HU or the cable. If possible you should measure this first with arduino disconnected (because it pulls the lines high) If this is too cumbersome you can upload a sketch that tristates D2-D4 (pinMode(2, INPUT))
I really wish you good luck now, and keep us updated on your progress!

@rysatko
Copy link

rysatko commented Oct 17, 2017

I will try the code with input pins on D2-D4, because Arduino is soldered to prototype board and it would be pain in ass to get it off. I can also build second cable, but it is nonsense. I will try it on Thursday (if I will not be in work till night :D ).
Also the Arduino could be bad. As I told you, the voltage converter on it is quite tricky and when I powered it directly from 12V, the LEDs on it lit only slightly. That time when I powered it with 5V from NTB or via 8205, it worked like a charm.

Thanks so much for your time and kindness. I really appriciate it. ;)

@rysatko
Copy link

rysatko commented Oct 28, 2017

Hello again.
I finally tried it. I'm not at home and I forgot to take USB cable to upload modified software so I tried to disconnect GND cable from the whole box (in my opinion it should work too, but maybe I am wrong). I have got 3V on D2 and D4 and 4,5V on D3.

@visualapproach
Copy link
Owner Author

Hi again! Hang on and I'll check what my DIN output measures at the end of the cable...

@visualapproach
Copy link
Owner Author

Yes, As I suspected I measured 4.7 volts at all three lines (In car, arduino end of cable, disconnected from arduino. I have an extra pair of DIN plugs so I can easily remove the device from the car). So I think you've traced it to be either your cable, or your HU. Next step would be to remove the cable and measure on the HU itself.

@rysatko
Copy link

rysatko commented Nov 4, 2017

Finally a day off - HU measured. RUN - 11,26V, DATA and CLK - 4,57V, BUSY - approx. 4,5V (fluctuating between 4,42V and 4,58V. Now I will try to desolder the cable from my board and try it again. The cable is 8x0,25mm2, connector is standard solderable 8-pin DIN 270°.

@visualapproach
Copy link
Owner Author

Good! It is a good thing that your HU is healthy. It is much easier to fix the cable. I use a shielded network cable with 4 twisted pairs in it. I had to run GND through the shield, rather than the GND at the cig connector, to get rid of alternator noise. (See image in this thread). I wish you luck!

@rysatko
Copy link

rysatko commented Nov 4, 2017

Connector checked and soldering is rock solid. So I desoldered BUSY, CLK and DATA at the side of Arduino and measured once again. And I found out, that when I move with the cable at the HU side, voltage of BUSY is droping to 0V. This is a hope :)

@visualapproach
Copy link
Owner Author

Yay! Bad wire? Great find! Intermittent faults are tricky to hunt down.

@rysatko
Copy link

rysatko commented Nov 4, 2017

I changed the wire aaand... Nothing again. :/ It is still losing connection. I think the problem is in the connector. But even if I tried to hold the cable in position where it appeared to be OK, nothing happened. HU still refuses to cooperate. I think I will get another Arduino and I will give it one more try...

@visualapproach
Copy link
Owner Author

Is there a point in getting a new Arduino if you know your cable/connector is bad? Of course it doesn't hurt getting some extra arduinos, they're pretty cheap.
Or do you get good readings out of the cable when it's not connected at the arduino side now?

@rysatko
Copy link

rysatko commented Nov 4, 2017

I have connection, when the cable goes straight forward or when I push it towards the drivers side. I tried to connect everything together and HU stil does not see any new device. For now I know the voltage converter on Arduino is bad. It is few years old and was used for several projects. It cost me about 3€. Maybe there could be also problem with the 8205...
I will build new board without the backpower protection and we will see. Just a question - what is the capacitor C2 at the drawing you posted at the beginning? I ve got only C1 - 470uF

@visualapproach
Copy link
Owner Author

Oh, c2 is a small ceramic cap. I put it there with the purpose of filtering noise when I had some issues. You can omit it. The big cap can be considered more of a local powerbank to survive short voltagedrops.

@rysatko
Copy link

rysatko commented Nov 11, 2017

I'm starting getting frustrated. Today I gave it a try. New Arduino, new cable and new simple board. When I was measuring connections between HU and board, I found out, that I do not have voltage at CLK pin. Even if I try to measure it directly in the HU connector, I cannot see anything...

@visualapproach
Copy link
Owner Author

That sucks! I can't really give you any advice on how to fix that. Sorry. But I'm feeling your frustration!

@rysatko
Copy link

rysatko commented Nov 12, 2017

Now I am just thinking... I have only connected DATA, BUSY, CLK and GND lines into HU. Pins for right and left audio and GND on pin are free. Have you tried this setup, when you were developing your board? Maybe HU shuts off CLK, when some of those 3 are free? I did not try to connect any load to them when I was measuring this time. And I do not remember, if I connected them when I was measuring the time before.

I am just cooking from water, before I get courage and time to remove HU from car and start disassembling it. :D

@visualapproach
Copy link
Owner Author

@rysatko I measured 5v on DATA, BUSY and CLK directly on the HU connector. Nothing connected at all.

@PedroPiko
Copy link

Hello Thomas,

First of all I would like to thank you for your work. This is very interesting also to me. I have tested on HU-603, which has not SAT mode. So I changed the CDC to MDC base, response IDs and now I running with MDC (buttons not tested on Nano outputs) but except text seems that is running OK. I have debug it with serial and found that MBR2 is there but there is no text in MDC. Do you have any idea how to enable it: Thank you. Peter

@Va1tel
Copy link

Va1tel commented Nov 21, 2024

https://github.com/Va1tel/ESP32-Volvo-MELBUS.git
I have prepared a repository on GitHub. If you have any ideas on how to solve the problem with Bluetooth, please share them.

@VincentGijsen
Copy link

VincentGijsen commented Nov 21, 2024 via email

@visualapproach
Copy link
Owner Author

Hi! Although ESP32 is really fast it has a long latency serving GPIO interrupts. That may cause issues when bit banging. The hardware SPI mode 3 is sampling on the wrong clock edge and is useless in my experience.
The 8266 is better choice for bit banging.

@f-io
Copy link

f-io commented Nov 22, 2024

Hi @Va1tel. I'm curious, is your ESP32 board 5V tolerant or is the schmatic just incomplete? As far as I remember melbus is sitting at 5V(?). Bluetooth streaming will increase power consumption by a lot, that may also introduce instability issues due to improper grounding / power. I'm also not sure if the isolation is really helpful, AGND is most likely connected to DGND at one point within the HU. Try to isolate AGND instead of DGND and of cause only if it is really necessary just to rule that out.

@Va1tel
Copy link

Va1tel commented Nov 22, 2024

@f-io, I'm not sure if my board supports 5v, I read that esp32 only perceives up to 3.3v, and MELBUS communicates on 5V, but there were no problems with sending and receiving data on the updated code without Bluetooth - this concerns grounding and power supply. The circuit is complete - only ESP32, DC-DC converter B1205S-2w, and 8 din connector are used. I'll add the pcm5102a module tomorrow to try to improve the sound. @VincentGijsen , thanks for the advice from esp_rom: I also realized that it was blocking the processor and switched to a hardware timer, since there you can achieve a delay in microseconds. By the way, yesterday I managed to ensure that music was playing and button control was working in CD-CHG mode: for this, in the ESP32-A2DP library itself, the task execution core was changed to 0 (the first core), and the logic was started as a task on core 1 (the second core), also commented on part of the kolbekov, which, in my opinion, blocked the basic logic of interaction with MELBUS. Tomorrow or maybe today I want to assemble with an external DAC and check its performance.

@goetzFromKoblenz
Copy link

Hi! Although ESP32 is really fast it has a long latency serving GPIO interrupts. That may cause issues when bit banging. The hardware SPI mode 3 is sampling on the wrong clock edge and is useless in my experience. The 8266 is better choice for bit banging.

I've used the 8266 in my device and it works quite fine. You can find cody snippets of how I handled I/O on 8266 waaaaayyyy up in this thread.

@goetzFromKoblenz
Copy link

@f-io, I'm not sure if my board supports 5v, I read that esp32 only perceives up to 3.3v, and MELBUS communicates on 5V, but there were no problems with sending and receiving data on the updated code without Bluetooth - this concerns grounding and power supply. The circuit is complete - only ESP32, DC-DC converter B1205S-2w, and 8 din connector are used. I'll add the pcm5102a module tomorrow to try to improve the sound. @VincentGijsen , thanks for the advice from esp_rom: I also realized that it was blocking the processor and switched to a hardware timer, since there you can achieve a delay in microseconds. By the way, yesterday I managed to ensure that music was playing and button control was working in CD-CHG mode: for this, in the ESP32-A2DP library itself, the task execution core was changed to 0 (the first core), and the logic was started as a task on core 1 (the second core), also commented on part of the kolbekov, which, in my opinion, blocked the basic logic of interaction with MELBUS. Tomorrow or maybe today I want to assemble with an external DAC and check its performance.

The ESP32 ist not 5V tolerant so I used a quite simple level shifter that may not look very modern but works fine. See the attached image.
grafik

@goetzFromKoblenz
Copy link

goetzFromKoblenz commented Nov 22, 2024

@f-io, I'm not sure if my board supports 5v, I read that esp32 only perceives up to 3.3v, and MELBUS communicates on 5V, but there were no problems with sending and receiving data on the updated code without Bluetooth - this concerns grounding and power supply. The circuit is complete - only ESP32, DC-DC converter B1205S-2w, and 8 din connector are used. I'll add the pcm5102a module tomorrow to try to improve the sound. @VincentGijsen , thanks for the advice from esp_rom: I also realized that it was blocking the processor and switched to a hardware timer, since there you can achieve a delay in microseconds. By the way, yesterday I managed to ensure that music was playing and button control was working in CD-CHG mode: for this, in the ESP32-A2DP library itself, the task execution core was changed to 0 (the first core), and the logic was started as a task on core 1 (the second core), also commented on part of the kolbekov, which, in my opinion, blocked the basic logic of interaction with MELBUS. Tomorrow or maybe today I want to assemble with an external DAC and check its performance.

The ESP32 ist not 5V tolerant so I used a quite simple level shifter that may not look very modern but works fine. See the attached image. grafik

The HU side is a (5V) pin from the radio and the NodeMCU side is a portpin of the ESP. GND of both sides is connected and the transistor's base is connected to 3V3 via 10k. There are a lot of variations of this circuit on the internet, mostly using FETs but this is the one I used.
The 3V3 Zener diode may be usesless, I just wanted to protect my ESP.

@Va1tel
Copy link

Va1tel commented Nov 22, 2024

@goetzFromKoblenz , does this mean that esp32 will not process the signal in principle, or that it will work for a while and then break down? The first option is clearly not my case, because I can both accept data from HU and send it in response. Perhaps my output Data, CLK and Busy have less than 5v or esp32 interprets everything above 3.3v as a high state.

@goetzFromKoblenz
Copy link

goetzFromKoblenz commented Nov 22, 2024

I just peeked into the Datasheet of ESP32 and according to that the maximum Power supply voltage VDD of the ESP32 is 3.6V. The maximum input voltage of the I/Os should not exceed VDD + 0.3V, so 3.9V at the I/Os would be the absolute maximum.
On my board (using a ESP8266) therefore it looks like this:
grafik
The Datasheet of the ESP32 can be found at https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf. Have a look at chapter 5.2.

@f-io
Copy link

f-io commented Nov 22, 2024

It is beyond specification (max rating IO V = VDD+0V3).
esp32-s3_datasheet_en.pdf page 64

There is mostlikly TTL logic on the HU side, it'll be fine with > 2,0 V as a logic high. But your ESP32 isn't fine with 5V at it's IO. This may work, may work for some time, don't work at all, may work but with unpredictable behavior. Additionally there is an ESD protection that will load the bus.

I used the cheapest 3V3/5V TTL shifter that were lying around, looking like these.
61a1Ix2bbrL AC_SL1000

@goetzFromKoblenz
Copy link

It is beyond specification (max rating IO V = VDD+0V3). esp32-s3_datasheet_en.pdf page 64

There is mostlikly TTL logic on the HU side, it'll be fine with > 2,0 V as a logic high. But your ESP32 isn't fine with 5V at it's IO. This may work, may work for some time, don't work at all, may work but with unpredictable behavior. Additionally there is an ESD protection that will load the bus.

I used the cheapest 3V3/5V TTL shifter that were lying around, looking like these.

Right. There are lot of ready-to-use level shifters around e.g. by TI. I did not have any at hand so I used the transistors, small footprint and bi-directional.

@f-io
Copy link

f-io commented Nov 22, 2024

Right. There are lot of ready-to-use level shifters around e.g. by TI. I did not have any at hand so I used the transistors, small footprint and bi-directional.

I also tried using those bidirectional level converter ICs I think it was TXS108E, but I ended up having more problems, so went the discrete route as well. Maybe the ICs were bad, it was not a trustworthy distributor.

@Va1tel
Copy link

Va1tel commented Nov 24, 2024

@VincentGijsen, @goetzFromKoblenz, @f-io , @visualapproach, Friends, have you ever encountered a PCM5102A connection to an esp32? The problem is as follows: the phone sees the device, connects, but there is no sound. There are clicks in the headphones after any action - pausing, the next track, but there is no music itself. The jumpers on the DAC are soldered. The connection is as follows:
BCK -> GPIO 25
DIN -> GPIO 26
LCK -> GPIO 33
SCK -> GND
I take the power supply of the dac from the vin esp32. To initialize bluetooth, I use the ESP32-A2DP library with an example of I2S with the definition of my own contacts. What could be the problem?

@VincentGijsen
Copy link

VincentGijsen commented Nov 24, 2024 via email

@Va1tel
Copy link

Va1tel commented Nov 24, 2024

Well,The dac is ‘invisible’ in the sense of, it only processes input. Perhaps in abundance, but you wired the dac to NOt mute? I think to recall this is needed, in addition.A new PCM5102 board has been failing the sound of certain web ...app.goo.glAre you sure the esp generates the I2s data, did you scope the IOs, to confirm clk, left/right and data are doing what is needed ?In terms of format of i2s I think I used the ‘Philips’ format.Good luck Sent from my phoneOn 24 Nov 2024, at 09:06, Va1tel @.> wrote: @VincentGijsen, @goetzFromKoblenz, @f-io , @visualapproach, Friends, have you ever encountered a PCM5102A connection to an esp32? The problem is as follows: the phone sees the device, connects, but there is no sound. There are clicks in the headphones after any action - pausing, the next track, but there is no music itself. The jumpers on the DAC are soldered. The connection is as follows: BCK -> GPIO 25 DIN -> GPIO 26 LCK -> GPIO 33 SCK -> GND I take the power supply of the dac from the vin esp32. To initialize bluetooth, I use the ESP32-A2DP library with an example of I2S with the definition of my own contacts. What could be the problem? —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.>

Is iOS an oscilloscope? There is no way to connect it, maybe close it back to esp32 and try to read and output data. Can it work?

@visualapproach
Copy link
Owner Author

Yes he ment an oscilloscope or logic analyzer on the Inputs/OutputS.
I don't have any experience on the 5102 so nothing to see here...

@goetzFromKoblenz
Copy link

@Va1tel : I try to understand what you are trying to do. You want do generate Audio output from a Digital data stream, right? Why don't you simply use a VS1053 board? You can directly feed mp3 and various other formats to it and it provides a ready-to-use audio amplifier. I did struggle a little with the demo software by ada but in the end I managed to get it running well. The difference to your project is that I only wanted to play music from an SD card but I don't see why it shouldn't work with bluetooth.

@VincentGijsen
Copy link

VincentGijsen commented Nov 24, 2024 via email

@Va1tel
Copy link

Va1tel commented Nov 24, 2024

Ha,I meant iOS as plural of IO, mutiple (gp)io / pins from the Esp32, to establish i2s signals are actually generated by the ESP32; a clock ,data and wordselect/left-right.What I think he tries to achieve; get better 16/24 sound out of the ESP32, streamed via Bluetooth. The vs1035 chips don’t work (to my understanding) for i2s, only mp3 encoded audio to analog. In this case the pcm51 is used to handle pcm data over is2 to analog. Audio comes from mobile phone). Using the build in dac from esp32 is quite garbage for audio applications (exception for some esp boards with building dac (es8xxx btw)..My comment was about establishing proper i2s output. And validate proper wireing or DACSent from my phoneOn 24 Nov 2024, at 13:04, Goetz Hasselberg @.> wrote: @Va1tel : I try to understand what you are trying to do. You want do generate Audio output from a Digital data stream, right? Why don't you simply use a VS1053 board? You can directly feed mp3 and various other formats to it and it provides a ready-to-use audio amplifier. I did struggle a little with the demo software by ada but in the end I managed to get it running well. The difference to your project is that I only wanted to play music from an SD card but I don't see why it shouldn't work with bluetooth. —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.>

Yes, that's exactly what I want to do. I will try to check the signals coming from the esp32 on the esp32 itself, sending from some contacts and receiving from others, because I do not have an oscilloscope or a logic analyzer. I also have two suggestions:

  1. I did not connect 3.3v, since it does not say anywhere that it needs to be additionally connected;
  2. I commented out some callbacks in the source library, as they slowed down the logic. I'll check these two points too.

@f-io
Copy link

f-io commented Nov 25, 2024

@Va1tel can you please specify which ESP32 board you are using, as well as the PCM board? Maybe a picture of your wiring? ESP32 has an internal LDO for 3V3. Optionally the ESP can also be supplied with 3V3 instead of 5V VIN.
You need to connect GND <-> GND between ESP32 and PCM board. VCC (AVDD/DVDD) on the PCM needs 3V3 as long as there is no local LDO, you cannot use the VIN 5V, otherwise you will fry the PCM IC

I never used a PCM, I was feeding the I2S (left justified) into an ADAU (DSP) asynchronous sample rate converter. At that time, there were no other options for additional codecs apart from SBC. iOS will prefere AAC, Android devices often do support APT-X but both can fall back to SBC.

Both of the "better" codecs are propritary ones, this is why you often find BT streaming solutions using of the shelf preprogrammed Qualcomm CSR boards (Qualcomm owns Aptx). ACC is owned by via licensing, both need valid keys within the CSR chip firmware. ESP maybe offer binarys for those codecs, if they do I'm sure that will involve some legal work and a few $$$$.

In your example code I couldn't find any initialization as well as no PIN definition for the I2S interface.
For testing I would higly recommend to start with the bare A2DP I2S example befor mixing up your code.

https://github.com/pschatzmann/ESP32-A2DP/blob/main/examples/bt_music_receiver_arduino_i2s_3/bt_music_receiver_arduino_i2s_3.ino

@Va1tel
Copy link

Va1tel commented Nov 25, 2024

Screenshot_2024-11-25-13-32-08-14_9ecc93bf6683d0fd0fd501ae5792979e
Screenshot_2024-11-25-13-35-49-70_3c841798971d89a92069939d312bec3c
@f-io , I am using these boards for a project. I have suspicions that the PCM board is not working, so I ordered a new one and will try it on it, but it will only be in a week(

@Va1tel
Copy link

Va1tel commented Nov 25, 2024

can you please specify which ESP32 board you are using, as well as the PCM board? Maybe a picture of your wiring? ESP32 has an internal LDO for 3V3. Optionally the ESP can also be supplied with 3V3 instead of 5V VIN. You need to connect GND <-> GND between ESP32 and PCM board. VCC (AVDD/DVDD) on the PCM needs 3V3 as long as there is no local LDO, you cannot use the VIN 5V, otherwise you will fry the PCM IC.

I never used a PCM, I was feeding the I2S (left justified) into an ADAU (DSP) asynchronous sample rate converter. At that time, there were no other options for additional codecs apart from SBC. iOS will prefere AAC, Android devices often do support APT-X but both can fall back to SBC.

Both of the "better" codecs are propritary ones, this is why you often find BT streaming solutions using of the shelf preprogrammed Qualcomm CSR boards (Qualcomm owns Aptx). ACC is owned by via licensing, both need valid keys within the CSR chip firmware. ESP maybe offer binarys for those codecs, if they do I'm sure that will involve some legal work and a few $$$$.

In your example code I couldn't find any initialization as well as no PIN definition for the I2S interface. For testing I would higly recommend to start with the bare A2DP I2S example befor mixing up your code.

the code that is currently presented in the repository does not have I2S initialization, since initially I was just trying to output analog audio from the internal esp32 DAC. I am currently using this code to test the I2S c PCM5102:

#include "AudioTools.h"
#include "BluetoothA2DPSink.h"

I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);

#define I2S_BCK_IO GPIO_NUM_33
#define I2S_DATA_OUT_IO GPIO_NUM_25
#define I2S_WS_IO GPIO_NUM_26

extern "C" void app_main(void)
{
    auto cfg = i2s.defaultConfig();
    cfg.pin_bck = I2S_BCK_IO;
    cfg.pin_ws = I2S_WS_IO;
    cfg.pin_data = I2S_DATA_OUT_IO;
    i2s.begin(cfg);

    a2dp_sink.start("MyMusic");

    while (true) {
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

@f-io
Copy link

f-io commented Nov 25, 2024

@Va1tel did you connect VIN (PCM) to 3V3 or to VIN of the ESP32?

edit: sorry without a proper link to your DAC board I wasn't aware it is using an onboard LDO.

PCM -  | - ESP32
VIN  <------> 5V
GND  <------> GND
LRCK <------> GPIO WX
BCK  <------> GPIO XY
DIN  <------> GPIO YZ

Solderbridge on the PCM board so the PCM.

Define the needed pins and use the linked example.

#include "ESP_I2S.h"
#include "BluetoothA2DPSink.h"

const uint8_t I2S_SCK = WX;      /* Audio data bit clock */
const uint8_t I2S_WS = WX;       /* Audio data left and right clock */
const uint8_t I2S_SDOUT = YZ;    /* ESP32 audio data output (to speakers) */
I2SClass i2s;

BluetoothA2DPSink a2dp_sink(i2s);

void setup() {
    i2s.setPins(I2S_SCK, I2S_WS, I2S_SDOUT);
    if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, I2S_STD_SLOT_BOTH)) {
      Serial.println("Failed to initialize I2S!");
      while (1); // do nothing
    }

    a2dp_sink.start("MyMusic");
}

void loop() {
}

@Va1tel
Copy link

Va1tel commented Nov 25, 2024

@Va1tel did you connect VIN (PCM) to 3V3 or to VIN of the ESP32 ? You have to connect it to 3V3!

PCM -  | - ESP32
VIN  <------> 3V3
GND  <------> GND
LRCK <------> GPIO WX
BCK  <------> GPIO XY
DIN  <------> GPIO YZ

Solderbridge on the PCM board so the PCM will generate the MCLK.

Define the needed pins and use the linked example.

#include "ESP_I2S.h"
#include "BluetoothA2DPSink.h"

const uint8_t I2S_SCK = WX;      /* Audio data bit clock */
const uint8_t I2S_WS = WX;       /* Audio data left and right clock */
const uint8_t I2S_SDOUT = YZ;    /* ESP32 audio data output (to speakers) */
I2SClass i2s;

BluetoothA2DPSink a2dp_sink(i2s);

void setup() {
    i2s.setPins(I2S_SCK, I2S_WS, I2S_SDOUT);
    if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, I2S_STD_SLOT_BOTH)) {
      Serial.println("Failed to initialize I2S!");
      while (1); // do nothing
    }

    a2dp_sink.start("MyMusic");
}

void loop() {
}

I connected it initially to VIN, but I also tried to connect it to 3.3v, perhaps by that time the PCM had already broken down. I was guided by this https://github.com/pschatzmann/arduino-audio-tools/wiki/External-DAC.

In the example, you use two different synchronization channels: first BCK, then SCK - I'm a little confused.

@f-io
Copy link

f-io commented Nov 25, 2024

Looks like your board is using 5V and an on board LDO (3V3/1V8).

Have you soldered the bridge on the top below SCK? You need to pull this pin to ground, otherwise the PCM will wait for an external SCK. Please read the chapter 9.3.5.3 Clock Slave Mode with BCK PLL to Generate Internal Clocks (3-Wire PCM)

SCK (system clock), in your example we like to use the internal PLL (phase lock loop) to operate the DAC in slave mode. The DAC will internaly generate the SCK based on the BCK.

WS (word select) = LRCK (left-right clock), this is the signal to indicate data is LEFT audio FRAME or RIGHT audio FRAME.

BCK (bit clock), this is the signal for the DAC when to READ the DATA Pin, there is a fixed timing between data and bit clock.

If you like to provide the SCK (some times also named MCLK = master clock) as well you need to make sure to take a look into Table 10. System Master Clock Inputs for Audio Related Clock for the right frequency for your FS 44.1 or 48 KHz. Other modes are useless with SBC, and even with APTX or AAC there is no benefit in using FS 88.1/96 KHz other than noise, depending on your output filter.

@Va1tel
Copy link

Va1tel commented Nov 25, 2024

Looks like your board is using 5V and an on board LDO. Have you soldered the bridge on the top below SCK? You need to pull this pin to ground, otherwise the PCM will wait for an external SCK. Please read the chapter 9.3.5.3 Clock Slave Mode with BCK PLL to Generate Internal Clocks (3-Wire PCM)

SCK (system clock), in your example we like to use the internal PLL (phase lock loop) to operate the DAC in slave mode. WS (word select) = LRCK (left-right clock), this is the signal to indicate data is LEFT audio FRAME or RIGHT audio FRAME. BCK (bit clock), this is the signal for the DAC when to READ the DATA Pin, there is a fixed timing between data and clock.

I didn't solder the jumper on top of the SCK, but I just shorted it with a wire to GND, which is probably the same thing.

@Va1tel
Copy link

Va1tel commented Nov 25, 2024

@f-io, Do I understand correctly that it will be enough for me to connect esp and pcm like this:

PCM - | - ESP32
VIN <------> 3V3
GND <------> GND
LRCK <------> GPIO 26
BCK <------> GPIO 33
DIN <------> GPIO 25

Solder the jumpers from the back side like this:
FLT:Low, DEMP: Low, XSMT: High, FMT: Low

Solder the jumper over the SCK and use this code:

#include "AudioTools.h"
#include "BluetoothA2DPSink.h"

I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);

void setup() {
    auto cfg = i2s.defaultConfig();
    cfg.pin_bck = 33;
    cfg.pin_ws = 26;
    cfg.pin_data = 25;
    i2s.begin(cfg);

    a2dp_sink.start("MyMusic");
}

void loop() {
}

@f-io
Copy link

f-io commented Nov 25, 2024

PCM - | - ESP32
VIN <------> 5V

     auto cfg = i2s.defaultConfig(TX_MODE);

otherwise LGTM.

@Va1tel
Copy link

Va1tel commented Nov 26, 2024

otherwise LGTM

I try it today

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