Saturday, November 26, 2016

Creating a 2m Fm Repeater with a Raspberry Pi (B) and a RTL dongle.

Creating a 2m Fm Repeater with a Raspberry Pi (B) and a RTL dongle. (Don't use this application without the RF filter)

RTL dongles is available from Giga Technology and the filter will be available soon.



For the purpose of this configuration I expect your Raspberry pi to be connected to the internet.
How will this repeater work.
This configuration was done with the latest Raspbian Os for Raspberry Pi downloaded from here https://www.raspberrypi.org/downloads/
I used my original Raspberry Pi B+ and also repeated  this on a Banana Pi
 as I need a hard drive to compile gnuradio for later SDR use.

I will be using a rtl dongle to receive my input signal on 70cm frequency configurable on the amateur 2m or 70cm band. The receiver signal will then be demodulated and re transmitted with a DSP Library simulating a FM Signal using a GPIO pin on the Raspberry as an transmitter.

Get your Raspberry Pi on the latest patch/update.

sudo apt-get update
sudo apt-get upgrade
Go and get some Coffee as it might take long time to update ..zzz...... ;-) 

Install the SDR command line application to access rtl  USB dongle.
This rtl library allow you to demodulate the fm / ssb input

sudo apt-get install rtl-sdr-0.5.3-3 mplayer octave gnuplot gnuplot-x11


Download the Fm transmitter software from github using the following command

Install the rpitx python library using the following command. 

rpitx is the main software to transmit. It allows to transmit from:
  • IQ files *.iq (can be generated by external software like GNU Radio).
  • Frequency/Time files *.ft (generally used to easily implement digital modes)
Installation of rpitx

git clone https://github.com/F5OEO/rpitx git clone https://github.com/F5OEO/rpitx
cd rpitx # make sure to have access to the internet to download packages # or download and install them manually (libsndfile1-dev and imagemagick) 
./install.sh

Ok lets create some IQ files that will be used  to test the transmitter.

SSB Transmiiter
./pissb sampleaudio.wav ssbIQ.wav


A sample script testssb.sh is included.


FM modulation

pifm converts an audio file (Wav, 48KHz, 1 channel, pcm_s16le codec) to Narrow band FM (12.5khz excursion) and outputs it to a .ft file. Assuming your audio file is in your current working directory ./pifm sampleaudio.wav fm.ft

Connect a antenna to pin 4  long wire 40cm or longer depending on 1/4 lent of wavelength.
Pin Connection Diagram. Use coaxial cable to make connection
Here is a link with the filter details for the 2m Band


You could then transmit it on 100MHZ (please set a correct frequency to be legal) 
sudo ./rpitx -m RF -i fm.ft -f 100000 -l -c1


A sample script : testfm.sh is included.  add -c1 for pin 4 transmission in file

VFO
A VFO mode is provided to allows precise frequency resolution. For example to set a carrier on 100MHz (please set a correct frequency to be legal)sudo ./rpitx -m VFO -f 100000 -c1

Ok we got the Transmitter working Now lets get the rtl dongle working.
Follow my steps here http://zr6aic.blogspot.co.za/2013/02/setting-up-my-raspberry-pi-as-sdr-server.html

When you are complete with installation of rtl_sdr and have tested it wit rtl_test -t we can now check what audio devices the raspberry have.

sudo aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Now we need to install some audio utility programs to pyp and convert audio signals
sudo apt-get install sox libsox-fmt-all
ok lets test to see if we can receive 2m band transmission.

Tune the the rtl dongle for a frequency of 145.500Mhz and transmit a test signal.

sudo rtl_fm -f 145500000 -M fm 

Transmit a mp3 file recording
sox -t mp3 zr6aic_CQ_mono.mp3 -t wav -r 48000 -c 1 - | sudo ./pifm - 145.5 -c1

Installing ffmpeg


# build and install x264
git clone --depth 1 git://git.videolan.org/x264 cd x264 
./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl 
make -j 4
sudo make install

 # build and make ffmpeg
git clone --depth=1 git://source.ffmpeg.org/ffmpeg.git cd ffmpeg
./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
make -j4
sudo make install


Install the following utility classes to help with the audio manipulation
sudo apt-get install libav-tools sox oggfwd libsndfile1-dev
sudo apt-get install fftw3 libfftw3-dev

Install csdr
git clone https://github.com/simonyiszk/csdr.git 
cd csdr 
git fetch 
git checkout dev 
make && sudo make install

Testing transmitter with Audio file (pin4 = -c1)
(while true; do cat speech48000.raw; done) | csdr convert_i16_f | csdr gain_ff 700 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 145000 -c1

Putting the rpitx transmitter in TCP port listening mode (replace ip with Raspberry pi ip)
Sending audio from remote computer. (using mike from Linux computer)
arecord -fS16_LE -r48000 -c1 - | nc 192.168.10.128 8011

