WikiVMAC PiHat v2 Testing I/O

HAMKit Wiki Repository
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
 HAMKit Wiki
News and Information
RasDuinoHat
Raspberry Pi
VDAS
VMAC PiHat v1
VMAC PiHat v2

The below is a simple piece of Python test code that will setup the HAMKit VMAC PiHat v2 GPIO and I2C I/O and allow you to easily perform basic tests.

For simplicity, you can use Thonny to run and edit the Python code. This application is included within Raspbian and also available for Windows and MAC users.

  • GPIO  Ground an Input (Button or SQ1-4), flash LEDs depending on which input selected.
  • Video Input Detect – (VD_1, VD_2, VD_3), flash LEDs depending on which input detected.
  • I2C FMS6501A  Fast Scan all Matrix inputs to all Matrix outputs. (Used on test jig to check all OK).
  • See other Wiki for DTMF Decode.

Bring up Test: When testing the Matrix, initially use audio at line level input, with a 1 kHz tone.  Monitor any output and as  the input matches output selected, a beep tone will be heard.  Simply select another input or output, and workaround all I/O.

Note: When using the audio tone test and then selecting video, or audio, inputs/output, an output level change will be noted. This is due to the two different impedance use for video and audio, and is normal.

CODE (Provisional)

# HAMKit VMAC PiHat | Test Loop Example Code to Setup GPIO and I2C. v2.0 Beta
# Test code is suitable for PiHat PCB revision 2.0
# GPIO : Ground an Input (Button/SQ1-4), flash LEDs depending on which input selected.
# I2C FMS6501 : Scan all Matrix inputs to all Matrix outputs. Used on test jig to check all OK.
# When testing Matrix, input line level audio @ 1kHz tone and as the input matches output selected, a tone will beep.
# Dave Williams G8PUO, January 2018

#!/usr/bin/python

#Check i2c bus
#sudo i2cdetect -y 1

import smbus
import RPi.GPIO as GPIO
import time

#====== GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#GPIO.cleanup()

#Define GPIO Inputs
Button = 4
SQ1 = 12
SQ2 = 16
SQ3 = 20
SQ4 = 21
VD1 = 18
VD2 = 23
VD3 = 24

#Setup Inputs with pull-ups enabled
GPIO.setup(Button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SQ1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SQ2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SQ3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SQ4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(VD1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(VD2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(VD3, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#Define GPIO Outputs
LEDStatus = 22
PTT = 27

#Setup Outputs
GPIO.setup(LEDStatus,GPIO.OUT)
GPIO.setup(PTT,GPIO.OUT)

#Initiate LEDs
GPIO.output(LEDStatus,GPIO.HIGH)
GPIO.output(PTT,GPIO.HIGH)
time.sleep(1)
GPIO.output(LEDStatus,GPIO.LOW)
GPIO.output(PTT,GPIO.LOW)
time.sleep(1)

#Good old fashion subroutine
def flashleds (flashes):
    for x in range(flashes):
        GPIO.output(LEDStatus,GPIO.HIGH)    
        GPIO.output(PTT,GPIO.HIGH)
        time.sleep(0.2)
        GPIO.output(LEDStatus,GPIO.LOW)       
        GPIO.output(PTT,GPIO.LOW)
        time.sleep(0.5)

#====== FMS

#define values
DEVICE_BUS = 1
DEVICE_ADDR = 0x43 #0x43 or 0x03

#setup i2c bus
i2cbus = smbus.SMBus(DEVICE_BUS)

while True:
    #Detect Change To An Input And Flash LEDs
    if GPIO.input(SQ1) == False:
        print ("SQ Input 1")
        flashleds (1)
    if GPIO.input(SQ2) == False:
        print ("SQ Input 2")
        flashleds (2)
    if GPIO.input(SQ3) == False:
        print ("SQ Input 3")
        flashleds (3)
    if GPIO.input(SQ4) == False:
        print ("SQ Input 4")
        flashleds (4)
        
    if GPIO.input(Button) == False:
        print ("Button")
        flashleds (5)
        
    if GPIO.input(VD1) == True:
        print ("Video Detect Input 1")
        flashleds (6)
    if GPIO.input(VD2) == True:
        print ("Video Detect Input 2")
        flashleds (7)
    if GPIO.input(VD3) == True:
        print ("Video Detect Input 3")
        flashleds (8)          

    #Send Command to I2C - Loop inputs to outputs
    #Input and Output Cycle
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x81) #Input 1 to Output 1
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x81) #Input 1 to Output 2
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x81) #Input 1 to Output 3
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x81) #Input 1 to Output 4
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x83) #Input 2 to Output 1
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x83) #Input 2 to Output 2
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x83) #Input 2 to Output 3
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x83) #Input 2 to Output 4
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x85) #Input 3 to Output 1
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x85) #Input 3 to Output 2
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x85) #Input 3 to Output 3
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x85) #Input 3 to Output 4
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x87) #Input 4 to Output 1
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x87) #Input 4 to Output 2
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x87) #Input 4 to Output 3
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x87) #Input 4 to Output 4
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x89) #Input 5 to Output 1
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x89) #Input 5 to Output 2
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x89) #Input 5 to Output 3
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x89) #Input 5 to Output 4
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x8b) #Input 6 to Output 1
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x8b) #Input 6 to Output 2
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x8b) #Input 6 to Output 3
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x8b) #Input 6 to Output 4
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x8c) #Input Pi to Output 1
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x8c) #Input Pi to Output 2
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x8c) #Input Pi to Output 3
    time.sleep(.01)       
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x8c) #Input Pi to Output 4


Please feel free to share our product love through the below

HAMKit | Facebook Comments