BUILD A CRICKET SCORE TICKER WITH A RAPBERRY PI

Hi guys,

In this blogpost I’ll be making a raspberry pi cricket score ticker. basically it makes the pi get the score card from the internet and displays it like a ticker On the LCD screen

For this we shall make use 0f an API (Application Programming Interface)(click here to know more about API) website that give us the  current score via the internet in .json (JavaScript Object Notation) format. This method can be used for getting other data such as weather data, football score,news. etc

Let us begin

parts you will need

  • Raspberry pi (my model is the raspberry pi b+ with raspbian OS installed)
  • 16X2 serial LCD module
  • internet connection

Pyserial

If you aren’t aware about Pyserial, it is the serial communication package for the python programming language. we will need this for sending data to the serial LCD module. Pyserial can also be used to send data to serial devices. It can also talk via serial with the arduino. If you need more help with the serial port connection check out this instructable http://www.instructables.com/id/Read-and-write-from-serial-port-with-Raspberry-Pi/

Installing pyserial to the Raspberry pi

  • boot the pi with a keyboard and mouse connected
  • open up lx-terminal
  • in terminal type sudo apt-get update to update apt get (if not updated recently)
  • now type sudo apt-get install python-pyserial
  • now open up the python shell and type import serial. if you get no errors then the serial module is successfully installed.

Important:remember its import serial not import Pyserial

Requests

The requests module will fetches us the score data from the cricket score API website. By default the requests module is not installed on python and we need to download the module and install it. see the next section regarding how to get this done.

We shall be getting the score info from  https://cricscore-api.appspot.com/ . This site provides the live score of domestic as well as international matches taking place on that day.

to get the data regarding the matches that are currently scheduled today we need to send a request to this link: https://cricscore-api.appspot.com/csa

it will get us with a page that looks something like this

[{“id”:958697,”t2″:”Central Zone (Bangladesh)”,”t1″:”East Zone (Bangladesh)”},{“id”:958695,”t2″:”North Zone (Bangladesh)”,”t1″:”South Zone (Bangladesh)”},{“id”:960101,”t2″:”West Indies Under-s”,”t1″:”Bangladesh Under-s”},{“id”:936969,”t2″:”Saracens Sports Club”,”t1″:”Ragama Cricket Club”},{“id”:959379,”t2″:”England Lions”,”t1″:”United Arab Emirates XI”},{“id”:874859,”t2″:”Northerns”,”t1″:”KwaZulu-Natal”},{“id”:852013,”t2″:”Lions”,”t1″:”Knights”},{“id”:852015,”t2″:”Dolphins”,”t1″:”Titans”},{“id”:852011,”t2″:”Cape Cobras”,”t1″:”Warriors”},{“id”:874855,”t2″:”Northern Cape”,”t1″:”Namibia”},{“id”:874857,”t2″:”South Western Districts”,”t1″:”Western Province”},{“id”:800465,”t2″:”England”,”t1″:”South Africa”},{“id”:897751,”t2″:”Brisbane Heat”,”t1″:”Melbourne Stars”},{“id”:895809,”t2″:”India”,”t1″:”Australia”},{“id”:896525,”t2″:”Sydney Thunder Women”,”t1″:”Melbourne Stars Women”},{“id”:896527,”t2″:”Sydney Sixers Women”,”t1″:”Hobart Hurricanes Women”},{“id”:896529,”t2″:”Melbourne Renegades Women”,”t1″:”Adelaide Strikers Women”},{“id”:914221,”t2″:”Pakistan”,”t1″:”New Zealand”}]

The ‘id’s correspond to separate matches

if we need to get the score of the Australia vs India match just find out the “id”. In this case it is “895809

Now if we go to this link https://cricscore-api.appspot.com/csa?id=895809 you will find the score there. the ‘id’ should be there at the end of the link.

Installing the requests module

this is similar to the pyserial library installation

  • open up lx-terminal
  • type the command sudo apt-get install python-requests
  • now open up the python shell and type import requests. if you get no errors then the serial module is successfully installed

The Final part

  • You will need this python program. copy and save it as ticker.py
    15/1/16
    from time import sleep
    import requests
    from serial import Serial
    
    sleep(60) #program starts after 1 minute of booting the pi
    
    ser = Serial(port='/dev/ttyAMA0',baudrate=9600)
    
    r = requests.get('http://cricscore-api.appspot.com/csa')
    scan_matches = r.json()
    print scan_matches #find the match_id you want the score of
    
    match_id = '800465' #paste the relevant match_id here
    
    k=0
    while k==0:
       r = requests.get('http://cricscore-api.appspot.com/csa?id='+match_id)
     
       match_data = r.json()
       current_score = match_data[0]['de']
       overview = match_data[0]['si']
    
       a = ' '
       s = current_score+a+overview
       sa = a + s + a
    
       j = len(sa)
       j -= 17
    
       i = 0
    
       while i < j:
           p1= sa[i]
           p2= sa[1+i]
           p3= sa[2+i]
           p4= sa[3+i]
           p5= sa[4+i]
           p6= sa[5+i]
           p7= sa[6+i]
           p8= sa[7+i]
           p9= sa[8+i]
           p10= sa[9+i]
           p11= sa[10+i]
           p12= sa[11+i]
           p13= sa[12+i]
           p14= sa[13+i]
           p15= sa[14+i]
           p16= sa[15+i]
           p17= sa[16+i]
           p18= sa[17+i]
    
           LCD = p1+p2+p3+p4+p5+p6+p7+p8+p9+p10+p11+p12+p13+p14+p15+p16+p17+p18
    
           ser.write(chr(12))
           ser.write(LCD)
           sleep(0.2)
           i += 1
     }
    

     

  • go to https://cricscore-api.appspot.com/csa and find the match ‘id’
  • paste the ‘id’ in the python program as shown in pic below
    
    `match_id = '800465' #paste the relevant match_id here`
  • Connect the parts as per the circuit diagram. You will need the raspberry pi GPIO pin layout from this linkcircuit connection.jpg
  • connect the pi a working internet connection and boot the pi and run the ticker.py program. Wait for a few minutes for the program to start running. There we be a slight lag in between for getting the accurate scores.cricket score ticker raspberry pi.jpg

If you would like to go one step further. you can make the python program run at startup. this way you won’t need to connect to a screen, besides the LCD. to do this try this link http://www.raspberrypi-spy.co.uk/2013/07/running-a-python-script-at-boot-using-cron/


Here is the video for this project

like if you liked this post. subscribe to this post if you want more such projects. Should I make a football score ticker next or some other project. leave your comments below.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s