Antenna Switching project

Here is a brief description of an automatic antenna switching project that uses the pre-observation script. You will need the pre/post observation modifications implemented by Chibill for this to work (see the mods at https://gitlab.com/librespacefoundation/satnogs/satnogs-client/blob/0/satnogsclient/observer/observer.py particularly those around the pre and post observation parts with the variables being passed to the scripts). For this to work you need to install wiring-pi which you can do with sudo apt-get install wiringpi

Firstly, run sudo satnogs-setup, go into advanced and set parameter SATNOGS_PRE_OBSERVATION_SCRIPT to /home/pi/preob.sh -f {{FREQ}}

Set parameter SATNOGS_POST_OBSERVATION_SCRIPT to /home/pi/postob.sh

Create file /home/pi/preob.sh with the following contents:

#!/bin/bash
#set the ports up and to known state
gpio mode 21 out
gpio mode 22 out
gpio mode 23 out
gpio mode 24 out
gpio write 21 0
gpio write 22 0
gpio write 23 0
gpio write 24 0

date=`date +%F" "%T`
freq=0

while getopts f: option
do
case "${option}"
in
f) freq=${OPTARG};;
esac

if ([ $freq -ge 136000000 ] && [ $freq -lt 139000000 ]) ;
then
    echo "$date 136 to 138 selected" >> /home/pi/freqset.txt
    gpio write 23 0
fi

if ([ $freq -ge 144000000 ] && [ $freq -lt 146000000 ]) ;
then
    echo "$date 144 to 146 selected" >> /home/pi/freqset.txt
    gpio write 23 0
fi

if ([ $freq -ge 399900000 ] && [ $freq -lt 405000000 ]) ;
then
    echo "$date 399.9 to 405 selected" >> /home/pi/freqset.txt
    gpio write 23 1
fi

if ([ $freq -ge 430000000 ] && [ $freq -lt 440000000 ]) ;
then
    echo "$date 430 to 440 selected" >> /home/pi/freqset.txt
    gpio write 23 1
fi

if ([ $freq -ge 460000000 ] && [ $freq -lt 470000000 ]) ;
then
    echo "$date 460 to 470 selected" >> /home/pi/freqset.txt
    gpio write 23 1
fi
done

write the file, then chmod +x /home/pi/preob.sh and chown satnogs:satnogs /home/pi/preob.sh

Create file /home/pi/postob.sh with the following contents:

#!/bin/bash
gpio write 21 1
sleep .2
gpio write 21 0
sleep .2
gpio write 22 1
sleep .2
gpio write 22 0
sleep .2
gpio write 23 1
sleep .2
gpio write 23 0
sleep .2
gpio write 24 1
sleep .2
gpio write 24 0
sleep .2
echo "Antenna switch reset" >> /home/pi/freqset.txt

write the file, then chmod +x /home/pi/postob.sh and chown satnogs:satnogs /home/pi/postob.sh - the post observation script is designed to cycle the relays to make sure the contacts are kept ‘fresh’ and losses minimized.

touch /home/pi/freqset.txt and chown it to satnogs:satnogs - this is the log file for antenna switching.

The picture above shows the basics of the switcher. I’ve tried to use parts that you can go and buy from eBay. Search for 4 channel optocoupler to find the above board. For coax relays, use something appropriate to the bands you want to switch. I used MD951 relays because they were in the junk box, you could push the boat out and use a nice SMA 18GHz multipole relay. Once you have the hardware installed, test it by writing to the various GPIO pins. I soldered an LED + 1.2K resistor across each of the relay coils as an easy way to see the various status’s of each relay.

Modify the /home/pi/preob.sh script to suite your frequency bands, and adjust the GPIO outputs to toggle the appropriate relay. There is scope for additional control such as switching in a down converter, toggling voltage up the coax to power LNA’s etc. If you make the above script better, please publish it on this thread - thanks.

The above picture shows the implementation here. 3 coax relays can be seen in the background, these are interconnected with semi-rigid 50 ohm coax. The right had relay connects to the SDR and selects the outputs of the pair of input select relays. The bottom relay is currently used to switch between VHF and UHF. The top relay will be used to select L-Band and probably S-Band IF. It is possible to add another relay using the spare opto-isolated port on the board, this could be for switching between two VHF antennas where losses will be less than at L-Band etc.

Any questions, please ping me in the @satnogs IRC, my nick is pjm.

I hope this is useful and some of you build it to expand your stations capabilities.

Paul M0EYT - Station #91

10 Likes

Hopefully eventually the MR will be merged in to the current stuff. :slight_smile:

2 Likes

Hi chilbill. I have a few small micro antenna relays, 3 in each sealed unit, and a handfull of Arduinos that I need to use for something.

If I could get the Arduino to read the antenna id codes, especially from the I/O pin from the RPI3, then the Arduino could switch many antennas and combinations as needed.

Would you be willing to discuss this change in your project?

bob
w4ush

For reference the MR was

And is currently part of the main code.

Want to add relevant information for if people search this up.

Sorry for digging out a 2 year old thread.

I’m looking into a similar project: being able to select an antenna, or switch between filters/lna on a single antenna, from an observation pre-script.

My idea would have been be to use a RF switch IC, i got a bunch of HMC190 around, controlled by a littlle attiny microcontroller over USB.

Would it be better to use a coaxial relay ? Do they have less insertion loss ?

I don’t have experience in RF PCB design so for a start i’d be happy if it works well for VHF, to switch for example between a narrow 137MHz and a wider VHF filter.

