WS4E – Ham Radio And Other Stuff




The Arduino Fox Hunt Transmitter will be documented in another post, in this post I want to document the Raspberry Pi SSTV Field Day Beacon.
The one thing that I don’t like about the Raspberry Pi is that it only has digital input/output logic lines.  It has no built in analog capabilities to read voltages, etc.. so you can’t use it to easily interface with reading a potentiometer, a temperate probe, a light level meter, a sound meter or any of the other gazillion things that are analog and usually just a matter of reading the analog voltage or resistance or something similar.  With the Raspberry Pi, you just have I/O lines that can either send or read HIGH(3.3V), or LOW(0V) and that is all. If you want to do anything else you will have to build your own connections to an outboard ADC chip or something else via SPI or I2C bus connections.    So, keeping this in mind I tried to stay within the digital in/out capabilities of the Raspberry Pi in order to keep things simple as possible.
In order to create a SSTV Beacon we need the following things:
1) A webcam to take the pictures with.  I have a USB Webcam that has built in support on the Raspberry Pi so that was easy.
2) A radio to be a transmitter.  I used my old ICOM IC-2100H 2m Mobile that I keep as a ‘spare’.  This is very rugged radio and used to be in my car, but now I keep it as an extra.
3) An interface with the radio.  The Raspberry will need to be able to control the PTT line of the radio, and to be able to send audio into the radio to transmit.
WS4E - Ham Radio And Other Stuff
4) Software requirements:
  • Do this every 15 minutes
  • Take a snapshot of the field day site with the Webcam, overlay some text and a timestamp on the image
  • Encode the snapshot image into an SSTV AFSKsignal
  • Turn the PTT line ON
  • First play some voice audio files that do announcements of the beacon, what it is doing, and maybe the same time announce where our field day site is located, the website to find more info etc..
  • Play(transmit) the SSTV AFSK image sound to send the image over the air
  • End the transmission with a quick audio CW ident
  • Turn the PTT Off.
5) After getting most of this working. I decided to think about how to add one more feature.  Since it will be doing these broadcasts every 15 minutes over our club repeater, it would be nice if the beacon had enough smarts to a) not transmit over top of anyone already talking, b) make sure the ‘coast is clear’ before it began its transmission sequence.
At first I attempted to do this by “listening” to the audio out of the radio, building an ADC circuit using a MCP3008 10bit ADC, etc.. but after I got it all built, I found it to be very unreliable because the ADC is really made to measure 0-3V signals, and the signal coming from the audio out of the radio is in the mV range.   I could have used an OpAmp or something to bring the audio signal into a more measurable range but the breadboard was already getting full of wires just to support connecting to the MCP3008 over a SPI bus style circuit.  So, at first I decided to just scrap the idea.  But them I started thinking about how repeaters work and how they just use COR/COS lines which go high/or low do signal squelch, or pl tone detection.  I then started looking for a signal on the IC-2100H board that would provide me a simple squelch detection hi/lo signal.    Eventually I found one, in the connector that goes to the front LCD panel that probably turns on the “Busy” display on the LCD screen.  It was normally 5V High when the squelch was closed, and the radio was silent, and went to 0V when the squelch was open and the radio was receiving.  This was perfect, since the Raspberry Pi’s GPIO digital IO lines can handle up to about 5V input with no problems.  It would be a simple connection of this right up to a digital GPIO pin and just read the line for high or low.  This is the difference between 10 different connections going to a 16pin DIP chip to a single wire going to a single GPIO pin on the Pi board.  Much more simple.
6) I also decided I wanted to be able to have an accurate timestamp on the images.  But the Raspberry Pi has no accurate clock built-in and it resets its clock to 1969 on bootup everytime.  It is totally dependent on having normally getting a time source over the network via NTP to set its clock with during the operating system startup. But on Field Day it will be running at an isolated location with no network/internet connectivity. So it would not be able to have an accurate time as is.  I found a easy to add RTC clock chip that is available on a little board that plugs right into the first 6 pins on the Raspberry Pi header.   The RTC is called “RasClock”, made by AfterThought Software and available from several vendors on the net which sell Raspberry Pi accessories.  I got the RTC board, connected it to the Pi, and got it running in just a few minutes.  Now the Pi has a perfectly accurate on-board clock and will bootup with the correct time already set.  Now putting timestamps on the webcam snapshots will be easy and accurate.

I also purchased one of the little micro SD card holders made by the same people, and found it solved the problem I had of every so often accidentally bumping the regular SD card that always stuck out a little bit from the board.  This would often cause the Raspberry Pi to reboot or start having io errors which forced me to reboot to get it to work again.  I did not like the way that the SD card slow was designed on the Raspberry Pi to begin with myself, but their little micro card hides the SD totally under the board and makes it impossible to bump and solves that design issue.

Ok, now to document the actual build of this SSTV Beacon.

Here is a couple of images of the basic physical connections made between the Raspberry Pi, and the IC-2100 radio.

