WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [SOLVED] Audio over PWM on PiZero  (Read 9842 times)

Offline yojk

  • Newbie
  • *
  • Posts: 4
[SOLVED] Audio over PWM on PiZero
« on: November 26, 2016, 04:55:38 AM »
Hello everybody,
I really like the piCore for Raspberry Pis. I've installed piCore on my Pi1B, so that this plays a webradio over the 3,5mm Audio Jack. Everything worked well, then I got a Pi Zero and I wanted to try this as well.
When I connect the Pi Zero with an HDMI Monitor everything works same as on the Pi1B connected to the HDMI Monitor (digital audio output over HDMI).
Now I wanted to set up an analogue audio output on the PiZero. So that I can directly connect speakers to the PiZero Webradio.

I started by following this:
https://learn.adafruit.com/adding-basic-audio-ouput-to-raspberry-pi-zero/pi-zero-pwm-audio#low-pass-filter-wiring
but with GPIO13 as PWM1 and GPIO12 as PWM0

By installing wiringpi.tcz and setting the gpios:
Code: [Select]
sudo gpio -g mode 12 pw
sudo gpio -g mode 13 pw
I didn't follow the instruction because dtoverlay in /boot/config.txt didn't change anything and I couldn't compile the gpio_alt.c. But I thought if GPIO readout looks good, that should work too.

The GPIO readout seems good:
Code: [Select]
+-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | ALT0 | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 | ALT0 | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | ALT0 | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | ALT0 | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+

But I still don't get an audio signal out of the gpio pins.
By using
Code: [Select]
aplay honkhonk.wav, there is no error but also no audio
By using
Code: [Select]
speaker-test, I get:
Code: [Select]
speaker-test 1.1.1

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 512 to 32768
Period size range from 512 to 32768
Using max buffer size 32768
Periods = 4
was set period_size = 8192
was set buffer_size = 32768
 0 - Front Left
Write error: -5,Input/output error
xrun_recovery failed: -5,Input/output error
Transfer failed: Input/output error

And by using
Code: [Select]
mpg123 <Webradiourl>, there is also a error:
Code: [Select]
...
MPEG 1.0 L III cbr128 48000 stereo
[src/libout123/modules/alsa.c:238] error: Fatal problem with alsa output, error -5.
[src/libout123/libout123.c:634] error: Error in writing audio (Input/output error?)!
main: [src/mpg123.c:832] error: Deep trouble! Cannot flush to my output anymore!

I'm not so experienced with Linux, so I don't now where to continue.
I hope someone has any hints, what I can do to get the analogue audio signal over the gpios.
Also I'm starting to doubt, if PWM0 over GPIO12 is still possible on PiZero. But then PWM1 audio over GPIO13 should work anyway, isn't it?

Thanks a lot in advance for your efforts and hints,
yojk




« Last Edit: November 26, 2016, 10:54:35 AM by Rich »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Audio over PWM on PiZero
« Reply #1 on: November 26, 2016, 05:43:27 AM »
Are you running programs as root or tc user?
 
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Audio over PWM on PiZero
« Reply #2 on: November 26, 2016, 05:46:39 AM »
Download a copy and keep it handy: Core book ;)

Offline yojk

  • Newbie
  • *
  • Posts: 4
Re: Audio over PWM on PiZero
« Reply #3 on: November 26, 2016, 06:40:29 AM »
Hi
This might help
http://forum.tinycorelinux.net/index.php/topic,19409.msg119615.html#msg119615

Still same error

Are you running programs as root or tc user?

The normal webradio script would be run as root, but the described tests were made as tc.
When I run speaker-test as root, there is still the same error.

Offline yojk

  • Newbie
  • *
  • Posts: 4
Re: Audio over PWM on PiZero
« Reply #4 on: November 26, 2016, 06:51:58 AM »
Hello again,
I didn't add the gpio settings in bootsync yet, now after I did everything works.
so using pwm audio output over GPIO 12 and GPIO 13 works with the following lines in /opt/bootsync.sh:
Code: [Select]
/usr/local/bin/gpio -g mode 13 pwm
/usr/local/bin/gpio -g mode 12 pwm

