Raspberry Pi & Soundmodem – It works!!

It is a bout time for an update on my Raspberry Pi APRS project.

and a messy desk!

Two raspberry pi computers, a 32″ display, and a messy desk!

(Part 01)

Many months ago I was working on getting a Raspberry Pi working for APRS work. I was experiencing a ton of issues with getting soundmodem to decode aprs signals that were known to be good (ie. ideal recording played back as an MP3 file, no RF involved).

Raspberry Pi (Model B) in a clear protective case.

Raspberry Pi (Model B) in a clear protective case.

Most recently, I have managed to get the Raspberry Pi and soundmodem to play nicely with a USB soundcard (the Creative SB1140)! Finally some success – some of which I attribute to a more polished distribution.

In my previous attempts, I tried advanced commands such as setting the dwc_otg.speed=1 flag in (/boot/cmdline.txt) which did not solve the issue(s).

I installed a new image of the Wheezy Raspbian distro (2013-09-25-wheezy-raspbian.zip), and so a software update was in order. To facilitate the update, I logged into the shell and issued the following commands:

sudo apt-get update
sudo apt-get upgrade
SSH shell connection to Raspberry Pi

SSH shell connection to Raspberry Pi

It should be noted that you do not need to connect the Raspberry Pi to an external display to complete this work – yes it may be easier, however, there is another way! You can connect to the Pi by using an SSH client such as Putty. All you need is the local IP address of the Pi (as a tip, log in to your router and look for the clients listed in the DHCP table).

Once the core operating system was updated, I installed some of the components which would be needed for operating an APRS gateway:

sudo apt-get install screen build-essential python-serial sqlite3 python-dev soundmodem libax25 libax25-dev ax25-tools ax25-apps libax25-dev

The above command downloads and installs ~47Mb of binaries and takes some time to complete. Once the desired software was installed, I had some fiddling to do with how the system recognizes the USB sound card.

To eliminate as many variables as possible, I told the system to ignore the on-board sound card (output only, so useless) by modifying /etc/modules as follows:

sudo vi /etc/modules

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with “#” are ignored.
# Parameters can be specified after the module name.
#snd-bcm2835
snd-usb-audio

Next, I modified /etc/asound.conf as follows:

sudo vi /etc/asound.conf

pcm.dmixer{
type    dmix
ipc_key 1024
slave   {
pcm     “hw:0,0”
period_time     0
period_size     1024
buffer_size     8192
rate    48000
}
bindings        {
0       0
1       1
}
}
pcm.asymed      {
type    asym
playback.pcm    “dmixer”
capture.pcm     “hw:0,0”
}
pcm.dsp0        {
type    plug
slave.pcm       “asymed”
}
pcm.!default    {
type    plug
slave.pcm       “asymed”
}
pcm.default     {
type    plug
slave.pcm       “asymed”
}
ctl.mixer0      {
type    hw
card    0
}

Next, a basic soundmodem configuration is established. This is the core of the software TNC so take some time to learn the ins and outs of this configuration file.

sudo vi /etc/ax25/soundmodem.conf

<?xml   version=”1.0″?>
<modem>
<configuration name=”AX25″>
<chaccess txdelay=”250″ slottime=”100″ ppersist=”40″ fulldup=”0″ txtail=”100″/>
<audio type=”alsa” device=”plughw:0,0″ halfdup=”1″ capturechannelmode=”Mono”/>
<ptt file=”none” hamlib_model=”” hamlib_params=”” gpio=”0″/>
<channel name=”sm0″><mod mode=”afsk” bps=”1200″ f0=”1200″ f1=”2200″ diffenc=”1″ inlv=”8″ fec=”1″ tunelen=”32″ synclen=”32″/>
<demod mode=”afsk” bps=”1200″ f0=”1200″ f1=”2200″ diffdec=”1″ inlv=”8″ fec=”3″ mintune=”16″ minsync=”16″/>
<pkt mode=”MKISS” ifname=”sm0″ hwaddr=”NOCALL-05″ ip=”44.128.0.2″ netmask=”255.255.255.0″ broadcast=”44.128.0.255″ file=”/dev/soundmodem0″ unlink=”1″/>
</channel>
</configuration>
</modem>

Be sure to replace the NOCALL-05 with your own call-sign to ensure that the APRS packets conform to regulations! The txdelay=250 and txtail=100 are to add a time-delay for VOX operation – these values could be tweaked if you are using a hardware PTT.

Raspberry Pi GPIO (general purpose input / output) header & serial adapter.

Raspberry Pi GPIO (general purpose input / output) header & serial adapter.

Speaking of hardware PTT – it is a somewhat common problem when working with a Pi that a USB to serial adapter may malfunction. It would be advisable to use one of the GPIO pins of the Pi in order to toggle the PTT for your radio.

I may use a GPIO to serial adapter which was purchased on eBay for less than the cost of the materials. It is simple enough to use the GPIO pin directly, just be aware that the Pi is not able to source a large current so it would be prudent to use a transistor to drive an optocoupler for galvanic isolation of the Pi from the radio.

Edit the axports file to include a statement for soundmodem and your callsign(with SSID – ie. -05). This file assists in setting up an AX.25 port which acts as a network adapter. We will use this functionality later to produce AX.25 packets which we can use / listen to in order to verify functionality and to set output levels.

sudo vi /etc/ax25/axports

# /etc/ax25/axports
#
# The format of this file is:
#
# name callsign speed paclen window description
#
sm0     VE3BUX-05       1200    255     2       VHF APRS (1200 bps)
#1      OH2BNS-1        1200    255     2       144.675 MHz (1200  bps)
#2      OH2BNS-9        38400   255     7       TNOS/Linux  (38400 bps)

Next I modified the alsa-base.conf file found in /etc/modprobe.d so that it was as follows:

sudo vi /etc/modprobe.d/alsa-base.conf

# autoloader aliases
install sound-slot-0 /sbin/modprobe snd-card-0
install sound-slot-1 /sbin/modprobe snd-card-1
install sound-slot-2 /sbin/modprobe snd-card-2
install sound-slot-3 /sbin/modprobe snd-card-3
install sound-slot-4 /sbin/modprobe snd-card-4
install sound-slot-5 /sbin/modprobe snd-card-5
install sound-slot-6 /sbin/modprobe snd-card-6
install sound-slot-7 /sbin/modprobe snd-card-7
# Cause optional modules to be loaded above generic modules
install snd /sbin/modprobe –ignore-install snd && { /sbin/modprobe –quiet snd-ioctl32 ; /sbin/modprobe –quiet snd-seq ; : ; }
install snd-rawmidi /sbin/modprobe –ignore-install snd-rawmidi && { /sbin/modprobe –quiet snd-seq-midi ; : ; }
install snd-emu10k1 /sbin/modprobe –ignore-install snd-emu10k1 && { /sbin/modprobe –quiet snd-emu10k1-synth ; : ; }
options snd slots=snd_bcm2835,snd_usb_audio
options snd_usb_audio index=0
#options snd_bcm2835 index=-2
# I commented the above line out as I found it was ineffective at blocking the snd_bcm2835 from being loaded
# Prevent abnormal drivers from grabbing index 0
options bt87x index=-2
options cx88_alsa index=-2
options snd-atiixp-modem index=-2
options snd-intel8x0m index=-2
options snd-via82xx-modem index=-2

The intent in the alsa-base.conf file is to preemptively load the USB sound card, blocking the built-in one from taking index=0 (the default device).

Audio test bench for soundmodem testing.

Audio test bench for soundmodem testing.

So by this point, all should be going well and your system will likely work just fine. We can now start testing by recording and playing back audio handled by the USB sound card. For my initial tests, I simply plugged the USB sound card’s mic jack into the speaker output of my computer and played some audio. I recorded the incoming audio as follows:

arecord -vv ~/testaudio.wav

You can then play back the audio to check your levels by issuing the following command:

aplay ~/testaudio.wav

If you wish to adjust the levels, simply run:

sudo alsamixer

Press F5 to display all “devices” associated to your USB sound card. Using the arrow keys, select the parameter you wish to change and exit by pressing “ESC”.

To check that soundmodem will handle AX25 network traffic, issue the following commands:

sudo screen -dmS sm soundmodem
sudo /sbin/route add -net 44.0.0.0 netmask 255.0.0.0 dev sm0
ping -i 5 44.128.0.1

You should now hear the familiar sound of packtets, provided you are monitoring the output audio of the USB sound card using a speaker or headphones. To see what soundmodem is doing in the background, you can “attach” to the screen as follows:

sudo screen -r sm

To exit the screen without killing the soundmodem daemon, press Ctl-A then while holding Ctl, press D

If you have local APRS traffic, by all means connect your radio to the sound card’s input (mic) jack and try to decode the packets. You can see any decoding by running the following command:

sudo axlisten -a -c

You should see something similar to the following:

AX.25 test packets from audio recording

AX.25 test packets from audio recording

If you do not have local APRS traffic which is frequent enough to use for real-world testing, you can download and play any audio file containing APRS (or packet) data. Here is a good resource that I used: WA8LMF Test CD

We will now install and configure dixprs. Start by creating the install directory, and then populate it with a configuration file.

sudo mkdir /usr/local/dixprs
sudo vi /usr/local/dixprs/config.txt

In the config.txt file, you will need to modify it to suit your particular details. Be sure to change the callsign, latitude and longitude at a bare minimum!

[GENERAL]
# Mandatory parameters
# Your callsign with SSID
CALLSIGN=NOCALL-5
# Degrees; West is negative, East is positive
LONGITUDE=-75.00
# Degrees; South is negative, North is posittive
LATITUDE=45.00
# Optional parameters
# Station height abvove the see level in meters; no default
#ASL=
# Owner name and contact; no default
#OWNER=
# Spool directory to import packets; no default
#SPOOL= # Station symbol; default is S#
#SYMBOL=
# UDP port base number; default is 31110
#UDPBASE=
# Beacon frequency in minutes; default is 30
BCNTIME=30
# Beacon text; %v replaced with actual version string; default is %v
# Used as default for ISGW and RADIO
BCNTXT=Raspberry Pi Soundmodem APRS gateway
# Select km/mi on monitor and in DX list; default is y (km)
#METRIC=<y/n>
# Max number of digis passed for local stations
# Used as message gating condition for gating to Rf
# Default value is 2
#LOCALHOPS=
# Range in km within messages gated to Rf
# If defined, checked after hop count (local) check
# No default
#MSGRANGE=
#################################################################
#
# IS gateway settings; remove this section to disable GW #
#
#################################################################
[ISGW]
# Mandatory parameters
# Domain name of IS server to connect
host=noam.aprs2.net
# Optional parameters
# Port number; default is 14580
#PORT=14501
# Filter; default is r/@/150
# @ is replaced with station position
FILTER=r/@/30
#################################################################
#
# WRB server settings; remove this section to disable it #
#
#################################################################
[WEBSERVER]
# Mandatory parameters
# WEB server port, no default
port=9999
################################################################# #
#
# Radio port configuration settings; repeat section for #
# multiple ports #
#
#################################################################
[RADIO]
# Mandatory parameters
# Interface type
INTERFACE=AX25
# Device; as listed by ifconfig; it is nbot the ax.25 port name!
DEVICE=sm0
# Optional parameters
# Modem speed, default is 1200
#SIGNALRATE=1200
# Enable/disable NWS WX bulletin and object gating from IS to Rf
# Disabled by default
#GATENWS=<y/n>
# Enable/disable BOM WX bulletin and object gating from IS to Rf
# Disabled by default
#GATEBOM=<y/n>
# Descripton of port; no default
#DESCRIPTION=
# Via used to send locally generated packets; default is WIDE1-1,WIDE2-2
#AXVIA=
# Digipeaters processed with WIDEn-n algorithm; default is WIDE1,WIDE2
#WIDEN=
# Blacklisted stations; they are not digipeated, not gated; default is NOCALL,N0CALL
# PHG string, do not mix with range; no default
#PHG=
# Range value in miles, do not mix with PHG; no default
#RNG=
# Enable/disable transmission; change it to PTTON=1 to enable trasmission; default is no
#PTTON=<y/n>
# Gate locally generated frames to IS gateway; default is no
# Useful for rx-only radio ports
# Experimental, use carefully
#GATELOCAL=<y/n>
# Gate digipeated frames to IS gateway; default is no
# Experimental, use carefully
#GATEDIGI=<y/n>
# Beacon text; %v replaced with actual version string; default is %v
#BCNTXT=
# Enable/disable digipeater; default is enabled
#DIGIPEATER=<y/n>
# Modem/TNC setup parameters 0…255; no defaults
# Use to setup modem/TNC by DIXPRS
#TXD=
#PPERSIST=
#SLOTTIME=
#TXTAIL=
#DUPLEX=
# Below these are the traffic shaping settings for gating messages
# From IS to Rf
#
# For advanced users only; do not change if you do not know how
# traffic shaping works and if you do not have good reason !!!
# Traffic shaping high treshold, default is 0.75
#TRAFFICHIGH=
# Traffic shaping low treshold, default is 0.5
#TRAFFIClow=
# Traffic shaping transmission delay, default is 5.0 sec
#TRAFFICDELAY=
# Comma separated list of addresses to send receveid/transmitted frames
# in hostip:port format. No default.
#UDPCC=