One image shows the IC-2100H radio sitting next to it on the bench, and one is just the Raspberry Pi and its breadboard.  In the pictures you can see the cable to the front panel RJ45 Mic Connector which is the main connection made.  And you can see the little red wire I have that is connected to the squelch detection signal inside the radio and comes out of the case with the 12V power cable through a hole in the back of the radio.

Here is the circuit diagram of all the connections I ended up making.

Without the MCP3008 ADC stuff it turned out actually very simple to do. You can see in the pictures above  how much room that left in the middle of the breadboard after I took it out.

There is nothing complicated in the circuit above:
  • I used a NPN transistor to take the 3.3V HIGH signal of the Raspberry Pi GPIO digital output pin and use it to switch the MIC PTT to ground and activate the push to talk line.
  • There is a simple voltage divider on the 1/8 audio out from the Raspberry Pi’s built-in soundcard to attenuate the audio before it goes into the MIC input line and keep from overloading and distorting the mic input.
  • And there is just a 1k resistor inline with the 5V/0V squelch detection signal from the radio in order to protect the Raspberry Pi GPIO input pin from getting any excessive current.  Normally you would want to use a 5v-to-3v logic level converter, or maybe at least a voltage divider when connecting a 5v device to the GPIO pins, but I measured only a few mA of current on this signal from the radio, and everyone says that the Pi seems to work fine with 5v incoming on its 3v logic inputs without much problem anyway.

After the physical circuit design comes the software work.

The Raspberry Pi is pretty much a full blown Linux computer. This makes almost anything possible as far as software.  You can write in pretty much any of the regular Linux programming languages you want such as Python, C, Java, Perl, etc.   I had originally planned to write something in Python or Perl, but it turned out that the stuff I was using all had simple standard utility commands to control them all, and I could just write a simple shell script that could be called by a cron job to do the periodic beacon.
I am using the standard Raspbian Linux distribution, with the following popular additional utilities installed:

  • For webcam snapshots: fswebcam – this is the utility that takes the snapshot from the webcam device and creates a jpg
  • To encode the image into SSTV: I originally thought about doing digital SSTV but I ran into some problems. Its very much a new thing and the software out there not very reliable, and it also is very wide bandwidth and requires nearly crystal clear signals to work.  And I found that the hardware driver for the Raspberry Pi on board broadcom soundcard introduces a bit of noise into the audio and this would causing problems with the digital signal.  I decided to stick to old fashioned analog SSTV which are very robust in their transmissions.  I chose the ROBOT36 image encoding because it only takes 36-seconds(hence the name) to transmit the image which is important since this will be taking over our club repeater every 15 minutes, and its the most popular encoding format used for automated systems such as the SSTV pictures from satellites, space probes etc.  They even use ROBOT36 for the SSTV on the ISS, and it was used on the MIR space station.  It’s not the best image quality SSTV encoding type, because its so fast, but its a good trade off between quality and speed which I put more importance on speed of transmission.  For the source code, I found a decent robot36 encoding C program someone had written here: https://gist.github.com/anonymous/5723053/, that I downloaded and compiled on the Pi.  This simply takes the image file, and turns it into a wav audio file with the SSTV signal that you can then playback and transmit.
  • Controlling the Raspberry Pi GPIO digital input/output: There are libraries for nearly every popular programming language from C, Java, Perl, Python, Ruby, etc.. but I chose to just use a simple set of utilities that allow you to control the GPIO lines from the command line and in shell scripts which was perfect for the sort of cron job I wanted to write for this application.  They are available here: https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/
  • Audio Files:  The other thing I have is I generated several voice wav file recordings to play each time along with the image for announcements etc.  You can generate these with the built in text to speech feature built into MacOS, or you can use one of the websites on the internet that can do this for you.  I  also have a 1200hz tone, that will start the beacon transmission, and I used a website to generate a wav file of a CW ident that is the last thing that gets transmitted.
Putting all of those things together and using them as the building blocks, I wrote a shell script that I will use to be called every 15 minutes from a cron job.

Here is the source of the shell script that runs the job.  Its pretty self explanatory, and well commented. The last thing I added was the logic to “listen” to the radio for 10 seconds, and make sure it didn’t hear anything before it begins its transmissions.  And if it does hear something, then wait 30 seconds and try again.  Hopefully it will be a nice polite little automated beacon on our repeater and play nice with others.