Afterwards it seems, that it configures itself.

Sorry for brothering you and thank you for your help.

Offtopic:
Is there a possibility to mark an Topic solved?
« Last Edit: November 26, 2016, 07:00:30 AM by yojk »

Offline creitzel

  • Newbie
  • *
  • Posts: 36
Re: [SOLVED] Audio over PWM on PiZero
« Reply #5 on: March 27, 2021, 01:06:14 PM »
Sorry to resurrect a dead thread, but I think I'm having the same problem as the OP trying to get my pi zero to redirect audio out of the gpio pins. 

I have tried all of the tutorials/references I have found on the web, including the one's mentioned above:

I've tried several configurations to try and get it to work, including:
  • using dt_overlay=pwm, dt_overlay=pwm_2chan settings in config.txt
  • the OP's method of using wiringpi and assigning pwm to pins 12 and 13
  • using pins 18 and 19 instead of 12 and 13.

no matter which method I try, I never get any audio when using the alsa speaker-test utility. 

I'm fairly experienced with linux, and raspberry pi's, even piCore which I've used in a previous project or 2, but I'm a relative newbie when it comes to the pi's audio, and alsa in general.  So, is there a tutorial that I'm missing somewhere, or something that could walk me through from start to finish in getting this setup and working?

Thanks in advance for any assistance you guys can give me.

Chris

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: [SOLVED] Audio over PWM on PiZero
« Reply #6 on: March 27, 2021, 01:35:46 PM »
I can't help directly, but here are a couple of points:

- wiringpi is depeciated
- the in-built sound card changed name from ALSA, to Heaphones, b1 and b2 is recently builds.

Offline creitzel

  • Newbie
  • *
  • Posts: 36
Re: [SOLVED] Audio over PWM on PiZero
« Reply #7 on: March 28, 2021, 09:42:11 AM »
Thanks for the quick reply!  :-)

I can't help directly, but here are a couple of points:

- wiringpi is depeciated
- the in-built sound card changed name from ALSA, to Heaphones, b1 and b2 is recently builds.

Ok, so if wiringpi is deprecated, then what is the current recommended way for accessing the gpio in piCore?

And, as I'm a newbie to audio on the pi, where does the "in built sound card" come into play?, is there some selection somewhere in the alsa libraries that I need to be pointing at "Headphones", instead of "ALSA"?  Or, is there a completely different library that I should be using?

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: [SOLVED] Audio over PWM on PiZero
« Reply #8 on: March 28, 2021, 02:00:08 PM »
Sorry I don't use pure piCore so I can't give you the details, just pointing out things have changed recently.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1063
Re: [SOLVED] Audio over PWM on PiZero
« Reply #9 on: March 29, 2021, 09:48:30 AM »
alsa and the alsa kernel modules extensions are not on the image, you need to download/install them.  What does dmesg say about sound modules?  You may need to manually load the bcm2835 sound modules.

as for setting the gpio pins, do that from the config.txt with overlays, there should be no need for command line tools.   


Offline creitzel

  • Newbie
  • *
  • Posts: 36
Re: [SOLVED] Audio over PWM on PiZero
« Reply #10 on: March 29, 2021, 02:55:18 PM »
Thanks for the reply Paul,

alsa and the alsa kernel modules extensions are not on the image, you need to download/install them. 

Yes, I figured this out, before I posted.  I have downloaded and installed the following TCZ's:
  • alsa.tcz
  • alsa-modules-4.19.81-piCore.tcz
  • alsa-utils.tcz
I'm attempting to get this working with piCore v 11.0 BTW

What does dmesg say about sound modules?  You may need to manually load the bcm2835 sound modules.

