Saturday, June 8, 2013

I wanted to do something different for ARRL Field Day this year.  So, I came up with two different ideas on what I could do that we would be interesting at our Field Day.   I have been playing a bit with both a Raspberry Pi and Arduino's lately so I started thinking what kind of things I could do with those devices.

  1. Periodically Send SSTV images from a webcam over our VHF repeater.  This would require building some sort of device to take the images, and send them over the repeater.  I decided I would use my Raspberry Pi, and old USB webcam, and my old IC-2100H 2m mobile radio to accomplish this.
  2. Let's have a Fox Hunt!  We have never had a fox hunt at field day, so I thought this would be a good year to have one.  I decided to build one out of a Yaesu VX-5R radio(because you can adjust the xmit power way way down via the service menu), and use an Arduino to create the fox beacon.

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.  
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.    Here is how to create those files using a Mac: http://etc.usf.edu/techease/4all/learning/how-do-i-use-the-speech-service-in-mac-os-x-to-record-text-into-an-audio-file/
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: