Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7503

Beginners • How can I use the rasp-4B USB-C OTG function to simulate wired headphones and connect to Android and iOS devices?

$
0
0
I have a project requirement that I disguise a Raspberry Pi as a headset with wired controls to connect to Android and iOS devices.

The Raspberry Pi should be able to send and receive audio, control volume, and answer and hang up phone calls.

I've tried for a long time without success. Has anyone encountered a similar requirement or has a similar open-source solution?

1. Initial Attempt

Based on tutorials found online, I configured /boot/firmware/ as follows:

config.txt

Code:

...[all]dtoverlay=dwc2...
cmdlien.txt

Code:

...rootwait modules-load=dwc2,g_audio ...
After connecting to my Windows computer, it was successfully recognized as an audio device.

However, it was not recognized when connected to either an Android device or an iPhone. The Android device was recognized as a charger, while the iPhone did not respond at all.

2. use libcomposite

I suspected that this approach was too crude and some key information might be missing, so I tried to write a configuration file for an audio device using libcomposite.

Code:

#!/bin/bashset -eGADGET_DIR="/sys/kernel/config/usb_gadget/g_audio"VID="0x1d6b"     PID="0x0104"       SERIAL="RPi4-UAC2-001" MANUFACTURER="Raspberry Pi" PRODUCT="Pi4 UAC2 Audio"FUNC_NAME="Pi4 Speaker+Mic" if [ -d "$GADGET_DIR" ]; then    echo "Cleaning up old gadget..."    echo "" > "$GADGET_NAME/UDC" || true    rm -f "$GADGET_NAME/configs/c.1/uac2.usb0" || true    rm -f "$GADGET_NAME/os_desc/c.1" || true    rmdir "$GADGET_NAME/configs/c.1/strings/0x409" || true    rmdir "$GADGET_NAME/configs/c.1" || true    rmdir "$GADGET_NAME/functions/uac2.usb0" || true    rmdir "$GADGET_NAME/strings/0x409" || true    rmdir "$GADGET_NAME/webusb" || true    rmdir "$GADGET_NAME/os_desc" || true    rmdir "$GADGET_NAME" || truefimkdir -p "$GADGET_DIR"cd "$GADGET_DIR"echo "$VID" > idVendorecho "$PID" > idProductecho "0x0200" > bcdUSB     echo "0x0100" > bcdDevice   mkdir -p strings/0x409echo "$SERIAL" > strings/0x409/serialnumberecho "$MANUFACTURER" > strings/0x409/manufacturerecho "$PRODUCT" > strings/0x409/productmkdir -p functions/uac2.usb0echo 48000 > functions/uac2.usb0/c_srateecho 48000 > functions/uac2.usb0/p_srateecho 3 > functions/uac2.usb0/c_chmaskecho 3 > functions/uac2.usb0/p_chmaskecho 2 > functions/uac2.usb0/c_ssizeecho 2 > functions/uac2.usb0/p_ssizeecho "$FUNC_NAME" > functions/uac2.usb0/function_namemkdir -p configs/c.1/strings/0x409echo "UAC2 Config" > configs/c.1/strings/0x409/configurationecho 100 > configs/c.1/MaxPowerln -s functions/uac2.usb0 configs/c.1/echo 1 > os_desc/useecho "0xcd" > os_desc/b_vendor_codeecho "MSFT100" > os_desc/qw_signln -s configs/c.1 os_desc/c.1UDC_NAME=$(ls /sys/class/udc | head -n 1)echo "$UDC_NAME" > UDCecho "UAC2 Gadget enabled on $UDC_NAME with MaxPower=100mA"
But as before, Windows can read it normally, while Android and iOS still cannot recognize it.

Statistics: Posted by lucifd — Thu Nov 27, 2025 7:47 am — Replies 1 — Views 16



Viewing all articles
Browse latest Browse all 7503

Trending Articles