GM everybody!
this is a follow-up of nice contribution of UHF-satcom.

In my realization I try to follow the “KISS approach”, both in the hardware and in the software, as well as trying to have as few electrical connections as possible to minimize RFI leakage. This setup has only a USB cable between RPI and the RF switch; it is also useful to use ferrite clamps on each cable… we are listening to objects that transmit very weak signals!

As some of you know, I made a small controller with an ARDUINO nano capable of switching some RF relays via a serial link. This is the link [https://sourceforge.net/projects/ardu-rf-switch/] to this board. Any customitation to fulfill different setup it’s quite simple.

The hard part it’s about the integration with the Satnogs… that’s turned out not so simple, mainly due to how the microcontroller circuit is implemented. In particular, the DTR signal of the serial transceiver is used to “reset” the board in order to load the software via bootloader.
This process can be summarized as follows:

  • Arduino IDE open the serial port
  • the first transition on serial port trigs DTR and after abt 1.5 sec the board it’s ready to receive the code
  • compiled sketch it’s sent via serial to the board
  • once verified Arduino IDE shuts down the serial port and the device it’s ready to repeat this process every time.

The problem is in the last point: the serial port is closed and so any attempt to write to that port via
echo "somecommand" > /dev/ttyUSB0
does nothing but reset the board at each attempt.

Looking for a solution and to check if the controller was working correctly, I tried to command it through cutecom, a Linux application for communications via serial ports.
Everything ok, it works, but much more, once cutecom is closed it is possible to send commands to the board via consolle with echo ... !!!

So the trick is “open the serial port, then exit but without close the serial device”.

The magic trick is performed at RPI4 boot through a script (actually the same script used by the Satnogs client), activated by creating a service, considering that the different solutions via rc.local are no longer usable.

I followed this nice link. Below a quick recap:

sudo nano /lib/systemd/system/ARDU-RF.service

then insert the following text into this file, modify as per your setup; note that ‘preob.sh’ is the script executed by satnogs client “before” each observation ( it’s described below)


[Unit]
Description=Fake access to ARDU-RF board to avoid Arduino DTR issue
After=multi-user.target
[Service]
ExecStart=/home/pi/tests/preob.sh
[Install]
WantedBy=multi-user.target

  • Save and exit with ctrl + x, followed by y when prompted to save, and then enter.
  • sudo systemctl daemon-reload
  • sudo systemctl enable ARDU-RF.service
  • sudo reboot

At each boot the serial port has a “fake” use and then it’s leaved ‘open’

This is the content of preob.sh and postob.sh, invoked by the client to switch the correct antenna ( but they can do more for us :wink: ).

  • preob.sh : called just before observation starts, set the right antenna and write to the satnogs log.

#!/bin/bash
\# original scripts by UHF-satcom aka pjm
#set the ports up to known state and disable close between calls
stty -F /dev/ttyUSB0 9600 -hupcl

date=\`date +"%d/%m/%y %H:%M:%S %Z"\`
freq=0

while getopts f: option
do
case "${option}"
in
f) freq=${OPTARG};;
esac

if (\[ $freq -ge 399900000 \] && \[ $freq -lt 470000000 \]) ;
then
    echo "$date --> 399.9 to 470 frequency, ANT0 selected" >> /home/pi/tests/satnogs_log.txt
    #sleep 5
    echo -e "ANT0\\n" > /dev/ttyUSB0
fi

if (\[ $freq -ge 136000000 \] && \[ $freq -lt 150100000 \]) ;
then
    echo "$date --> 136 to 150.1 frequency, ANT1 selected" >> /home/pi/tests/satnogs_log.txt
    #sleep 5
    echo -e "ANT1\\n" > /dev/ttyUSB0
fi

if (\[ $freq -ge 24000000 \] && \[ $freq -lt 30000000 \]) ;
then
    echo "$date --> 24 to 30 frequency, ANT2 selected" >> /home/pi/tests/satnogs_log.txt
    #sleep 5
    echo -e "ANT2\\n" > /dev/ttyUSB0
fi
done

  • postob.sh : called at observation end, puts RF relays in ‘deactivated’ position do not waste energy unnecessarily[!!!], and to setup a know position.

#!/bin/bash
# original scripts by UHF-satcom aka pjm
# disable all relays... no power waste! 
date=\`date +"%d/%m/%y %H:%M:%S %Z"\` 
echo -e "ANT0\\n" > /dev/ttyUSB0 
echo "$date antenna switch reset " >> /home/pi/tests/satnogs_log.txt

Please take note about the following mandatory permissions, because the scripts are executed as “satnogs” user:

  • sudo usermod -a -G dialout satnogs, to access serial device by satnogs user
  • sudo usermod -a -G pi satnogs, to permit execution tro satnogs as member of pi group
  • touch satnogs_log.txt, to create the log file
  • chmod 666 satnogs_log.txt, to permit everybody writing on this file
  • chmod +x preob.sh, set script to be executable
  • chmod +x postob.sh, set script to be executable

To test the whole stuff try to esecute:

./preob.sh -f 435000000
./postob.sh
tail ./satnogs_log.txt

and satnogs_log.txt should contain:

18/02/21 12:15:25 GMT --> 399.9 to 470 frequency, ANT0 selected
18/02/21 12:30:23 GMT antenna switch reset 

So, sorry if this post isn’t that concise, I tried to keep it short… but I hope that shall be useful!

73’s de I3VFJ, Vittorio ( @vittben on TWTTR)

2 Likes