The only thing I can find in dmesg related to sound/audio are the following 2 lines, which appear to me to say that it is finding the kernel modules, and correctly creating the sound card device:

Code: [Select]
[   19.759223] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[   20.005672] bcm2835_audio soc:audio: card created with 8 channels

I'm not quite sure why I'm getting the warning, I'm pretty sure I just used
Quote
tce-load -iw alsa.tcz
to install the alsa modules.

Just in case you need to see more of the dmesg output, here it is in it's entirety:

Code: [Select]
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.19.81-piCore (root@box) (gcc version 8.1.0 (piCore)) #1 Sun Nov 3 14:08:10 UTC 2019
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] OF: fdt: Machine model: Raspberry Pi Zero W Rev 1.1
[    0.000000] Memory policy: Data cache writeback
[    0.000000] cma: Reserved 8 MiB at 0x1b000000
[    0.000000] On node 0 totalpages: 114688
[    0.000000]   Normal zone: 1008 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 114688 pages, LIFO batch:31
[    0.000000] random: get_random_bytes called from start_kernel+0x90/0x4a4 with crng_init=0
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:5D:0D:D6 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=/dev/ram0 elevator=deadline rootwait quiet nortc loglevel=3 noembed nozswap
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 429736K/458752K available (6960K kernel code, 632K rwdata, 2084K rodata, 456K init, 796K bss, 20824K reserved, 8192K cma-reserved)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xdc800000 - 0xff800000   ( 560 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xdc000000   ( 448 MB)
[    0.000000]     modules : 0xbf000000 - 0xc0000000   (  16 MB)
[    0.000000]       .text : 0x(ptrval) - 0x(ptrval)   (6961 kB)
[    0.000000]       .init : 0x(ptrval) - 0x(ptrval)   ( 456 kB)
[    0.000000]       .data : 0x(ptrval) - 0x(ptrval)   ( 633 kB)
[    0.000000]        .bss : 0x(ptrval) - 0x(ptrval)   ( 797 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] ftrace: allocating 25190 entries in 74 pages
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000031] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
[    0.000080] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.000196] bcm2835: system timer (irq = 27)
[    0.000599] Console: colour dummy device 80x30
[    0.000625] console [tty1] enabled
[    0.000694] Calibrating delay loop... 697.95 BogoMIPS (lpj=3489792)
[    0.060341] pid_max: default: 32768 minimum: 301
[    0.060883] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.060903] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.062302] CPU: Testing write buffer coherency: ok
[    0.063617] Setting up static identity map for 0x8200 - 0x8238
[    0.065004] devtmpfs: initialized
[    0.076304] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
[    0.076711] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.076742] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.078104] pinctrl core: initialized pinctrl subsystem
[    0.079648] NET: Registered protocol family 16
[    0.083065] DMA: preallocated 1024 KiB pool for atomic coherent allocations
[    0.090318] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers.
[    0.090334] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.090566] Serial: AMBA PL011 UART driver
[    0.093784] bcm2835-mbox 2000b880.mailbox: mailbox enabled
[    0.138214] bcm2835-dma 20007000.dma: DMA legacy API manager at (ptrval), dmachans=0x1
[    0.140717] SCSI subsystem initialized
[    0.141164] usbcore: registered new interface driver usbfs
[    0.141285] usbcore: registered new interface driver hub
[    0.141465] usbcore: registered new device driver usb
[    0.160956] raspberrypi-firmware soc:firmware: Attached to firmware from 2020-05-22 21:12, variant start
[    0.170971] raspberrypi-firmware soc:firmware: Firmware hash is 4da3e1264076308eda90652cb98b553ae0586390
[    0.183449] clocksource: Switched to clocksource timer
[    0.290040] VFS: Disk quotas dquot_6.6.0
[    0.290167] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.290500] FS-Cache: Loaded
[    0.290848] CacheFiles: Loaded
[    0.309672] NET: Registered protocol family 2
[    0.310994] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes)
[    0.311058] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
[    0.311128] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[    0.311200] TCP: Hash tables configured (established 4096 bind 4096)
[    0.311362] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.311395] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.311826] NET: Registered protocol family 1
[    0.312914] RPC: Registered named UNIX socket transport module.
[    0.312927] RPC: Registered udp transport module.
[    0.312932] RPC: Registered tcp transport module.
[    0.312938] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.313365] Trying to unpack rootfs image as initramfs...
[    0.945554] Freeing initrd memory: 4704K
[    0.968241] hw perfevents: no irqs for PMU, sampling events not supported
[    0.968308] hw perfevents: enabled with armv6_1176 PMU driver, 3 counters available
[    0.972486] Initialise system trusted keyrings
[    0.972919] workingset: timestamp_bits=14 max_order=17 bucket_order=3
[    0.988439] FS-Cache: Netfs 'nfs' registered for caching
[    0.989752] NFS: Registering the id_resolver key type
[    0.989802] Key type id_resolver registered
[    0.989810] Key type id_legacy registered
[    0.989839] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.996115] Key type asymmetric registered
[    0.996132] Asymmetric key parser 'x509' registered
[    0.996246] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[    0.996708] io scheduler noop registered
[    0.996722] io scheduler deadline registered (default)
[    0.997337] io scheduler cfq registered
[    0.997353] io scheduler mq-deadline registered (default)
[    0.997362] io scheduler kyber registered
[    1.000145] bcm2708_fb soc:fb: FB found 1 display(s)
[    1.009500] Console: switching to colour frame buffer device 82x26
[    1.014480] bcm2708_fb soc:fb: Registered framebuffer for display 0, size 656x416
[    1.016500] Serial: 8250/16550 driver, 1 ports, IRQ sharing enabled
[    1.019366] bcm2835-rng 20104000.rng: hwrng registered
[    1.019878] vc-mem: phys_addr:0x00000000 mem_base=0x1ec00000 mem_size:0x20000000(512 MiB)
[    1.020956] vc-sm: Videocore shared memory driver
[    1.021607] gpiomem-bcm2835 20200000.gpiomem: Initialised: Registers at 0x20200000
[    1.042178] brd: module loaded
[    1.055721] loop: module loaded
[    1.056610] Loading iSCSI transport class v2.0-870.
[    1.057578] usbcore: registered new interface driver smsc95xx
[    1.057611] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    1.585660] dwc_otg 20980000.usb: base=(ptrval)
[    1.786027] Core Release: 2.80a
[    1.786060] Setting default values for core params
[    1.786095] Finished setting default values for core params
[    1.986470] Using Buffer DMA mode
[    1.986486] Periodic Transfer Interrupt Enhancement - disabled
[    1.986492] Multiprocessor Interrupt Enhancement - disabled
[    1.986504] OTG VER PARAM: 0, OTG VER FLAG: 0
[    1.986617] Dedicated Tx FIFOs mode
[    1.987520] WARN::dwc_otg_hcd_init:1045: FIQ DMA bounce buffers: virt = db114000 dma = 0x5b114000 len=9024
[    1.987547] FIQ FSM acceleration enabled for :
[    1.987547] Non-periodic Split Transactions
[    1.987547] Periodic Split Transactions
[    1.987547] High-Speed Isochronous Endpoints
[    1.987547] Interrupt/Control Split Transaction hack enabled
[    1.987562] dwc_otg: Microframe scheduler enabled
[    1.987745] WARN::hcd_init_fiq:457: FIQ on core 0
[    1.987762] WARN::hcd_init_fiq:458: FIQ ASM at c04ff490 length 36
[    1.987790] WARN::hcd_init_fiq:497: MPHI regs_base at dc810000
[    1.987823] dwc_otg 20980000.usb: DWC OTG Controller
[    1.987916] dwc_otg 20980000.usb: new USB bus registered, assigned bus number 1
[    1.987992] dwc_otg 20980000.usb: irq 56, io mem 0x00000000
[    1.988046] Init: Port Power? op_state=1
[    1.988052] Init: Power Port (0)
[    1.988456] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 4.19
[    1.988474] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    1.988486] usb usb1: Product: DWC OTG Controller
[    1.988496] usb usb1: Manufacturer: Linux 4.19.81-piCore dwc_otg_hcd
[    1.988506] usb usb1: SerialNumber: 20980000.usb
[    1.989611] hub 1-0:1.0: USB hub found
[    1.989711] hub 1-0:1.0: 1 port detected
[    1.990786] dwc_otg: FIQ enabled
[    1.990798] dwc_otg: NAK holdoff enabled
[    1.990804] dwc_otg: FIQ split-transaction FSM enabled
[    1.990823] Module dwc_common_port init
[    1.991376] usbcore: registered new interface driver usb-storage
[    1.991800] mousedev: PS/2 mouse device common for all mice
[    1.993251] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer
[    1.993819] bcm2835-cpufreq: min=700000 max=1000000
[    1.995832] sdhci: Secure Digital Host Controller Interface driver
[    1.995840] sdhci: Copyright(c) Pierre Ossman
[    1.996323] mmc-bcm2835 20300000.mmcnr: could not get clk, deferring probe
[    1.996836] sdhost-bcm2835 20202000.mmc: could not get clk, deferring probe
[    1.997013] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.997460] ledtrig-cpu: registered to indicate activity on CPUs
[    1.997572] hidraw: raw HID events driver (C) Jiri Kosina
[    1.997763] usbcore: registered new interface driver usbhid
[    1.997769] usbhid: USB HID core driver
[    1.998642] vchiq: vchiq_init_state: slot_zero = (ptrval), is_master = 0
[    2.000152] [vc_sm_connected_init]: start
[    2.008024] [vc_sm_connected_init]: end - returning 0
[    2.009315] Initializing XFRM netlink socket
[    2.009367] NET: Registered protocol family 17
[    2.009487] Key type dns_resolver registered
[    2.010858] registered taskstats version 1
[    2.010884] Loading compiled-in X.509 certificates
[    2.027193] zbud: loaded
[    2.028221] zswap: loaded using pool lzo/zbud
[    2.035818] uart-pl011 20201000.serial: cts_event_workaround enabled
[    2.035927] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[    2.037699] console [ttyS0] disabled
[    2.037746] 20215040.serial: ttyS0 at MMIO 0x0 (irq = 53, base_baud = 50000000) is a 16550
[    2.037812] console [ttyS0] enabled
[    2.039137] mmc-bcm2835 20300000.mmcnr: mmc_debug:0 mmc_debug2:0
[    2.039151] mmc-bcm2835 20300000.mmcnr: DMA channel allocated
[    2.067284] sdhost: log_buf @ (ptrval) (5b113000)
[    2.103249] mmc1: queuing unknown CIS tuple 0x80 (2 bytes)
[    2.104227] random: fast init done
[    2.104908] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    2.106526] mmc1: queuing unknown CIS tuple 0x80 (3 bytes)
[    2.109428] mmc1: queuing unknown CIS tuple 0x80 (7 bytes)
[    2.114846] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[    2.116194] of_cfs_init
[    2.116306] of_cfs_init: OK
[    2.120087] Freeing unused kernel memory: 456K
[    2.120097] This architecture does not have kernel memory protection.
[    2.120102] Run /init as init process
[    2.203863] Indeed it is in host mode hprt0 = 00021501
[    2.274117] mmc0: host does not support reading read-only switch, assuming write-enable
[    2.278278] mmc0: new high speed SDHC card at address aaaa
[    2.282651] mmcblk0: mmc0:aaaa SU32G 29.7 GiB
[    2.314202] mmc1: new high speed SDIO card at address 0001
[    2.377736]  mmcblk0: p1 p2 p3
[    2.523573] usb 1-1: new high-speed USB device number 2 using dwc_otg
[    2.523758] Indeed it is in host mode hprt0 = 00001101
[    2.844173] usb 1-1: New USB device found, idVendor=1a40, idProduct=0101, bcdDevice= 1.11
[    2.844201] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[    2.844209] usb 1-1: Product: USB 2.0 Hub
[    2.845126] hub 1-1:1.0: USB hub found
[    2.845248] hub 1-1:1.0: 4 ports detected
[    3.951294] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    7.734006] Adding 1999996k swap on /dev/mmcblk0p3.  Priority:-2 extents:1 across:1999996k SSFS
[    8.031558] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[    8.235820] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[   19.697415] i2c /dev entries driver
[   19.710053] uart-pl011 20201000.serial: no DMA platform data
[   19.759223] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[   20.005672] bcm2835_audio soc:audio: card created with 8 channels
[   20.682420] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[   20.808290] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[   20.808497] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[   20.808508] cfg80211: failed to load regulatory.db
[   20.885989] brcmfmac: F1 signature read @0x18000000=0x1541a9a6
[   20.903784] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43430-sdio for chip BCM43430/1
[   20.904112] usbcore: registered new interface driver brcmfmac
[   21.183613] brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43430-sdio for chip BCM43430/1
[   21.183773] brcmfmac: brcmf_c_process_clm_blob: no clm_blob available (err=-2), device may have limited channels available
[   21.184699] brcmfmac: brcmf_c_preinit_dcmds: Firmware: BCM43430/1 wl0: Oct 22 2019 01:59:28 version 7.45.98.94 (r723000 CY) FWID 01-3b33decd
[   28.631834] random: crng init done
[   28.744524] NET: Registered protocol family 10
[   28.752178] Segment Routing with IPv6
[   30.201404] brcmfmac: power management disabled
[   30.203404] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[   32.385260] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

