##Step 1: UPDATE wiringPi. 

wiringPi is the arduino like library that allows you to flip digital lines on
the GPIO connector and read them. We use this library as it is easy to use for those who
have the experience with Arduino programming.

	cd /tmp
	wget https://project-downloads.drogon.net/wiringpi-latest.deb
	sudo dpkg -i wiringpi-latest.deb

##Step 2: INSTALL ncurses

From the command line terminal, run:

	sudo apt-get install ncurses-dev

##Step 3: INSTALLING FFTW3

We use the excellent FFTW3 library to do all our Fourier Transforms, this library is central
to our SDR work.

Innstall fftw3 from the tarball downloaded from www.fftw.org, follow
the instructions for the config, make.  run make install as sudo

	./configure
	make
	sudo make install

You have to run the same process once more for installation of the single
precision float library.

	./configure --enable-float
	make
	sudo make install

##Step 4: Some required standard libraries 

	sudo apt-get install libasound2-dev
	sudo apt-get install libgtk-3-dev
	sudo apt-get install libgtk+-3-dev

##Step 5: INSTALLING LOOPBACK

IMPORTANT: pulseaudio maybe taking over ALSA sound system that sbitx runs on 
edit /etc/pulse/client.conf and add the line

	autospawn = no

to disable it.

We need a way to pass audio between the sbitx and other programs running on the RPi like
WSJT-X, etc.

The snd-aloop will add three 'virtual sound cards' to the system
enable=1,1,1 enables all the three and these three cards are numbered 1,2,3.
This way there are a total of 4 cards: card 0 is the actual circuit audio circuit
and three virtual cards.

All cards under Linux are refered to like "hw:1,0", where, the first of the two
digits represents the card number, and the second digit is called a 'device'.
In the loopback what you play to "hw:1,0" will be avaiable to be recorded at "hw::1,1"

When we need to connect an external program, let's say wsjt-x to sbitx, the sbitx will play
the audio to the speaker (hw:0,0) as well as hw:1,0. The wsjtx-x will capture this using 
hw:1,1 as the audio capture device. Note that the hw:1,0 and hw:1,1 are working as a pair.
To pick up the modulating audio generated by wsjtx (or other external programs), the playback 
device of the external program should be set to hw:2,0 and the sbitx will capture back the 
transmitting audio from hw:2,1. Again, hw:2,0 and hw:2,1 are operating as second pair.

			SBITX Audio              WSJT-X Audio
			hw:0,0 -> Speaker
			hw:0,0 <- Mic
			
			hw:1,0 -> Line out ----> hw:1,1 Mic In / Capture
			hw:2,1 <- Line In ------ hw:2,0 Speaker

To temporarily enable the  loopback, you have to run this command from the command line:

	sudo modprobe snd-aloop enable=1,1,1 index=1,2,3

You can check that the three loopback devices are working by running the command :

	aplay -l

The sbitx will not work if the loopback is not present. You can automatically run snd-aloop
upon booting up by adding this line to /etc/rc.local 

  sudo modprobe snd-aloop enable=1,1,1 index=1,2,3 

##Step 6:

EDITING THE config.txt

The file /boot/config.txt can only be edited by the super user. You can edit it with either nano
or vi from the terminal. This file is used to configure the Raspberry Pi as it is booting up. 

add these lines to the very end of the  /boot/config.txt

	gpio=4,17,27,22,10,9,11,5,6,13,26,16,12,7,8,25,24=ip,pu
	gpio=24,23=op,pu

	#Disable under-voltage warning
	avoid_warnings=1
	dtoverlay=audioinjector-wm8731-audio

You also have to disable the built-in audio system, locoate the line that says
dtparam=audio=on and add a '#' character before it to disable it

	#dtparam=audio=on
	

##STEP 7: SUPPRESS THE LOW VOLTAGE WARNINGS

The Raspberry Pi has some issue when powered from the GPIO pins instead of the USB power port.
It keeps complaining about low power (although we supply it 5.5V). To keep the Low voltage
warnings from popping up all the time, from the commaind line run:

	sudo apt remove lxplug-ptbatt


##STEP 8: Install ntpstat
ntp and ntpstat are useful to know if the radio is synched to realtime.
this is important when the date/time in the logbook needs to be accruate.
it is also useful for ft8 synchronization

sudo apt install ntp
sudo apt install ntpstat

## step 9: the webserver of sbitx runs on port 8080 this has
to redirect to port 80. To do this...
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080

and then, install iptables-persistent (so it saves the current iptables)
sudo apt-get install iptables-persistent --fix-missing

## step 10: to make your sbitx appear as sbitx.local on the local network
copy the files hosts and hostname to etc under sudo

sudo cp hosts /etc/hosts
sudo cp hostname /etc/hostname

## step 11: create a fresh logbook database in the data subdirectory
you may have to install sqlite3 first

sudo apt update
sudo apt install sqlite3
sudo apt install libsqlite3-dev

cd data 
sqlite3 < create_db.sql

##step desktop short-cut
this doesnt work with touch as it needs double click
fro Accessories->File Manager,
from edit menu go to preferences and in the general tab turn on 
open files wiht single click
