Tuesday, December 29, 2020

HAMVOIP - email on a Raspberry Pi pin status change

 I wanted to have the clubhouse send me an email if the alarm system went off.  The plan is to have a contact closure bring GPIO 0 (Pin 11) logic low on alarm.

The GPIO example didn't include a way to then detect when the pin went high again, so I had to come up with a slight modification.

The first step is to set up email:

https://www.hamvoip.org/howto/Allstar_email_howto.pdf

Then I wrote some clever scripts to perform an endless round-robbin task of monitoring the GPIO pin in question.

The script /home/email_alarm.sh is started from /etc/rc.local


----------------
home/email_alarm.sh
----------------

#!/bin/bash
# Required button hold down seconds
# set mode to in and pullup pin 0 (Physical pin 11, GPIO17)
PIN="0"
gpio mode $PIN in
gpio mode $PIN up
bash home/alarm_wait_active.sh &
exit

-------------
home/alarm_wait_active.sh
-------------

#!/bin/bash
# Required button hold down seconds
HOLDTIME=5
#define pin to watch
PIN="0"
TIME1=1
while [ 1=1 ]
 # wait in interrupt for pin to go low
 gpio wfi $PIN falling
 do
 # Got the low now poll to see if it stays low for holdtime
 while [ `gpio read $PIN` -eq "0" ];
 do
 sleep 1
 let TIME1+=1
 if [ $TIME1 -gt $HOLDTIME ]; then
 # if greater than holdtime then exit past done
 break 3;
 fi
 done
 TIME1=1
 continue
done
# code to execute when holdtime is exceeded goes here
#echo -e "Subject: Pi alarm active" | sendmail -v email@gmail.com
echo "alarm active"
bash /home/alarm_wait_clear.sh &
exit


---------------
/home/alarm_wait_clear.sh
---------------

#!/bin/bash
# Required button hold down seconds
HOLDTIME=5
#define pin to watch
PIN="0"
TIME1=1
while [ 1=1 ]
 # wait in interrupt for pin to go high
 gpio wfi $PIN rising
 do
 # Got the low now poll to see if it stays high for holdtime
 while [ `gpio read $PIN` -eq "1" ];
 do
 sleep 1
 let TIME1+=1
 if [ $TIME1 -gt $HOLDTIME ]; then
 # if greater than holdtime then exit past done
 break 3;
 fi
 done
 TIME1=1
 continue
done
# code to execute when holdtime is exceeded goes here
#echo -s "Pi alarm cleared" | sendmail -v email@gmail.com
echo "alarm cleared"
bash ./alarm_wait_active.sh
exit

Sunday, May 3, 2020

Spot Island-style Copper Clad board prototyping

I can't claim to have invented this style of prototype board layout, I'm sure I've seen this somewhere before.  "Dead bug" style prototyping where there is no printed circuit board layout is available is also popular.  The components are glued to a copper clad board in "dead bug" style while the leads are thrust in the air above the board like legs of a dead insect.  This is a messy way to try to attach components.

I prefer this spot island style method, which is similar to Manhattan-style.  Copper clad board is great for prototyping with either through-hole components or even surface mount.  This method isn't appropriate for DIP packages, but for discrete components it works just fine.  A perf board for DIP packages can be used above the level of this method to transition the circuit into IC chips as needed.

We've all got broken drill bits laying around (unless you've thrown them away).  The broken drill bit is still a valuable commodity.  I turned a couple into hole saws for making spot islands on copper clad boards.  First put the bit in your drill or drill press and use a grinding wheel to flatten it back out past the broken point.  Then put it in the vice and cut the center out with a Dremel tool grinding disc leaving only the edges.  This creates two fly cutter blades to act as a hole saw.  Cutting through the thin layer of copper into the circuit board is all that is needed.

