USHAM.NET


Node 28523 Allmon W/Echolink KD4HLV-L
Node 28525
Support Page   Home   Buy  Ham's Project Page   Stuff For Sale




Hardware

Reading up on the DMK Engineering URI FOB, there are 4 GPIO pins coming from the CM119A sound chip. GPIO pin 3 is the PTT, so only pins 1,2 and 4 are available.
But GPIO pin 2 can only be used for input, while pins 1 and 4 can be use for input and output. See URI FOB Schematic as a PDF.

On the URI FOB, the DB25 connector pin 2 is labeled GPIO 1 and pin 4 is labeled GPIO 4. For input only, GPIO pin 2 is DB25 labeled pin 3. See URI FOB
data sheet for details. With all this information on hand, the next step was to see how to control GPIO pin 1 from Allstar app_rpt.



==========================================================================================================================

App_Rpt Configuration

To have Allstar and app_rpt manage the GPIO pins, I find the GPIO pins are controlled from a cop command. The details on this are located in this document:
Manipulating GPIO (and Parallel Printer Port) signals within chan_usbradio and chan_simpleusb. Also, I need to use the Allstar events manager to keep track of the state of the PTT on the radio. The details are located in the article Event Management Subsystem.

So as to not go into excruciating details, these were my requirements:

    I wanted to control the fan through a shell script.
    I wanted the fan script to know the state of the radio PTT (on or off).
    I needed the script to turn the fan on and off similar to logic per the tx fan script logic ported from IRLP by K0KN.
    I want to use an Arduino 1 channel relay like this (click here)

Assuming my node number is 1999 (pseudo node as example), the changes needed in rpt.conf and simpleusb.conf (or usbradio.conf) are these:

Add to simpleusb.com designate GPIO pin 1 as default state off (ground):

; When you configure a GPIO pin, you can either designate it as
; 'in' (input), 'out0' (output with a default state of 'off'),
; or 'out1' (output with a default state of 'on').

gpio1=out0 ; in, out0 or out1

 

Next modify the rpt.conf to add an event entry in the node stanza [1999]:

events=events1999

Next add an events stanza as defined above. It will create 2 events to monitor the radio TX key and create an empty file in the /tmp folder. If the file exists,
the radio is transmitting. If it does not exist, it is idle.

[events1999]
touch /tmp/RPT_TXKEYED1999 = s|t|RPT_TXKEYED
rm -f /tmp/RPT_TXKEYED1999 = s|f|RPT_TXKEYED

Next, add 2 functions that will eventually be called to turn on and off GPIO pin 1. Create in [functions1999] stanza corresponding to node 1999

90=cop,62,GPIO1=0 ; Turn off GPIO 1
91=cop,62,GPIO1=1 ; Turn on GPIO 1

Now we have what we need for app_rpt to receive commands to control the fan (GPIO pin 1), and inform us of the state of the radio transmitter key. The only thing we need is a process to manage the fan control process, and we will do this thru a shell script.

 
Testing GPIO Changes

To control the fan, we use an external shell script. We will control the fan by turning it on and off using the app_rpt function configured earlier below to execute a cop command. To test it, use the asterisk CLI command to execute function *91 to run cop command defined above (use your node number instead of 1999)

asterisk -rx "rpt fun 1999 *91"

To turn fan off:

asterisk -rx "rpt fun 1999 *90"

If fan turns on and off, we are ready to use a shell script to control the fan.

We also want to test that we can see the file created in the /tmp directory when the radio PTT is active. When radio is transmitting. you will see a file in the /tmp folder. File disappears when radio goes back to RX:

ls /tmp
-rw-r--r-- 1 root root 0 Aug 24 17:59 RPT_TXKEYED1999

 
Adding Fan Scripts

We will be putting a few scripts in the /etc/asterisk/local folder.

First, add the following line to end of existing /etc/rc.local

/etc/asterisk/local/run_app_rpt_fan.sh

