No sound card detected for Opi zero 2w

Thank Totof
I forgot that there’s an overlay_prefix factor. SDA1 and SCL1 have been recognized:

(.venv) pi@orangepizero2w:~/fluidsynth_oled$ gpio readall
 +------+-----+----------+--------+---+  ZERO2W  +---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 |      |     |     3.3V |        |   |  1 || 2  |   |        | 5V       |     |      |
 |  264 |   0 |    SDA.1 |   ALT5 | 0 |  3 || 4  |   |        | 5V       |     |      |
 |  263 |   1 |    SCL.1 |   ALT5 | 0 |  5 || 6  |   |        | GND      |     |      |
 ...
 +------+-----+----------+--------+---+  ZERO2W  +---+--------+----------+-----+------+
(.venv) pi@orangepizero2w:~/fluidsynth_oled$

However, one quite confusing issue is that I can’t find the correct I2C address (I’m using a 0.96" OLED screen with SSD1306). The pins are connected correctly, but I still can’t detect the I2C address:

(.venv) pi@orangepizero2w:~/fluidsynth_oled$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
(.venv) pi@orangepizero2w:~/fluidsynth_oled$

Perhaps some info here
https://www.youtube.com/watch?v=rBsVADehPXg&t=307s

Hello again sangto2906
for your adress and with i2c1 you must scope the 3rd node see picture

The reg value of the good i2c is i2c@5002400

Thank you for your response. I tried it, but things don’t seem to be going well.

I have enabled i2c0 in the config:

pi@orangepizero2w:~$ sudo cat /boot/armbianEnv.txt
verbosity=1
bootlogo=false
console=both
disp_mode=1920x1080p60
overlay_prefix=sun50i-h616
rootdev=UUID=405c2535-1ad5-46a9-8e38-aedf835f3f33
rootfstype=ext4
fdtfile=allwinner/sun50i-h618-orangepi-zero2w-essai.dtb
overlays=i2c0-pi
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

When I checked, i2c5002400 is mapped to i2c0:

pi@orangepizero2w:~$ ls /sys/devices/platform/soc*/*/i2c-* | grep "i2c-[0-9]"
/sys/devices/platform/soc/5002000.i2c/i2c-4:
/sys/devices/platform/soc/5002400.i2c/i2c-0:
/sys/devices/platform/soc/5002c00.i2c/i2c-3:
/sys/devices/platform/soc/6000000.hdmi/i2c-2:
/sys/devices/platform/soc/7081400.i2c/i2c-1:

However, when I try to detect devices on the bus, nothing is detected and the scan takes a long time — around 3 minutes:

pi@orangepizero2w:~$ sudo i2cdetect -y 0
[sudo] password for pi:
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

The overlay seems to be working properly. Could it be that pull-up resistors are required?

Here’s the GPIO layout for reference:

 +------+-----+----------+--------+---+  ZERO2W  +---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 |      |     |     3.3V |        |   |  1 || 2  |   |        | 5V       |     |      |
 |  264 |   0 |    SDA.1 |    OFF | 0 |  3 || 4  |   |        | 5V       |     |      |
 |  263 |   1 |    SCL.1 |    OFF | 0 |  5 || 6  |   |        | GND      |     |      |
 |  269 |   2 |     PWM3 |    OFF | 0 |  7 || 8  | 0 | ALT2   | TXD.0    | 3   | 224  |
 |      |     |      GND |        |   |  9 || 10 | 0 | ALT2   | RXD.0    | 4   | 225  |
 |  226 |   5 |    TXD.5 |    OFF | 0 | 11 || 12 | 0 | ALT4   | PI01     | 6   | 257  |
 |  227 |   7 |    RXD.5 |    OFF | 0 | 13 || 14 |   |        | GND      |     |      |
 |  261 |   8 |    TXD.2 |   ALT5 | 0 | 15 || 16 | 0 | OFF    | PWM4     | 9   | 270  |
 |      |     |     3.3V |        |   | 17 || 18 | 0 | OFF    | PH04     | 10  | 228  |
 |  231 |  11 |   MOSI.1 |    OFF | 0 | 19 || 20 |   |        | GND      |     |      |
 |  232 |  12 |   MISO.1 |    OFF | 0 | 21 || 22 | 0 | ALT5   | RXD.2    | 13  | 262  |
 |  230 |  14 |   SCLK.1 |    OFF | 0 | 23 || 24 | 0 | OFF    | CE.0     | 15  | 229  |
 |      |     |      GND |        |   | 25 || 26 | 0 | OFF    | CE.1     | 16  | 233  |
 |  266 |  17 |    SDA.2 |    OFF | 0 | 27 || 28 | 0 | OFF    | SCL.2    | 18  | 265  |
 |  256 |  19 |     PI00 |   ALT4 | 0 | 29 || 30 |   |        | GND      |     |      |
 |  271 |  20 |     PI15 |    OFF | 0 | 31 || 32 | 0 | OFF    | PWM1     | 21  | 267  |
 |  268 |  22 |     PI12 |    OFF | 0 | 33 || 34 |   |        | GND      |     |      |
 |  258 |  23 |     PI02 |   ALT4 | 0 | 35 || 36 | 0 | OFF    | PC12     | 24  | 76   |
 |  272 |  25 |     PI16 |    OFF | 0 | 37 || 38 | 0 | ALT4   | PI04     | 26  | 260  |
 |      |     |      GND |        |   | 39 || 40 | 0 | ALT4   | PI03     | 27  | 259  |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+  ZERO2W  +---+--------+----------+-----+------+

P/S: This is getting quite long — do you think it’s better to create a separate topic just for I2C to avoid cluttering other replies?

Hello sangto2906

Perhaps a good idea to spilt the i2c discussion

For the pin i2c sda.1 and scl.1 it’s i2c1 that you need to mentionned in dietpiEnv.txt

your precedent screenshoot in post look correct for i2c1

(.venv) pi@orangepizero2w:~/fluidsynth_oled$ gpio readall
 +------+-----+----------+--------+---+  ZERO2W  +---+--------+----------+-----+------+
 | GPIO | wPi |   Name   |  Mode  | V | Physical | V |  Mode  | Name     | wPi | GPIO |
 +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+
 |      |     |     3.3V |        |   |  1 || 2  |   |        | 5V       |     |      |
 |  264 |   0 |    SDA.1 |   ALT5 | 0 |  3 || 4  |   |        | 5V       |     |      |
 |  263 |   1 |    SCL.1 |   ALT5 | 0 |  5 || 6  |   |        | GND      |     |      |
 ...
 +------+-----+----------+--------+---+  ZERO2W  +---+--------+----------+-----+------+
(.venv) pi@orangepizero2w:~/fluidsynth_oled$

And your next screennshoot as well with the

pi@orangepizero2w:~$ ls /sys/devices/platform/soc*/*/i2c-* | grep "i2c-[0-9]"
/sys/devices/platform/soc/5002000.i2c/i2c-4:
/sys/devices/platform/soc/5002400.i2c/i2c-0:
/sys/devices/platform/soc/5002c00.i2c/i2c-3:
/sys/devices/platform/soc/6000000.hdmi/i2c-2:
/sys/devices/platform/soc/7081400.i2c/i2c-1:

The good line is this “/sys/devices/platform/soc/5002400.i2c/i2c-0:”
so to scope your adress use

i2cdetect -y 0

No need to use sudo

Thank Totof for your response. The issue was actually due to my misunderstanding between I2C and its bus mapping. I’ve successfully configured it now, and it seems I don’t need to create a separate topic anymore.

pi@orangepizero2w:~$ i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

At first, I thought that since the command

pi@orangepizero2w:~$ ls /sys/devices/platform/soc*/*/i2c-* | grep "i2c-[0-9]"
/sys/devices/platform/soc/5002400.i2c/i2c-3:

returned i2c-3, I needed to configure overlay=i2c3-pi and look for I2C3 on the board.
Haha, turns out that was just a misunderstanding on my part, so i think i won’t create a new topic unless something too difficult arises.

Hello again

No you have connected your screen to the pin sda.1 and scl.1 , so it’s i2c1
and in your opizero2w it seems it’s the 3rd noticed i2c-3 with the register
@5002400 who correspond to the i2c1-pi pins

In Your sreenshoot you have the adress of your device
You read 3C so your device must have the adress 0x3c if I’m right

Hello everyone

I gave in to the fun of testing the script to enable sound. I bought an OrangePi Zero2W 4GB pack and a PCM5102 board to test it all more easily than dismantling my server that contains my original Zero2W.
This kind of pack

I’ll make a small PCB to accommodate the PCM5102 board in the stack, a bit like in this photo with the PCM5102 and a heatsink on top.
Something like this (picture from the web)

1 Like

Orange Pi is truly amazing as they are both compact and powerful enough. I’m developing a synthesizer project (I can fit them inside my MIDI device and carry it around easily). The configuration was a bit challenging, but with your help, I’ve been able to gradually complete it. Thank you and the community for your enthusiastic support!

2 Likes

Hello everyone

I’ve just receive my OPI zero 2w with it’s expansion board
I burn a fresh SD card with the Dietpi image with LMS ans Squeezlight
Everything is “okay”
I run the last script and test the jack , there is sound but not ine the good format
so i modified my asound.conf to correct it and now i can play music in my earphone
i plan to extend the script with the modification of the asound.conf file like this

        format S16_LE
        rate 44100
        type hw
        card 0
        device 0
}

pcm.!default {
        type plug
        slave.pcm "device"
}

ctl.!default {
        type hw
        card 0
}


Now i tested later the HDMI sound :wink:

Hello everyone

I’ve just receive my OPI zero 2w with it’s expansion board
I burn a fresh SD card with the Dietpi image with LMS ans Squeezlight
Everything is “okay”
I run the last script and test the jack , there is sound but not in the good format
so i modified my asound.conf to correct it and now i can play music in my earphone
i plan to extend the script with the modification of the asound.conf file like this

pcm.device{
        format S16_LE
        rate 44100
        type hw
        card 0
        device 0
}

pcm.!default {
        type plug
        slave.pcm "device"
}

ctl.!default {
        type hw
        card 0
}

That’s good , the sound work imediatly on HDMI
the selection of te card 2 modify the asound.conf !!!
Need to go further :wink:

1 Like

Hello everyone

I tested the jack connector and the HDMI for the sound, it’s okay with the script
I receive my PCM5102 so i tested and i need to make some change in the script
i need to implement clock and some parts to have sound with the PCM5102
Now it’s done and work very well

@MichaIng just one item doesn’t work in the script , the command line “G_CONFIG_INJECT”
Perhaps you can help me to implement it
This line found in the forum can do the job ?

# DietPi-Globals: dietpi-* aliases, G_* functions and variables
. /boot/dietpi/func/dietpi-globals || { echo -e '[\e[31mFAILED\e[0m] DietPi-Login | Failed to load DietPi-Globals. Skipping DietPi login scripts...'; return 1; }

So the new script to obtain sound with the PCM5102 on the 40pin hat

# Create the directory for user overlays
mkdir -p /boot/overlay-user
cd /boot/overlay-user
# Create the overlay source file
cat << '_EOF_' > sound-hdmi-jack-i2s0-hat.dts
/dts-v1/;
/plugin/;
/ {
	compatible = "allwinner,sun50i-h618";
	fragment@0 {
		target = <&pio>;
		__overlay__ {
			ahub_daudio0_pins_d: ahub_daudio0_sleep {
				pins = "PI0", "PI1", "PI2", "PI3", "PI4";
				function = "gpio_in";
				drive-strength = <0x14>;
				bias-disable;
			};
			ahub_daudio0_pins_a: ahub_daudio0@0 {
				pins = "PI0", "PI1", "PI2";
				function = "i2s0";
				drive-strength = <0x14>;
				bias-disable;
			};
			ahub_daudio0_pins_b: ahub_daudio0@1 {
				pins = "PI3";
				function = "i2s0_dout0";
				drive-strength = <0x14>;
				bias-disable;
			};
			ahub_daudio0_pins_c: ahub_daudio0@2 {
				pins = "PI4";
				function = "i2s0_din0";
				drive-strength = <0x14>;
				bias-disable;
			};
		};
	};
	fragment@1 {
		target-path = "/soc";
		__overlay__ {
			ahub0_plat: ahub0_plat {
				#sound-dai-cells = <0>;
				compatible = "allwinner,sunxi-snd-plat-ahub";
				apb_num = <0>; /* for dma port 3 */
				dmas = <&dma 3>, <&dma 3>;
				dma-names = "tx", "rx";
				playback_cma = <128>;
				capture_cma = <128>;
				tx_fifo_size = <128>;
				rx_fifo_size = <128>;
				pinctrl-names = "default", "sleep";
				pinctrl_used;
				pinctrl-0 = <&ahub_daudio0_pins_a>, <&ahub_daudio0_pins_b>, <&ahub_daudio0_pins_c>;
				pinctrl-1 = <&ahub_daudio0_pins_d>;
				status = "okay";
			};
			ahub0_mach: ahub0_mach {
				compatible = "allwinner,sunxi-snd-mach";
				soundcard-mach,name = "ahubi2s0";
				soundcard-mach,format = "i2s";
				soundcard-mach,frame-master = <&ahub0_cpu>;
			        soundcard-mach,bitclock-master = <&ahub0_cpu>;
			        soundcard-mach,slot-num = <2>;
			        soundcard-mach,slot-width = <32>;
				status = "okay";

				ahub0_cpu: soundcard-mach,cpu {
					sound-dai = <&ahub0_plat>;
					soundcard-mach,pll-fs = <4>;
				        soundcard-mach,mclk-fs = <0>;
				};

				soundcard-mach,codec {
				};
			};
		};
	};
	fragment@2 {
		target-path = "/soc";
		__overlay__ {
			codec: codec {
			                       compatible = "allwinner,sun50i-h616-codec";
			                       status = "okay";
			                       allwinner,audio-routing = "Line Out", "LINEOUT";
			                       };
			 };
	};
	fragment@3 {
		target-path = "/soc";
		__overlay__ {
			ahub_dam_plat: ahub_dam_plat {
			                       compatible = "allwinner,sunxi-snd-plat-ahub_dam";
			                       status = "okay";
			                       };
			 };
	};
	fragment@4 {
		target-path = "/soc";
		__overlay__ {
			ahub1_plat: ahub1_plat {
			                       compatible = "allwinner,sunxi-snd-plat-ahub";
			                       #sound-dai-cells = <0x00>;
			                       status = "okay";
			                       };
			 };
	};
	fragment@5 {
		target-path = "/soc";
		__overlay__ {
			ahub1_mach: ahub1_mach {
			                       compatible = "allwinner,sunxi-snd-mach";
			                       soundcard-mach,name = "HDMI";
			                       soundcard-mach,format = "i2s";
			                       status = "okay";
			                       
			                       soundcard-mach,cpu {
					           sound-dai = <&ahub1_plat>;
				                   };

				               soundcard-mach,codec {
				                   };
			                       };
			 };
	};
};
_EOF_
# Install the device tree compiler
apt install device-tree-compiler
# Compile the overlay binary file
dtc -I dts -O dtb -o sound-hdmi-jack-i2s0-hat.dtbo -@ sound-hdmi-jack-i2s0-hat.dts
# To see the result of the compiler uncommit next line
#fdtdump sound-hdmi-jack-i2s0-hat.dtbo
# Enable the user overlay via U-Boot environment file
G_CONFIG_INJECT 'user_overlays=' 'user_overlays=sound-hdmi-jack-i2s0-hat' /boot/dietpiEnv.txt

