Changing audio GPIO pins?
Tristan M. (2946) 1039 posts |
I have tried searching and was probably using the wrong magic words. My plan here is to buy an Orange Pi lite or something to free up my Zero from media server / NAS duty so the Zero can be used for RISC OS any time. It seems to be happier than the Pi3 with it at this point. |
Rick Murray (539) 13840 posts |
I think the first question is – what does the PWM audio? RISC OS/Linux or thé firmware? If thé latter, is it possible on the Zero? |
Jeffrey Lee (213) 6048 posts |
AIUI RISC OS doesn’t alter any of the GPIO settings, so the default will be set at whatever the firmware leaves it as (I’m not sure what that would be for the Zero). Presumably you could fairly easily put together some code to reconfigure the pins using e.g. the GPIO module and then put it in your boot sequence.
The firmware handles PWM audio. It is supported on the Zero, you just need to build your own output filter and (I think) fiddle with the GPIO configuration. |
Tristan M. (2946) 1039 posts |
Great! I seem to recall I saw something that says something can be added to config.txt to specify a DTO for changing the PWM audio pins of a Pi Zero without extra resources, however I haven’t tried it. Perhaps I’m just a dummy but everything I have read on DTOs has never said explicitly if / how they interact with an OS (probably Raspbian). I was hoping for a little enlightenment here. When I have some time I’ll give it a go. I’ll just chuck a multimeter on one of the pins to see if something happens before getting out the soldering iron. Well, now I’ve finally worked out how to talk to the IO controller I can change the pin modes if necessary. It’s a little bit of an aside, and I’m not sure if it’s my imagination but I was trying out audio using different combinations of things on Raspbian and RISC OS on the Pi 3, but I swear in RISC OS it’s louder and has less hiss. Sadly they are both beaten by the cheap 7.1 channel USB dongle. We actually bought it a while back because it was recommended on some site for use with the mic. It worked really well for that. I never even bothered setting up the phantom power supply to drive the mic. The level was a touch low but not terrible. Amazing for a PC mic connector though. I ordered an Orange Pi PC to take over the role of NAS / UPnP server from the Zero. It will hopefully be here in a month or two :( I also ordered a neat little thingy for the Zero. It’s a 3 port USB hub with an Ethernet adaptor with a RISC OS supported chipset and a Micro USB OTG connector. It also has a 5v power connector. Talk about lots of birds with one stone. It’ll probably be a couple of days before I can spare time to check whether just changing config.txt works but I’ll let you all know when I do. |
Chris Evans (457) 1614 posts |
I believe we had to set up GPIO appropriately but I can confirm that when we connected up a Pi Zero’s PWM Audio pins to a circuit copied from the B+ schematic it worked fine under RISC OS! One of great things about the Pi is that most hardware aspects are set up by start.elf and can then be controlled by config.txt or GPIO settings. n.b. In this case config.txt isn’t used to control things, but for the record an authoritative list of what config.txt can do, is now on the official site at:https://www.raspberrypi.org/documentation/configuration/config-txt.md |
Clive Semmens (2335) 3276 posts |
Are these the same for all models of Pi? |
Jeffrey Lee (213) 6048 posts |
There are at least a couple of config.txt settings that can influence PWM audio quality (avoid_pwm_pll and disable_audio_dither), so there’s a good chance it’s one of those which is set differently.
Yes, the config.txt settings listed on that page should apply to all models of Pi. |
Tristan M. (2946) 1039 posts |
Hi! I stole some time to do a little test. Honestly I should be sleeping but I really wanted to test it. I snatched this line from AdaFruit to go in config.txt As it was pointed out to me, it won’t work out of the box. GPIO 13 had to be changed to ALT 0 and GPIO 18 to ALT 5. After changing my all-elbows GPIO program to do this, I fired up an MP3 in DigitalCD to test. It appears to work fine. Jeffrey, I did a little reading and what you said makes sense about the audio options. I’m looking forward to building a filter, and when the preamp arrives, building and connecting it too. addendum: |
Tristan M. (2946) 1039 posts |
Time’s a bit limited so I haven’t had a chance to make a filter board, but my preamp arrived and I built it. Even though it’s a cheap Chinese valve preamp and playing through my TDK noise cancelling earbuds (also inexpensive), the Pi 3 internal audio sounds really good. Yes, it’s going to be a monstrosity of a thing using a Pi Zero, PWM audio, a valve preamp and RISC OS. Not quite an Archimedes but still something fun. |
Tristan M. (2946) 1039 posts |
Again, time issues. However I did manage to scavenge up the right caps and resistors to test the PWM output on a breadboard with a speaker from a broken earbud plugged in. High tech, I know. I couldn’t find a jack. As it is I’m pretty sure all the components I used were 30 years old minimum but they all check out. I have a suspicion that with the correct incantation to config.txt the GPIO pins could be initialised correctly for output without the need to fiddle them after boot. What exactly is a bit more of a mystery. Info on config.txt is pretty scattered and incomplete with varying levels of age and obsolescence. |
Tristan M. (2946) 1039 posts |
I thought somebody might appreciate this. It’s version 1 of the audio for my Pi Zero. There was however an issue with the 3.5mm plug sticking out a fraction of a mm too far and preventing it from seating correctly. It’s been rearranged so it’s connected in a rather fragile manner to a 4 pin connector. It’s only temporary. I’ve ordered some board mount 3.5mm stereo jacks. They’ll be here any month! It works fine. Sounds good. I can confirm it can talk to the RTC and the bonus EEPROM in Raspbian, and the Ethernet is unconfirmed. I can’t seem to work out inline pics. Sorry. |
Chris Evans (457) 1614 posts |
The link I posted https://www.raspberrypi.org/documentation/configuration/config-txt.md is on the official RPF site so should be authoritative. If you think anything is missing, confusing or wrong, I’m sure they would love feedback via the forums! Or it does say “View/Edit this page on GitHub” |
Tristan M. (2946) 1039 posts |
Chris, It seems to be a bit more comprehensive now. The dtoverlay link needs some work though I think. |