Next, create a script to /etc/asterisk/run_app_rpt_fan.sh and add this, using your own node number:

#!/bin/bash

killall -e app_rpt_fan.sh > /dev/null
/etc/asterisk/local/app_rpt_fan.sh 1999 > /dev/null &

Make it executable with a:

chmod +x /etc/asterisk/local/run_app_rpt_fan.sh

 

Next, copy/download the main fan shell script into /etc/asterisk/local/app_rpt_fan.sh.
http://latinovoip.net/hamradio/allstar/app_rpt_fan.sh

Make it executable with a:

chmod +x /etc/asterisk/local/app_rpt_fan.sh

 

Or copy/paste script below. You can customize how much time fan will turn of while radio is transmitting, and how long to keep fan on after radio stops TX. Enjoy!

#!/bin/bash

#########################################################################################
#
# filename: app_rpt_fan.sh
#
# description: This file controls a PC fan attached to a DMK Engineering URI FOB
# It starts up when PTT is detected,
# and will stay on for the time period specified in
# the TIMEAFTER variable after the PTT drops.
# If the PTT is triggered in the countdown period, the timer resets.
#
# original authors: The majority of this script (the state manager) was taken from
# the ID scripts by KC6HUR and WW4M.
#
# history:
# 2005-02-16 kd6hwc Initial creation (with help from other scripts)
# 2007-07-29 k6jwn Added new variable PTTON, fan won't come on until this timer reaches it's limit.
# 2012-01-28 k0kn Adapted script for app_rpt system
# 2014-08-24 kp4tr Modified script for DMK Engineering URI FOB
#########################################################################################
#
# Modified from http://www.qsl.net/k0kn/txfan script by Kyle K0KN
# To use the GPIO pin on DMK Engineering URI FOB GPIO pin 1
# DB25 pin 2 and the functions+events stanza in rpt.conf
#
# Use diagram from http://www.dmkeng.com/images/GPIO_Relay.pdf
# The GPIO pin requires using a NPN switching transistor like
# 2N2222 or 2N3904 since it only draws 8 ma.
# You can use the Arduino 1 channel 12V relay boards for fan switch
# or build your own. Inside URI FOB DB25 male connector add a 4.7K resistor
# to base and wire inside DB25 male connector like this:
#
# Emitter to ground (DB25 pin 13,19,20 or 25)
# Base to DB25 pin 2
# Collector is your switch that would go to relay ground (-) or
# to arduino 1 channel relay input
#
# This is created in the [events] stanza of the node in rpt.conf
# When PTT is keyed and deleted when unkeyed
# In rpt.conf define in functions and events stanza
# Change 1999 to your rpt.conf configuration node number.
#
# [functions1999]
# 90=cop,62,GPIO1=0 ; Turn off GPIO 1
# 91=cop,62,GPIO1=1 ; Turn on GPIO 1
#
# [events1999]
# touch /tmp/RPT_TXKEYED1999 = s|t|RPT_TXKEYED
# rm -f /tmp/RPT_TXKEYED1999 = s|f|RPT_TXKEYED
#
##################################################################

#set -xv

