Wiki VMAC PiHat Matrix GUI

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
Standard Page
VDAS
VMAC PiHat v1
VMAC PiHat v2

    In order to further enhance our VMAC PiHat Home AV Switch Wiki test code, we take the ‘memory’ concept to select inputs and outputs, add a graphic interface and add Buttons.

    To learn more about how to easily add graphics to code, visit our Wiki Raspberry Python GUI where we take Python and incorporate a graphical user interface, GUI.  This Wiki is an extension of this, as can be seen below.

    The Python code includes a GUI library called appJar, which is then merged with our test code to control the FMS6501A audio and video matrix device, through screen buttons.  The buttons are then set in the code to select certain inputs and outputs.

    NB: If you have a touch screen on your Pi, then the buttons should also just work!

    In our example, the buttons call functions as listed below:

    • Memory 0 = Mute All. Flash LED.
    • Memory 1 = Video In 1 to both Video Out 1 plus 2. Audio In 4 to Audio Out 3 plus 4. Flash LED.
    • Memory 2 = Video In 2 to both Video Out 1 plus 2. Audio In 5 to Audio Out 3 plus 4. Flash LED.
    • Memory 3 = Video In 3 to both Video Out 1 plus 2. Audio In 6 to Audio Out 3 plus 4. Flash LED.
    • Memory 4 = Pi Video to both Video Out 1 and 2. Pi L/R Audio to Audio Out 3 and 4. Flash LED.

    Pressing the buttons will automatically setup the inputs and outputs, flash the PiHat LED’s and display in the Terminal details of the memory selected.

    The project test code is named HAMKit VMAC PiHat – Test Matrix GUI v1.py  and this was, for convenience only, then renamed in the Pi Terminal to MatrixGUI.py using the below command:

    mv "HAMKit VMAC PiHat - Test Matrix GUI v1.py" MatrixGUI.py

    Rather than open the Python IDE editor, the code was then simply run from the terminal command line, using the below command:

    python MatrixGUI.py

    Note: You will need to install the GUI library called appJar.   Should this need adding, simply run the below commands:

    pip3 install appjar
    pip install appjar

    HAMKit VMAC PiHat – Test Matrix GUI v1 – Python Code

    # HAMKit VMAC PiHat - Test Matrix GUI v1
    # Memory 0 = Mute All. Flash LED.
    # Memory 1 = Video In 1 to both Video Out 1 plus 2. Audio In 4 to Audio Out 3 plus 4. Flash LED.
    # Memory 2 = Video In 2 to both Video Out 1 plus 2. Audio In 5 to Audio Out 3 plus 4. Flash LED.
    # Memory 3 = Video In 3 to both Video Out 1 plus 2. Audio In 6 to Audio Out 3 plus 4. Flash LED.
    # Memory 4 = Pi Video to both Video Out 1 and 2.  Pi L/R Audio to Audio Out 3 and 4. Flash LED.
    # NB: All outputs are initially muted
    # Dave Williams G8PUO, January 2017
    
    #!/usr/bin/python
    
    import smbus
    import RPi.GPIO as GPIO
    import time
    from appJar import gui
    
    # Create and setup a GUI Window
    app = gui("HAMKit PiHat Matrix Memories", "400x400")
    app.setBg("lightblue")
    app.setFont(16)
    app.setTitle("HAMKit PiHat Matrix Memories")
    
    #====== GPIO
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    #GPIO.cleanup()
    
    #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 subroutines
    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.2)
    
    def memory0():
    	print ("Memory 0 - Mute")
    	i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x0) #Mute
    	time.sleep(.01)
    	i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x0) #Mute
    	time.sleep(.01)
    	i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x0) #Mute
    	time.sleep(.01)
    	i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x0) #Mute
    	time.sleep(.01)         
    	flashleds (1)            
    
    def memory1():
    	print ("Memory 1 - Video In 1>Video Out 1+2 & Audio In 4>Audio Out 3+4")
    	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, 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)    
    	flashleds (1)	
    	
    def memory2():	
    	print ("Memory 2 - Video In 2>Video Out 1+2 & Audio In 5>Audio Out 3+4")
    	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, 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)    
    	flashleds (1)	
    
    def memory3():	
    	print ("Memory 3 - Video In 3>Video Out 1+2 & Audio In 6>Audio Out 3+4")
    	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, 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)    
    	flashleds (1)	
    	
    def memory4():	
    	print ("Memory 4 - Pi Video Out>Video 1+2 & Pi Audio L/R>Audio Out 3/4")
    	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, 0x89) #Input 5 to Output 3
    	time.sleep(.01)
    	i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x8b) #Input 6 to Output 4
    	time.sleep(.01)     
    	flashleds (1)
    
    #====== FMS
    
    #define values
    DEVICE_BUS = 1
    DEVICE_ADDR = 0x43 #0x43 or 0x03
    
    #setup i2c bus
    i2cbus = smbus.SMBus(DEVICE_BUS)
    
    #Set all outputs to mute.
    i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x0) #Mute
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x0) #Mute
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x0) #Mute
    time.sleep(.01)
    i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x0) #Mute
    time.sleep(.01) 
    
    # GUI Buttons
    app.addButton("Memory Mute", memory0)
    app.addButton("Memory One", memory1)
    app.addButton("Memory Two", memory2)
    app.addButton("Memory Three", memory3)
    app.addButton("Memory Four", memory4)
    
    app.go()

    Please feel free to share our product love through the below