Cron Job Shell Script Source Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
#!/bin/bash
#
# This is the cron job to do an SSTV beacon transmissions for W4CN Field Day 2013
#
# 06/2013 – Don Hoover WS4E
#
export SSTVDIR=/home/pi/SSTV
cd $SSTVDIR
# Set some variables
GPIO_PTT=6
GPIO_SQL=11
DEBUG=1
# Initalize the GPIO ports
/usr/local/bin/gpio mode $GPIO_PTT out
/usr/local/bin/gpio mode $GPIO_SQL in
####################################
### Do image capture from webcam ###
####################################
# capture image and save
/usr/bin/fswebcam –jpeg 95 –skip 2 -F 2 –deinterlace –banner-colour #10263A93 –shadow –title W4CN –subtitle ARTS Field Day –info Cherokee Park –crop 320×240 -d /dev/video0 –save ${SSTVDIR}/webcam.jpg
# Run program to encode webcam.jpg to webcam.wav audio file
${SSTVDIR}/robot36
####################################
### Listen to the SQL Signal ###
####################################
# Listen to the sql signal line from the radio so
# we don’t transmit over top of anyone and be good neighbors
# on the repeater
OK_CONTINUE=0
TRY_COUNTER=1
MAX_TRIES=4
while [ $OK_CONTINUE == 0 ];
do
# Listen for 10 seconds
echo Listening for 10 seconds Try=$TRY_COUNTER
for i in {1..10}
do
SIGNAL_DETECTED=0
# Get the Squelch port status
SQL_STATUS=`/usr/local/bin/gpio read $GPIO_SQL`
echo Squelch=$SQL_STATUS
if [ $SQL_STATUS == 0 ]; then
echo ..Signal Detected
SIGNAL_DETECTED=1
fi
sleep 1
if [ $SIGNAL_DETECTED == 1 ];then
echo ..Stop Listening Early
break # exit listen for loop
fi
done
if [ $SIGNAL_DETECTED == 1 ]; then
echo Signal Detected…sleeping for 30 seconds and then try again.
sleep 30
if [ $TRY_COUNTER -gt $MAX_TRIES ]; then
Reached Max Tries….aborting program
exit
fi
TRY_COUNTER=$[TRY_COUNTER + 1]
else
echo OK Nothing heard for 10 seconds…Continuing
OK_CONTINUE=1
break # ok continue no need to try again, exit while loop
fi
done
###############################
### OK Now Transmit Beacon ###
###############################
# Reset output audio volume levels
# TODO
# PTT ON
/usr/local/bin/gpio write $GPIO_PTT 1
#
# Transmit beacon voice messages before the sstv image
#
/usr/bin/aplay ${SSTVDIR}/1200tone.wav
sleep .25
/usr/bin/aplay ${SSTVDIR}/this_is_the_w4cn_field_day_beacon.wav
sleep .25
/usr/bin/aplay ${SSTVDIR}/arts_club_field_day_is_at_cherokee_park.wav
sleep .25
/usr/bin/aplay ${SSTVDIR}/at_gps_coordinates.wav
sleep .25
/usr/bin/aplay ${SSTVDIR}/this_beacon_transmits_every_15_minutes_during_field_day.wav
sleep .25
/usr/bin/aplay ${SSTVDIR}/the_next_transmission_will_be_a_webcam_image_sent_via_sstv.wav
sleep .25
/usr/bin/aplay ${SSTVDIR}/visit_w4cn_dot_org_for_more_information.wav
sleep 1
#
# Transmit SSTV Image
#
/usr/bin/aplay ${SSTVDIR}/webcam.wav
# End with CW ident
sleep 1
/usr/bin/aplay ${SSTVDIR}/ws4e_cw.wav
sleep 1
############################
### Complete and Cleanup ###
############################
# PTT OFF
/usr/local/bin/gpio write $GPIO_PTT 0
/usr/local/bin/gpio write $GPIO_PTT 0
# Cleanup
rm -f ${SSTVDIR}/webcam.jpg

WS4E - Ham Radio And Other Stuff Schematic

Wednesday, November 21, 2012

Well, I have officially joined the 43ft vertical club.  The ubiquitous 43ft these days seems to be turning into the vertical antenna equipment of the G5RV.

Having a couple of days off, I finally got a chance to do the full install of this antenna, just in time for winter.

First I had to run a new coax line of RG-213 out to the back corner of the yard from the shack.  I took the ‘shallow trench’ made with a spade approach which I have used in the past.  I also am starting to like RG-213 more than LMR-400.  The specs are nearly the same, but the RG-213 has a solid PE (looks like hard plastic) dielectric inside it, where the LMR-400 has foam.  I think the RG-213 will actually hold up better long term outdoors and buried.   I have concerns about LMR-400’s foam getting full of water seeping in the coax over long term.  But, that being said I do have 2 runs of LMR400 already in the ground that have been there for about 4 years now with no problems.   But if I ever have to replace them, I think will go with RG-213 next time for those as well.

After the coax was run, I decided I needed to upgrade my single point ground panel.  I had used a pretty nice all aluminum NEMA box I got from a surplus site when we first moved into this house(see it in this previous blog post), it was kinda small inside being only 8×8 inches and it was going to be very full by the time I put a 3rd coax line and polyphaser through it.    I had originally purchased some of the nice watertight cable feedthrough couplers from DX Engineering to use with my box, so I went to their website to look at ordering some more for this new cable run, but then I came across a new offering.  They now offer their own nice weatherproof box, along with some of those coax feed through couplers, an aluminum panel for inside, and even a little copper bar to use in mounting copper strap like I have to the grounding panel.  Pretty much everything you need to setup a single point ground box.  AND, it was 13×14 so quite a bit bigger than the one I originally used.  I decided to spend just a little more money and get the whole kit.  Really, at $49.95 this is a very good price.

For more detail: WS4E – Ham Radio And Other Stuff Schematic


© 2015 Powered By Engineering Projects Team, Raspberry Pi Projects

Scroll to top