if [[ $# -eq 0 ]];then
echo "Need a valid local Allstar node number to run fan script"
exit
fi

#this is set from events stanza to create or destroy this file
PTTSTATE="/tmp/RPT_TXKEYED$1"

#Your custom function defined in rpt.conf to turn URI FOB GPIO pin 1 on and off
FANON="/usr/bin/asterisk -rx \"rpt fun $1 *91\""
FANOFF="/usr/bin/asterisk -rx \"rpt fun $1 *90\""

# Define the period of time after the PTT drops to shut off the fan
TIMEAFTER=600

# Define the max PTT time before the fan is activated
PTTON=10

#### No changes needed after this line

# define variables
declare -i IDLETIMER
declare -i PTTKEY

# Start with state set to "Initial"

STATE="Initial"

while [ TRUE ]
do

case "$STATE" in

"Initial") # Wait for first keyup, then proceed to Countdown

echo -en "\r"`date ` "STATE = Initial\n"
sleep 1;
PTTKEY=0

while [ TRUE ]
do
echo -en "\rPTT Timer: $PTTKEY "
sleep 1;

# while PTT is silent (PTT=T)
if [ -f $PTTSTATE ] ; then
PTTKEY=$PTTKEY+1
fi

if ! [ -f $PTTSTATE ] ; then
PTTKEY=0
fi

if [ $PTTKEY -gt $PTTON ] ; then
break
fi
done
echo -en "\nPTT timer expired, activating fan"
eval $FANON
STATE="Countdown"
;;

"Countdown") # Count down period, if PTT is triggered, reset the timer.

echo -en "\n\n"`date ` "STATE = Countdown\n"
sleep 1
IDLETIMER=$TIMEAFTER

while [ TRUE ]
do
echo -en "\rFan powerdown timer: $IDLETIMER "
IDLETIMER=$IDLETIMER-1
sleep 1

if [ -f $PTTSTATE ]
then
IDLETIMER=$TIMEAFTER
fi

if [ $IDLETIMER = 0 ]
then
break
fi
done

echo -en "\nTimer expired, deactivating fan"
eval $FANOFF
STATE=Initial
;;

esac
done

echo -e "\n\nOops! - Not supposed to get to here"

============================================================================================================================


Manipulating GPIO (and Parallel Printer Port) signals within chan_usbradio and chan_simpleusb
Submitted by duuuude on Sat, 10/09/2010 - 18:02

The GPIO (general-purpose I/O) pins on a URI (or similar USB device) may be individually used as
either input or output pins. Currently the URI (because of the CM108-AH chip) only supports 2
usable GPIO pins (GPIO 1 and GPIO 4), plus one pin (labeled GPIO2, but is actually the 'HOOK' signal
on the CM-108AH chip) that may be used only for input. The old version of the URI and some other
devices that use the original CM-108A chip, have full access to the GPIO 2 signal also.

The upside to the CM-108AH is that if you are monitoring an external contact closure, the GPIO2 (HOOK)
input is internally pulled-up and de-bounced, so its perfect for such applications.

Chan_usbradio and chan_simpleusb supports configuration of the GPIO pins in the following manner
(from within the section of usbradio.conf that is for the desired device):

gpio1 = in          ; in, out0 or out1
gpio4 = out0        ; in, out0 or out1

When you configure a GPIO pin, you can either designate it as 'in' (input), 'out0' (output with a default state of 'off'), or 'out1' (output with a default state of 'on').

It also supports configuration of pins 2-9 (output) and pins 10-13 and 15 (inputs) on a Parallel
Printer Port (if you happen to have one) in the following manner:

pp2 =  out1      ; out0, out1 or ptt
pp10 = in        ; in, cor or ctcss

When you configure an input pin (10,11,12,13 or 15), you can either designate it as 'in' (input),
'cor' (use as the 'cor' input), or 'ctcss' (use as the 'ctcss') input. If you choose 'cor' or
'ctcss', you also need to set the associated 'carrierfrom' or 'ctcssfrom' to either 'pp' (use the
associated input pin non-inverted) or 'ppinvert' (use the associated input pin inverted).

When you configure an output pin (2-9), you can either designate it as 'out0' (output with a default
state of 'off'), 'out1' (output with a default state of 'on'), or 'ptt' makes the PTT signal present
on it either non-inverted or inverted, depending on the 'invertptt' setting.

Pins 18-25 are ground, and all other pins are to be treated as no connection.

The condition of the input pins are made available via channel variables (e.g. RPT_URI_GPIO1,
RPT_URI_GPIO4, RPT_PP12, etc.) used by the Event Management Subsystem.