as for setting the gpio pins, do that from the config.txt with overlays, there should be no need for command line tools.   

I saw the overlay method first and thought it appeared to be the easier path, so I tried it.  I've tried the following overlays:
  • dt_overlay=audremap
  • dt_overlay=pwm
  • dt_overlay=pwm-2chan
I was unable to get any sound using any of these.  I haven't been able to figure out if/how I can verify that the overlay is active, from the command line.  So, it becomes a bit of a dead-end for me.  Is there a utility I can use or something?

I'm also a bit confused about which pins I should be expecting the output on (several references all quoting pin numbers, and not being clear about which pin numbering they are using).  So, if I used an overlay like dt_overlay=audremap am I reading the README file correctly to assume that the left channel should be coming out of GPIO 12 (physical pin 32 on the header), and the right channel should be coming out of GPIO 13 (physical pin 33 on the header)?

Is there someway to verify that I am in fact getting a pwm signal out of the pin?  I ask, because I am connecting the pin to a small board that my buddy built (a band pass filter, and a PAM8403 amplifier), and if I can verify that the pi zero is in fact producing the pwm signal, I think I can focus on the board as the culprit.  I'm definitely not an electronics guy, I just dabble a bit for a hobby, but I do have access to a multimeter, and an oscilloscope, if those would be of any use.