Don't try to hold the board in your hand.  The drill press WILL drag it out of your hand the slice up your precious work.  First drill mounting holes in the board and use some screws to hold it to a block of wood.  The wood can be fastened safely into the vice of the drill press allowing for precision machining.  Lower the bit into the board until the copper is machined away leaving an island of copper and a recessed circle of board substrate.  Don't go the whole way through the board.

Once the board is laid out with islands it can be populated using good radio frequency layout practices.  Component leads can be cut short.  In the example below the board is cut with a strip at the top to feed Vcc power to components, where the rest of the board is left for a ground plane.

Here we see the DIP package of an Op Amp floating above the copper clad.  This is done by making "stilts" of components leads.  Once the DIP part of the component is finished, it can be incorporated into the copper-clad board.

When working at VHF frequencies this construction method works very well to keep leads short.  Islands can be drilled and later bridged with short jumps of clipped leads.  I have created two islanding bits.  The larger one can accommodate a hole drilled in the center if needed, while the small bit is good for just a few component leads that must be joined together.


Don't be stifled by a lack of printed circuit boards while experimenting with electronics.  There are many useful circuits that can be manufactured in this way.  If additional RF shielding is required, card stock can be sprayed with contact cement to facilitate the adhesion of ordinary kitchen aluminum foil.  In the photo I sacrificed an old Dilbert comic strip printed on cardstock with Omega advertisements on the opposite side.


The card stock is easily folded up to provide the RF shielding that may be required.  In this project photo below, the entire circuit board is RF shielded leaving only the inductor adjustment slug exposed for alignment tuning.


Saturday, April 11, 2020

Chimney Antenna Mount


We had some serious wind gusts with a cold front that moved in.  Usually the winds come in March, but this year they came mid-April. Well, I added one more antenna to the stack.  One more straw that broke the camel's back.  This chimney strap-mount was ok when it was just a 6 meter antenna, but it just couldn't take the wind and all the loading on the mast.

This is how I found it Friday morning.  I had to use a piece of paracord to hold the rotator motor upright and lashed to the edge of the chimney to give myself a warm fuzzy overnight so it wouldn't blow down and wreck all the antennas.

Here we are Saturday morning with the equipment as found.





It took about 3 hours mostly on my own to put everything back together.  The new mount is very stout made out of hardened steel bed frame angle iron.  I stood on it after it was torqued down.  That shouldn't go anywhere.  The antennas were re-arranged in the proper order to minimize the torque moment on the mast.  The 432 is now at the top (center mounted), the 6 is in the middle because it is small.  And the 2/3 rds of the 17B2 Cushcraft is at the bottom because it is so huge and heavy.  I had to put the outriggers on it to support the weight and keep it from sagging.

I can replace the feedline on the 6m antenna later after the roofers have replaced the shingles.  For now we're done.


Happy DX and we're back on the air!

Sunday, March 15, 2020

Radio Frequency Noise Cancelling

By this time we are all familiar with the technology of noise cancellation.  The concept is that the noise is sampled along with the desired signal.  The noise is then turned 180 degrees and mixed with the received data to cancel out the noise, leaving only the intended received signal.

There are several products on the market that do this.  Here is just one device in particular that I have built from a kit.  This is not meant as an advertisement, but only a testimonial to the technology.  The QRM-180 kit by AG6YJ is a compact and clever kit.  The packaging is superb, documentation is good, and assembly is easy.


