Raspberry GPIO's Setup: Difference between revisions
mNo edit summary |
|||
(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= At this moment only PTT is working, | = At this moment only PTT is working, SQL is a work in progress = | ||
Lets consider we are going to use | Lets consider we are going to use | ||
GPIO 17 (Pin 11) for | GPIO 17 (Pin 11) for SQL input | ||
GPIO | GPIO 20 (Pin 13) for PTT Output | ||
= Install wiringpi = | = Install wiringpi = | ||
Line 24: | Line 24: | ||
#!/bin/bash | #!/bin/bash | ||
#script name - Init_GPIO | #script name - Init_GPIO | ||
# | # SQL Input | ||
gpio -g mode 17 in # makes gpio 17 pin 11 on Raspberry pi 2/3 as input | gpio -g mode 17 in # makes gpio 17 pin 11 on Raspberry pi 2/3 as input | ||
gpio -g mode 17 up # activates pull-up | gpio -g mode 17 up # activates pull-up | ||
# PTT pin (Output) | # PTT pin (Output) | ||
gpio -g mode | gpio -g mode 20 out # makes gpio 20 pin 13 as output | ||
gpio -g write | gpio -g write 20 0 # Default to 0/Off | ||
After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. | After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. | ||
= Create the | = Create the SQL monitoring script = | ||
Create the following file using nano: | Create the following file using nano: | ||
sudo nano /usr/local/sbin/ | sudo nano /usr/local/sbin/SQL-wfi.sh | ||
<pre> | |||
#!/bin/bash | |||
gpio -g mode 17 in | |||
gpio -g mode 17 up | |||
while [ 1=1 ] | |||
do | |||
# wait int pin to go low | |||
gpio -g wfi 17 both | |||
SQL=$(gpio -g read 17) | |||
if [ "$SQL" = "0" ]; then | |||
# gpio -g write 20 1 | |||
echo SQL GPIO low/closed | |||
else | |||
# gpio -g write 20 0 | |||
echo SQL GPIO high/open | |||
fi | |||
done | |||
</pre> | |||
After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. | After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. | ||
= Make the Init-GPIO and | = Make the Init-GPIO and SQL-wfi.sh scripts run at startup = | ||
you have to add a line to the rc.local file. | you have to add a line to the rc.local file. | ||
Line 90: | Line 68: | ||
Before the '''exit 0''' line you have to add: | Before the '''exit 0''' line you have to add: | ||
# For | # For PTTLink | ||
/usr/local/sbin/Init-GPIO.sh | /usr/local/sbin/Init-GPIO.sh | ||
/usr/local/sbin/ | /usr/local/sbin/SQL-wfi.sh | ||
After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. | After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. | ||
Line 98: | Line 76: | ||
= Set permissions to execute scripts = | = Set permissions to execute scripts = | ||
<pre> | |||
cd /usr/local/sbin | |||
sudo chmod +x Init-GPIO.sh | |||
sudo chmod +x SQL-wfi.sh | |||
</pre> | |||
= Test GPIO pins = | = Test GPIO pins = | ||
Line 109: | Line 87: | ||
High: | High: | ||
<pre> | |||
gpio -g write 20 1 | |||
</pre> | |||
Low: | Low: | ||
<pre> | |||
gpio -g write 20 0 | |||
</pre> | |||
= Edit rpt.conf file = | = Edit rpt.conf file = | ||
Line 126: | Line 108: | ||
Then at the end of the file add the following stanza: | Then at the end of the file add the following stanza: | ||
<pre> | |||
[events12345] | |||
gpio -g write 20 1 = S|T|RPT_TXKEYED; | |||
gpio -g write 20 0 = S|F|RPT_TXKEYED; | |||
</pre> | |||
After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. | After making your changes type '''<CTRL> + <X>''' and then type '''<Y>''' followed by '''<Enter>'''. You will be back to the previous menu and choose '''<Back>'''. |
Latest revision as of 22:15, 10 March 2022
At this moment only PTT is working, SQL is a work in progress
Lets consider we are going to use
GPIO 17 (Pin 11) for SQL input
GPIO 20 (Pin 13) for PTT Output
Install wiringpi
sudo apt-get install git-core sudo git clone https://github.com/WiringPi/WiringPi.git /opt/wiringpi cd /opt/wiringpi sudo ./build
Create an initialization file
Create the following file using nano:
sudo nano /usr/local/sbin/Init-GPIO.sh
Add the following code to the file
#!/bin/bash #script name - Init_GPIO # SQL Input gpio -g mode 17 in # makes gpio 17 pin 11 on Raspberry pi 2/3 as input gpio -g mode 17 up # activates pull-up # PTT pin (Output) gpio -g mode 20 out # makes gpio 20 pin 13 as output gpio -g write 20 0 # Default to 0/Off
After making your changes type <CTRL> + <X> and then type <Y> followed by <Enter>. You will be back to the previous menu and choose <Back>.
Create the SQL monitoring script
Create the following file using nano:
sudo nano /usr/local/sbin/SQL-wfi.sh
#!/bin/bash gpio -g mode 17 in gpio -g mode 17 up while [ 1=1 ] do # wait int pin to go low gpio -g wfi 17 both SQL=$(gpio -g read 17) if [ "$SQL" = "0" ]; then # gpio -g write 20 1 echo SQL GPIO low/closed else # gpio -g write 20 0 echo SQL GPIO high/open fi done
After making your changes type <CTRL> + <X> and then type <Y> followed by <Enter>. You will be back to the previous menu and choose <Back>.
Make the Init-GPIO and SQL-wfi.sh scripts run at startup
you have to add a line to the rc.local file.
sudo nano /etc/rc.local
Before the exit 0 line you have to add:
# For PTTLink /usr/local/sbin/Init-GPIO.sh /usr/local/sbin/SQL-wfi.sh
After making your changes type <CTRL> + <X> and then type <Y> followed by <Enter>. You will be back to the previous menu and choose <Back>.
Set permissions to execute scripts
cd /usr/local/sbin sudo chmod +x Init-GPIO.sh sudo chmod +x SQL-wfi.sh
Test GPIO pins
You can test PTT output by manually setting High or Low the PTT pin.
High:
gpio -g write 20 1
Low:
gpio -g write 20 0
Edit rpt.conf file
Now use nano to edit your rpt.conf file:
sudo nano /etc/asterisk/rpt.conf
On your node number stanza, i.e. [12345] add the following line:
events=events12345;
Then at the end of the file add the following stanza:
[events12345] gpio -g write 20 1 = S|T|RPT_TXKEYED; gpio -g write 20 0 = S|F|RPT_TXKEYED;
After making your changes type <CTRL> + <X> and then type <Y> followed by <Enter>. You will be back to the previous menu and choose <Back>.