Testing RTL_fm (replace ip with your Raspberry ip)
sudo rtl_fm -M wbfm -f 98000000 | play -t raw -r 24k -es -b 16 -c 1 -V1 -
sudo rtl_fm -M wbfm -f 98000000 |nc  192.168.10.128 8011 -


Send rtl_dongle to transmitter (replace with your raspnerry ip)
sudo rtl_sdr -s 250000 -f 144300000 -p 0 - | nc -vv 192.168.10.128 8011
sudo rtl_sdr -s 4800 -f 144300000 -p 0 - | nc -vv 192.168.10.128 8011
 

Working RX with rtl dongle
sudo nc -l 8011 | csdr convert_i16_f | csdr gain_ff 8000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 145300 -c1

Working TX with pin 4

sudo rtl_fm -s48000 -g 49.6 -l 0 -M fm -f 434400000 |nc  192.168.10.128 8011 -

here is repeater without sqaulse


How to make the Repeater to auto start when the Raspberry start boot up.

Create a file and edit it
sudo vi /etc/init.d/Repeater

Add the following in the file and save it

#! /bin/sh

# /home/pi/sh/run_repeater.sh

### BEGIN INIT INFO

# Provides:          SDR repater start script
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO

# If you want a command to always run, put it here


# Carry out specific functions when asked to by the system

case "$1" in
  start)
    echo "Starting SDR_repeater"
    # run application you want to start
    /home/pi/sh/run_repeater.sh
    ;;
  stop)
    echo "Stopping SDR_Repeater"
    # kill application you want to stop
    killall rtl_fm
    killall rpitx
    ;;
  *)
    echo "Usage: /etc/init.d/Repeater {start|stop}"
    exit 1
    ;;

esac

Make the file executable

sudo chmod 755 /etc/init.d/Repeater


Create a file in the /home/pi/sh/run_repeater.sh

Vi /home/pi/sh/run_repeater.sh

Add the Repeater script define above in this file so that it can auto start on boot time.


sudo rtl_fm -p 38 -s48000 -g 0 -l 3 -M fm -f 434400000 |csdr convert_i16_f | csdr gain_ff 12000 | csdr convert_f_samplerf 20330 | sudo rpitx -i- -m RF -f 145293 -c1&


Test the start and stop script.


Start the Repeater

sudo /etc/init.d/Repeater start

Stop The Repeater

sudo /etc/init.d/Repeater stop

Here is a video of the Test of the repeater ( I have changed the wires with a coaxial cable)


Video testing Fm demod and re mod cross band


What else can I do

Creating APRS transmitter
Setting up APRX rpitx with Raspberry Pi

aprs --callsign <callsign> --output - "<message>" | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -m RF -i - -f 144800 -c1

Repeater configured in a single line 
sudo rtl_fm -p 38 -s48000 -g 0 -l 0 -M fm -f 434400000 |csdr convert_i16_f | csdr gain_ff 12000 | csdr convert_f_samplerf 20330 | sudo rpitx -i- -m RF -f 145293 -c1


Specifications (measured with New Low pass filter board )

Here is some results of Power measurements at 145Mhz. (@50ohm) 

  • Voltage  1.3V
  • Power 32.7 mW  (15.1dBm)

Total power consumption on power supply when repeater is running

Measured  5.44 V  and  540mA  = Total watts   2.937Watts

Gnu radio implementation of the repeater.


Here is a GnuRadio equivalent of the command line version.

1)  Run trpitx making it listen for TCP connections from GnuRadio on port 8011
while true; do (nc -l 8011; dd if=/dev/zero bs=4096 count=30); done | sudo rpitx -i- -m IQFLOAT -f 145259 -c1
2) Run Gnuradio-companion
gnuradio-companion

3) Then load this GRC file to send a audio wav file to Transmitter on port 8011
Gnuradio transmits audio file to rpitx

Here is the file for the audio wave file transmitter sending the the audio to the rpitx listening on port 8011
https://github.com/antonjan/PiGnuradio/blob/master/AMSAT_Demo_2m_Transmitter_sonderscope.grc




Here is a link to the AMSATSA presentation where the Gnuradio and SDR Command line utilities was demonstrated.  SDR Fundamentals

Here is the Picture of the PCB almost complete.
2m Raspberry Pi TX (7 stage low pass filter)
 More Details to follow soon.
3D model of board with two filters available soon
Click Diagram to enlarge.
2 Filters with 2 SMA connectors (7 stage and ceramic filter)
The 7 stage can be made up for any band but ceramic filter is 2m band only.
The PCB's has arrived. The assembly and testing will now start.

PCB's has arrived. 


RTL dongles is available from Giga Technology and the filter will be available soon.
Functional Block Diagram


Ref: 2m Low pass filter  https://www.minicircuits.com/pdfs/LFCN-80.pdf