The noise cancelling device accepts two inputs.  The TX/RX antenna and a Noise Antenna input.  There is also a transceiver connection that goes to your radio.  In Transmit mode the signal from the transceiver goes straight out to the TX/RX antenna and can handle the power of a 100watt radio on HF.  Naturally a PTT is required to switch the device from receive to transmit mode.  This re-routes the RF from the radio straight out to the main antenna terminal.  A well designed device will also have RF detection to switch to transmit if a small amount of RF is detected on the radio output.  This prevents blowing out the circuitry of the device.  The QRM-180 uses tiny 6 volt incandescent lamps as fuses.  If something goes wrong, the fuse blows before the circuitry is damaged.
The receive function is what we are really interested in.  Noise cancellation will work only on local noise that you can receive with a sense antenna.  It won't be able to remove atmospheric noise, and it won't improve poor transmission quality.  If you can't eliminate a noise in your area by going around the home turning off things looking for the source, or if you have an essential device in the house that cannot be turned off, or the noise is somewhere in the neighborhood that you have no control over, then noise cancellation may work for you.  Removing noise allows weaker signals that are below the noise level to be heard by the receiver.  It may not be as effective as moving out into the country into your own private "radio-quiet zone" to escape the RF pollution in your neighborhood, but it will help.
The noise antenna can be anything that picks up the noise.  It can be resonant on the noise frequency, a length of wire, or a small telescopic mag mount.  It should not be resonant on the band that you are trying to receive on.  I small telescopic mag mount works for me on most bands.  A longwire strung outside works for some of the lower bands like 160m.  You have to find out what works for your troublesome noise.
The noise will be brought in and amplified and available for phase adjustment.  It will then be flipped in a 180° phase inverter.  The noise now becomes "anti-noise" which is the exact opposite amplitude of the noise with the same waveform.  The Main antenna will receive both the intended signal and some of the noise.  The signal is amplified and available for phase adjustment.  Tune off any strong transmissions and just listen to the background noise for a moment.  If you have an SDR you will be able to see the waterfall and the noise floor.  When the gain is turned down on both the QRM-180 and the RF gain of the radio, the phase adjustments (marked as ΓΈ in the diagram) can be made so that a null is seen on the S-meter of the radio.  In some cases the null may be very sharp and pronounced.  On an SDR you will see the noise floor across the band drop.  As the phase adjustment knobs are turned a null may even be visible moving up and down the band as the knobs are turned.  When both phase knobs are in the right position the noise floor will indicate the lowest S-meter reading.  This is an iterative process, and will also mean adjustment of the gain knob.  When the "anti-noise" amplitude matches the noise amplitude contained in the received signal the re-combination of those two signals (marked as x in the diagram) will pass the intended signal to the radio.  The removal of the unwanted noise signal is done by destructive interference.  There is a gain adjustment for the noise sense amplifier in the back of the unit, but unless the noise is unusually strong, the manual says to leave this gain up the whole way.
Now tune the radio receiver VFO to the desired signal.  Again adjust the gain knob to get the best signal with a maximum amount signal and minimal noise.  Turning the gain up too high will just make it worse again.  This seems complicated at first, but after using the QRM-180 for a few days the process becomes natural.

Reduce the gain --> find the null with the phase adjustment knobs --> adjust the gain for best signal to noise ratio.

Let's look at some real results on the QRM-180.  There is something in my surrounding neighborhood that creates a fairly high noise floor.  There are a lot of houses around and who knows what noise-producing products people have nowadays!  Adjustments within the band should only be minimal if at all once the noise is nulled out in one section of the band.  Here we see the different when I turn on the QRM-180, adjust the gain down and find the null.  With the gain down the whole way both signal and noise are attenuated which doesn't help.

I see the most benefit on 17, 20, and 40 meter bands using the telescopic mag-mount antenna as a noise sense.  Here we see the signal on the Flex waterfall with the QRM-180 turned off.  The input signal from the Main Antenna goes straight to the receiver, noise signal and all.  The S-meter reading is fairly high at S5 and we see only a few signals peaking up above the ugly noise floor.

Some gain is needed to find the null.  Once the null is found the amount of gain is a judgment call for the operator.  Using the QRM-180 I have been able to hear stations that were previously buried in the noise floor.  That's the beauty of it.  As the adage is told from the days of old, "You can't work them if you can't hear them."


This device works so well, I'm not sure why modern transceivers don't come equipped with this technology built in!  Digital Signal Processing and Software Defined Filters can only do so much to enhanced the readability of a signal or reject QRM from adjacent stations.  Notch Filters are great if the QRM is very narrow.  For total broadband noise the QRM-180 has allowed me to hear stations that I would have never heard without it.
.