The output pins may be manipulated via the 'cop,61' (or 'cop,62') command (directly or through a DTMF
command) as follows:

61 - Send Message to USB to control GPIO pins (cop,61,GPIO1=0[,PP4=1].....)
62 - Same as above, without generating the 'complete' telemetry.

Use 0 or 1 to set the specified output to 0 or 1, or a number greater then 1 to specify how
many milliseconds minus 1 to invert its current state. For example, to pulse the bit for 500ms you
would use the value '501'(currently, specified time only significant in increments of 50ms). The
use of specifying a value of N+1 to indicate N milliseconds was done so that if, in the future,
the granulatity increases down to the millisecond level, a value of 1 ms could be specified.

For example, if you wanted to have a DTMF function (in this example *1234) that turned GPIO 1
on, you would specify the following in the [functions] section of the rpt.conf file:

1234 = cop,61,GPIO1=1      ; Turn on GPIO 1

Note: You must have app_rpt version 0.259 10/9/2010, and chan_usbradio also released at
that time, and for Parallel Printer Port support, you must have app_rpt version 0.267
10/23/2010, and chan_usbradio also released at that time.

====================================================================================================================










____________________________________________________________________________________________________________________________________

All trademarks, trademark names, service mark names, trademark images and logos used on this web site are done so with an educational or informative intent. All trademarked names belong to the owner and no violation or infringement is intended. Motorola├é┬« is a registered trademark of Motorola Inc. Logo image used with permission. Registered trademarks, service marks, or copyrights of Motorola Inc.include the "batwing" M logo, Astro, Astro Saber, Astro Spectra, Channel Scan, Compa-Station, Consolette, Convertacom, CoronaryObservation Radio, COR, "Deluxe Line", DPL, Digital Private Line, Extender, Expo, GM300, GR300, GR500, GTX, Handi-Com, Handi-Talkie,Hear-Clear, HT50, HT90, HT100, HT200, HT210, HT220, HT440, HT600, HT1000, HT1250, JT1000, MaraTrac (a.k.a. Maratrac), MaxTrac (a.k.a.Maxtrac), MCX, MCX100, MCT3600, MTC4800, MDC600, MDC1200, Mem-o-Lert, Micom, Micor, Mitrek, Mitrek Plus, MPL, Mocom, Mocom 10, Mocom 30,Mocom 70, Modat, Mostar, Motrac, Motran, MoTrek, MSF5000, MSF10000, MSR2000, MT500, MT1000, MT2000, MTR2000, MTS2000, MPL, Multiple PL,MVA, MVS10, MVS20, P10, P50, P200, Power Voice, Privacy Plus, PT200, PT300, PT400, PT500, PL, Private Line, Privacy Plus, Quantar, Quantro,Quick Call, Quick Call II, Radius, Radio Service Software, RSS, Radius, "Research Line", Saber, Securenet, Sensicon, Sensitron, SM10, SM50,SM120, Smartnet, Smartzone, SP10, Spectra, Spectra II, Syntor, Syntor X2, Syntor X3, Syntor X, Syntor X-9000, Syntor X 9000E, Syntrx, System90, System 90S, Systems 9000, T-Power, Talkabout, Talkaround, Talkback Scan, Touch Code, Trunked X2, Trunked X3, UniChannel, the stylized anddrop-shadowed X on the Syntor X logo, XTS3000, XTS5000, DMK URI, Microsoft and there Windows Line, DOS through Windows 10 and beyond, a big bunch more that I can't remember at 3am. In short, trademarked names belong to the owner and no misuse, violation or infringement is intended. All usage on these web pages at this web site is in a descriptive or educational use. Not responsible for errors and typos. All ARiUSB are Sold AS-IS, but sold as Tested working when shipped 


_____________________________________________________________________________________________________________________________________







This Website is 100% MS Free

"Just say NO

                 to MicroSoft!!"
I've been MS and Virus Free since 2000!
"Say Yes! to Linux!!"