Sunday, October 4, 2020

A Simple Public Safety Radio Scanner with the Raspberry Pi - Part 3 - Trying to Downsize

 

Raspberry Pi 4 and Raspberry Pi Zero


After I built the amplifier last week for my scanner project, I quickly noticed a bit of a flaw in the design of the Raspberry Pi. 

When I tried to run the SDR in "idle" mode by turning the squelch setting on the rtl_fm application way up, I was still getting a fairly load hissing noise coming from the speaker when I was fully expecting silence. The issue stemmed from the way the sound circuit is configured for the 3.5mm phono plug on the Pi. Due to the size and circuit restraints of the Pi, there isn't a "true" sound card running built-in, meaning that the sound will truly never be high quality. Apparently having a constant hiss when there is no audio output is quite common. 

One option in resolving that is to plug in a dedicated USB soundcard which can be easily bought online for a few dollars, however, when I was doing my research I noticed that you could also use a Raspberry Pi Zero to create fairly decent audio by using its GPIO pins plugged into a pretty simple circuit (the Raspberry Pi Zero doesn't have a built-in sound port) 

I actually liked the idea of using the Pi Zero since it would give me the opportunity to really reduce the size of my scanner. As luck should have it, I also had a Raspberry Pi Zero on hand. 

To have the Pi Zero be able to connect to my amplifier, I needed to build an interface circuit that will act as a bridge between the Pi and the amp. This bridge, usually referred to as an audio HAT is actually a pretty common add on that you can buy from a lot of suppliers, however, when I came across a video by Tinkernut, I found that I could easily build my own audio HAT. 

The circuit itself was very easy to make needing only a handful of common components:

  • Two 270 Ohm resistors
  • Two 150 Ohm resistors
  • Two 10uf capacitors
  • Two 0.01uf capacitors.

After watching the video a few times, I was eventually able to replicate the circuit that he built on a breadboard - I won't go through the build itself the video does do a good job of explaining things and I do highly recommend that you check it out!



Audio HAT circuit

Part of the build needed to have a connection between the Ground, GPIO13, and GPIO18 connectors on the Pi Zero. Normally this would require careful soldering in a series of pins into the connectors. 

Raspberry Pi Zero GPIO pins

However, since I was only really interested in the three of the connectors on the Pi, I took 3 lengths of breadboard wire. and I soldered a wire to each of the pins that I was interested in. 

Pi Zero and wire

Soldering the wire to the GPIO connectors

Pi Zero wired up

Before the Pi could make any noise, I had to first configure the GPIO pins. To do this I had to make a change to the Config.txt file in the Raspbian boot directory, which I did by typing this command at the Pi's command prompt:

sudo nano /boot/config.txt

Once the config file was open, I paged down to the boot of the file and added this line item:

dtoverlay pwm=2-chan,pin=18,func=2,pin2=13,func2=4

I then saved the config file and rebooted the Raspberry Pi 

Once I had all the pins soldered up. I plugged the Pi into the audio HAT, hooked the output of the audio HAT to the input of my amp, and gave it a whirl. 

Pi hooked up to the audio HAT

I first started by playing a test sound (.wav) file that can as part of the built-in utilities that are included with Raspbian. 

To play a sample sound file, I called the aplay utility to play the file:

aplay /usr/share/sounds/alsa/Front_Center.wav

I was immediately greeted by a female voice that simply said "Front, Center"

Now that I know the audio circuit was working perfectly, I plugged my SDR dongle into the Pi and I entered the rtl_fm command to pull in my local FM station. 

I was immediately greeted with a wall of static. After trying a few different tweaks in the software settings for the dongle, I still was not having any success, even though the Pi Zero was set up almost identical to the Pi 4 that I had used earlier. 

After some fruitless tinkering, I hit up the internet for some clues. The short answer was the Pi Zero just simply did not have the horsepower needed to do the necessary conversion of radio signals to sound. 

While the Pi Zero behaves very much like any other Pi, the key difference is in the processor that is used. 

A typical Raspberry Pi that is available today has a quad-core processor, while the Pi Zero only has a single processor onboard - basically, a Pi Zero only has about a quarter of the processing power of a regular Pi. 

On my regular Raspberry Pi, I was finding that processing the radio signal was taking about 20% of the available CPU. If you factor that with the CPU on the Pi Zero this meant that almost all of the CPU would have been needed to do this. I was effectively overwhelming my Pi Zero. 

So, while I know now how to get sound out of a Raspberry Pi Zero, unfortunately, I was stuck with using my Raspberry Pi 4 for my scanner project.  

No comments:

Post a Comment