A little bit busy in this moment withwork and sport but next week on holiday
so i try to implement with an user overlay a cheap PCM5122 dac board :wink:

Okay so the main problem on Zero 2W is that, that codec and HDMI nodes are enabled in a file which is not included by the Zero 2W main device tree. So that is easy to solve, enabling those right in the 2W device tree as well, which brings is onto the same stage as the Zero 3.

Then we can add an additional overlay for the I2S0 HAT. With enabled codec, the one which defines/enables only ahub_daudio0 and ahub0_plat nodes should work.

EDIT: ahub_dam_plat should go into the device tree overlay for the HAT, since the board does not provide an audio jack, but the HAT does, right? On Linux 6.15, the same (updated) patch enables that one for Zero 2W OOTB. I’ll align it for now, but seems nonsense to me.

Hello Michaing

In fact it’s normhat for the zero 2w that the device tree don’t have audio out for the Jack connector, it’s on the expansion board
Like the IR, button, Usb and Ethernet connector
For i2s0 it’s on the hat 40 pin connector

So we can make a sound dtbo file
With HDMI and Jack

And a i2s dtbo file to enable sound on the hat

New kernel build to test:

cd /tmp
wget https://dietpi.com/downloads/binaries/testing/linux-{dtb,image}-current-sunxi64.deb
sudo dpkg -i linux-{dtb,image}-current-sunxi64.deb

To enable the I2C0 HAT:

G_CONFIG_INJECT 'overlays=' 'overlays=i2s0-hat' /boot/dietpiEnv.txt

As said, I aligned it the way it is done on Linux 6.15 already, with HDMI and audio jack enabled OOTB without overlay. Obviously, it does not cause issues if no HAT is attached, maybe some kernel error or warning during boot, as of non-existent hardware for an enabled node. But generally, sounds more reasonable to enable the jack with that or a dedicated overlay only.

Here the related commits:

Hello MichaIng

I try your new kernell , without succes and in the dtb/overlay there is no i2s0-hat.dtbo file

In fact for HDMI and Ahubi2s0 yoy need clock and format ine the dts or dtsi file
like this


and also for sound on HDMI and Jack the line “compatible etc…;”
and the line “#sound-dai-cells = <0x00>;” like in the script

Ready to test new one

Would those warnings of non-existent hardware come at every boot?

I’m using this device, both with and without the hat.

Looks like the patch needs to be added to another series file as well.

You mean the ahub0_cpu node from the overlay needs the PLL and CLK property as well, like the ahub1_cpu does already? At least it should, as I see that in the parent patch:

+               ahub1_mach:ahub1_mach {
+                       compatible = "allwinner,sunxi-snd-mach";
+                       soundcard-mach,name = "HDMI";
+
+                       soundcard-mach,format           = "i2s";
+                       soundcard-mach,frame-master     = <&ahub1_cpu>;
+                       soundcard-mach,bitclock-master  = <&ahub1_cpu>;
+                       /* soundcard-mach,frame-inversion; */
+                       /* soundcard-mach,bitclock-inversion; */
+                       soundcard-mach,slot-num         = <2>;
+                       soundcard-mach,slot-width       = <32>;
+                       status          = "disabled";
+                       ahub1_cpu: soundcard-mach,cpu {
+                               sound-dai = <&ahub1_plat>;
+                               soundcard-mach,pll-fs   = <4>;
+                               soundcard-mach,mclk-fs  = <0>;
+                       };
+
+                       ahub1_codec: soundcard-mach,codec {
+                               sound-dai = <&hdmi>;
+                       };
+               };

compatible properties are all identical, as far as I can see. Let me trigger a rebuild, this time with the overlay patch applied.

If it does show anything at all, every boot, yes. But I can move that part our quickly, if something does show up, any anyone is annoyed by it.

Hello MichaIng

Yes the cpu parts needs clock so pll mclk

For the codec part no need to fill this with sound-dai = <&hdmi>;

After rebuilding the kernel i can test it :winking_face_with_tongue: