Monthly Archives: April 2017

FreeSWITCH status on LED display using socket connection

It is a simple experiment to show  FreeSWITCH  status on LED display using socket connection. Here is Video :

What You Need

1.Raspberry pi-3

2.MAX-7219 based 8×8 LED Matrix Displays(4.No’s or more).

Those available in kit form and assembled form. And we can purchase through on- line marketing like Amazon etc.

In my case 4 modules are powered from GPIO pins of Raspberry . It is good to use separate power for modules for more than 2 modules.

3.Female to Female connector wires

to connect GPIO pins and MAX7219 LED modules.

Next What to do(installing FreeSWITCH)

1.Prepare SD card and load Raspbian and install FreeSWITCH.  For details

https://www.algissalys.com/how-to/freeswitch-1-7-raspberry-pi-2-voip-sip-server

2.Install Display drivers for MAX7219. 

git clone https://github.com/rm-hull/max7219.git
sudo python max7219/setup.py install

3.Do wiring.

(as given below) between GPIO of Raspberry pi and MAX 7219 matrix LED displays.

Pin        Name       Remarks            RPi Pin          RPi Function

1            Vcc          +5V Power              2                        5V0

2            Gnd           Ground                  6                        Gnd

3            DIN            Data In                 19                GPIO 10 (MOSI)

4             CS          Chip Select              24                 GPIO  8 (SPI CS0)

5            CLK           Clock                      23                GPIO 11 (SPI CLK)

4.Run demo program.

Edit matrix_demo.py according to no. of matrix devices used  i.e cascaded= n, in my case n=4.

device = max7219(serial, cascaded=4 or 1, block_orientation=block_orientation).

sudo python max7219/examples/matrix_demo.py

At Last

Use ESL connection between FreeSWITCH and Max7219demo program. For details

https://freeswitch.org/confluence/display/FREESWITCH/Python+ESL

Here is my source file.

#!/usr/bin/env python

import string
import sys
import re
import time
import argparse

from optparse import OptionParser
from ESL import *
from luma.led_matrix.device import max7219
from luma.core.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT

def main(argv):

        try:

                parser = OptionParser()
                parser.add_option("-a", "--auth", dest="auth", default="ClueCon",
                                                                help="ESL password")
                parser.add_option("-s", "--server", dest="server", default="127.0.0.1",
                                                                help="FreeSWITCH server IP address")
                parser.add_option("-p", "--port", dest="port", default="8021",
                                                                help="FreeSWITCH server event socket port")
                parser.add_option("-c", "--command", dest="command", default="status",
                                                                help="command to run, surround mutli word commands in \"\'s")

                (options, args) = parser.parse_args()


                con = ESLconnection(options.server, options.port, options.auth)
        #are we connected?

                if con.connected():
                        #run command

                        e = con.api(options.command)
                        print e.getBody()
                        global data
                        data = e.getBody()
                else:

                        print "Not Connected"
                        sys.exit(2)

        except:

                print parser.get_usage()

def demo(n, block_orientation):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation)
    print("Created device")

    # start demo
    msg = data
    print(msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)


while 1:
        if __name__ == "__main__":
                main(sys.argv[1:])


        if __name__ == "__main__":
            parser = argparse.ArgumentParser(description='matrix_demo arguments',
                formatter_class=argparse.ArgumentDefaultsHelpFormatter)

            parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')
            parser.add_argument('--block-orientation', type=int, default=0, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')

            args = parser.parse_args()

            try:
                demo(args.cascaded, args.block_orientation)
            except KeyboardInterrupt:
                pass