Chris

Offline creitzel

  • Newbie
  • *
  • Posts: 36
Re: [SOLVED] Audio over PWM on PiZero
« Reply #11 on: March 29, 2021, 03:27:59 PM »
Ok, looks like I may have answered at least one of my own questions.  I was asking for a utility to verify that the overlay is active, and it looks like the gpio utility from wiring pi can be used for this.

Executing

Code: [Select]
gpio readall

gives the following output, which seems to indicate that the overlay I am using is in fact active.  (I'm currently using dt_overlay=audremap,pins_18_19=on)

Code: [Select]
+-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT5 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 0 | ALT5 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | ALT5 | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 1 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 1 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 0 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 0 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 0 | 31 || 32 | 0 | ALT0 | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 | ALT0 | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 | ALT5 | 1 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+

Unfortunately, I'm still not getting any sound when hooked up to pin 18. 

I've tried using both speaker-test and aplay to try and play a wav file.  Both of the commands are outputting text that looks like they are working, but no sound.

Chris

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: [SOLVED] Audio over PWM on PiZero
« Reply #12 on: March 29, 2021, 05:51:22 PM »
Hi creitzel
... but I do have access to a multimeter, and an oscilloscope, if those would be of any use.
Disconnect the bandpass filter. Connect the scope to your output pin.
When there is silence, I would expect to see a square wave with a 50% duty cycle.
When you play sound, the waveforms duty cycle should appear to jitter.

Offline creitzel

  • Newbie
  • *
  • Posts: 36
Re: [SOLVED] Audio over PWM on PiZero
« Reply #13 on: March 30, 2021, 05:55:45 PM »
Disconnect the bandpass filter. Connect the scope to your output pin.
When there is silence, I would expect to see a square wave with a 50% duty cycle.
When you play sound, the waveforms duty cycle should appear to jitter.

Ok, I did what you recommended, and I do in fact see the square wave at 50% duty cycle, when playing nothing, and a "jittery" square wave when I use the speaker-test utility. 

Having success with that, I proceeded to hook up the little daughter board, and test with my scope on it, with the following results:

  • At the audio in pin, I get the same results as the pi output pin (expected because they are just 2 ends of the same connection)
  • At the output lead on the capacitor in the filter circuit, I got a typical looking audio signal wave (this was what my buddy said I should expect here).
  • At the audio out pin of the amplifier I got a "jittery" square wave as well (also what my buddy said I should expect, because the amp generates a PWM signal to drive the speaker).

After doing all of that, I still got no audio out of the speaker.  I figured the speaker must be bad, as that was all that was left (although, I just had this same speaker hooked up to an Esp32 with successful results, like a month or so ago).  So, I tested the speaker with an ohm meter, and it appears like I would expect it to (some little resistance, but definitely not an open circuit).

So, next I got out the breadboard and recreated the filter and amp circuit on it, with the same results as when it's all plugged into the daughter board.

Being frustrated at this point, I hooked the speaker directly up to the output pin of the pi, and lo and behold, I could just barely hear the output from the pi.  It is barely audible at all.  I think the pi may be outputting the signal so low, that the filter/amp circuit is basically filtering it all out. 

So, this leads me to my next question.  Is there something I have to do in the alsa configuration to increase the volume of the output?  I've already played around with the alsamixer utility, and I have it set to 100%.  Is there some other setting I'm missing/not aware of?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: [SOLVED] Audio over PWM on PiZero
« Reply #14 on: March 30, 2021, 07:00:51 PM »
Hi creitzel
... I proceeded to hook up the little daughter board, and test with my scope on it, with the following results:

At the audio in pin, I get the same results as the pi output pin (expected because they are just 2 ends of the same connection) ...
Not necessarily. The reason I had you disconnect the bandpass filter was to make sure it wasn't loading down the
output pin of the pi.

Quote
... At the output lead on the capacitor in the filter circuit, I got a typical looking audio signal wave (this was what my buddy said I should expect here) ...
So it sounds like the bandpass filter is working.

Quote
... At the audio out pin of the amplifier I got a "jittery" square wave as well (also what my buddy said I should expect, because the amp generates a PWM signal to drive the speaker). ...
We need some more details at this point. Check the following 2 items with the speaker connected and disconnected:
Does the output of the amp have a (relatively) stable square wave when the pi is playing nothing?
Does the square wave coming from the amp only get jittery when the speaker-test utility gets run?

Quote
... Being frustrated at this point, I hooked the speaker directly up to the output pin of the pi, and lo and behold, I could just barely hear the output from the pi. ...
Since this is an amplifier, you would think the output level should be at least as great as the input level, right?
See if you can barely hear the output when the speaker is connected to the amp.