The following steps are a one-shot quick and dirty installation of the dixprs software package:

cd ~
mkdir pyax25
cd pyax25
wget https://sites.google.com/site/dixprs/downloads/pyax25.tar.gz
tar -xzvf pyax25.tar.gz
./compile_ax25.py build
sudo ./compile_ax25.py install
sudo rm -rf pyax25
cd /usr/local/dixprs
sudo wget https://sites.google.com/site/dixprs/downloads/dixprs-2.2.2.tar.gz
sudo gzip -d dixprs-2.2.2.tar.gz
sudo tar -xvf dixprs-2.2.2.tar
sudo rm -f dixprs-2.2.2.tar
sudo chown -R pi:pi /usr/local/dixprs
sudo chmod 755 *.py
sudo chmod 644 *.txt
cd ~

With dixprs installed, test the package as follows:

/usr/local/dixprs/dixprs.py -c /usr/local/dixprs/config.txt

Now be aware, if you are still streaming your test audio to the Pi, the decoded packets may be sent out to the APRS tier2 servers if your connection is working! This may be a bit annoying for those who rely on actual RF-gateway tracking (ie. you are mis-reporting positions for anyone whose callsigns are decoded).

Well, this is a ton of information as it is, so I will leave it here for now. My immediate plans are to add GPS receiver functionality and to dabble with aprx again (software that I have used successfully in the past).

This entry was posted in Operating, Project and tagged , , , , , . Bookmark the permalink.

12 Responses to Raspberry Pi & Soundmodem – It works!!

  1. Alan Crosswell says:

    Hey there – a decade later I thought I’d chime in on my success getting soundmodem to work, especially PTT via a sound chip GPIO pin. I used a DINAH usb sound card but had to patch soundmodem to recognize the particular CM108/CM119 chip’s product ID. I’ve submitted a bug report to debian-hams….

    I also dealt with some of the issues related to potentially random order of USB device loading and so on.

    See https://github.com/n2ygk/aprspi for full details.

    73 de Alan N2YGK

  2. I have Respberry Pi 2. I go installed the RASPBIAN Operating system to it. I don’t have a knowledge to setup software EchoLink to it. Please help me

  3. Notice if I run a newer kernel like 4.1.19 -v7+ from wheeze 5/7/2015 zip pi2 the sound modem when started “sudo screen -dmS sm soundmodem” is sending packet info all the time until you issue “killall soundmodem”. Also interferes with ssh and winscp logins.
    Can some shed some light on this? This is also a problem using Debian-Jessie-lite and a pi3.

    • James says:

      This is a very interesting revelation – I will have to look into this myself and I will let you know what I find.

  4. Daniele says:

    Hi
    I have some problems with soundmodem, when run :

    sudo screen -dmS sm soundmodem

    nothing appear
    infact when I launch :

    sudo /sbin/route add -net 44.0.0.0 netmask 255.0.0.0 dev sm0
    SIOCADDRT: No such device
    pi@raspberrypi ~ $ sudo axlisten -a -c
    listen: no AX.25 port data configured

    sould you help me please ?
    73 de IW9GRL

    • James says:

      When you run the “screen” command, it runs your binary (application) and keeps it running in the background. To restore your screen session, you run: sudo screen -r
      To exit the screen without closing the running program, you press Ctl-A then Ctl-D
      I suspect you have a problem with your /etc/ax25/axports file – if you edit that file with “sudo vi /etc/ax25/axports”, check to make sure there are NO “blank lines”
      Then run sudo sm soundmodem to see what you get – if there are no errors, run the command again using screen

  5. I am kicking myself so hard right now for not getting a raspi during the pi sale.

  6. Ugo Poddine says:

    Hi everybody,

    Python based or other tool serial port redirection it’s a complex matter : the normal redirection tools (e.g. SOCAT) are not able to redirect the RS232 control signals (e.g. RTS/CTS used by Soundmodem as PTT signal). A few kernal level tools are available, requiring kernal level cross-compiling….
    Buty there is also a different simpler solution, based on the powerful RaspberryPI BCM2835 structure. The steps are the following :

    a) detach the serial console output from the UART pins of the GPIO board, as described in several RasperryPI documentation (google can find : search “UART”) : basically editing the /boot/cmdline.txt startup file…
    b) modify, using a text editor (not the soundmodemconfig utility !), the soundmodem.conf file, setting /dev/ttyAMAO as PTT interface; soundmodem will see the RaspberryPI UART as serial hardware (not emulated !) interface, including the control signals
    c) the CTS0 signal can be actually (RaspberryPI B+) associated to the GPIO pin 17 (BCM mode)when the pin mapping it’s set in ALT3 MODE. The “ALT mode” (alternative pin mapping matrix in the RaspberryPI) switch can be easily made by different utilities (for example small “to be compiled” functions like gpio_alt.c, or alternative Python libraries like “pigpio library” or other; at the moment it’s not managed by standard Python RPi.GPIO libraries ). It’s then required to create a small script (Python or bash) able to switch off SAMBA, sets the GPIO17 in ALT3 mode and finally executes soundmodem : doing this the GPIO17 can easily drive one of the classic PTT interfaces “GPIO pin based” without need of heavy, slow and expensive RS232-to-USB HW interfaces.
    Enjoy
    Ugo Poddine

  7. Richard says:

    sudo /sbin/route add -net 44.0.0.0 netmask 255.0.0.0 dev sm0

    I know dev sm0 is the soundmodem but what is 44.0.0.0 is that your network? how do I rout it to my network?

  8. Steve G6SQX says:

    Dixprs & Raspberrypi
    I have worked out how to drive GPOI 31 from soundmodem
    to give a 0v Ptt command to Tx a radio.
    I removed the serial port on the raspberry pi and changed the
    function of GPIO31 to ALT3 (UART0_RTS) with rpi tyools/gpio
    and made the ptt file in soundmodem.conf = /dev/ttyAMAO
    as per the article by Holger DL8SCU It should work with Flidgi etc.
    http://dl8scu.wordpress.com/2013/02/10/are-you-lucky-no-usb-to-serial-converter-needed/

    73de Steve G6SQX

    • Noel Petit -- WB0VGI says:

      Do you have more details on using the GPIO to key PTT with APRX on a Raspberry Pi? I have a C-Media Headphone audio/USB converter for the audio in/out. Would like to use GPIO to trigger PTT instead of kludging up a VOX system. Have the B model RPi and it is running APRX receive only iGate but we need a digipeater here so would like to get the thing to transmit.

      Thanks,
      Noel

      • James says:

        There are a number of solutions for your PTT using the GPIO on the Pi.
        In any case, as a minimum you will have to use a transistor to protect the Pi as it uses 3v3 logic levels (not 5v!). My personal preference in this area would be to use the on-board serial GPIO (pins 8 & 10, TX & RX respectively) interfacing with something such as an Atmel ATiny85 and an optocoupler for PTT control. You could in principle run a python script to act as a serial port receiver and toggle one of the GPIO pins high / low as required for your PTT however, this is perhaps not as simple as actually using the serial method as described. Let me know which method you would like to learn more about ..

Leave a Reply

Your email address will not be published. Required fields are marked *