Skip to main content

84. DIY Arduino Live IPL Scoreboard using Adafruit TFT Touch Shield and Python

 Hey everyone!

The Indian Premier League, IPL, is the most famous in all formats of Cricket. According to The Hindu, the Board of Control for Cricket in India (BCCI) has decided against suspending the league despite cricketers choosing to return home midway through the IPL and people calling for the tournament's postponement due to the current COVID-19 situation. This league has attracted millions of fans but sadly, none of them are allowed to watch the games in the stadium due to the pandemic situation.

While some may have access to view the scores or watch the match, some may not know about the match timeline until the final results are released. I decided to make a DIY Arduino Live IPL Scoreboard using my Adafruit TFT Touch Shield and Python and the scores will be updated every 100 milliseconds.

Read on further to learn how I did this project. After reading this post, you would also be able to make one on your own!

Hardware components required for this project

  •  Arduino Mega 2560
  • Adafruit 2.8" TFT Touch Shield for Arduino w/ Capacitive Touch - You could also use any other Arduino compatible TFT display
  • Micro SD Card 

Software apps and Online services

  • Arduino IDE 1.8.13 - Latest version
  • Python 3.9.4
  • ESPN Cric Info xml - http://static.cricinfo.com/rss/livescores.xml

Setup





Connections

You can simply place the Adafruit TFT Touch shield onto your Arduino Mega 2560 development board.
Make sure to include these in your code:
  • SD Chip Select pin - D4
  • TFT Data Command pin - D9
  • TFT Chip Select pin - D10

Coding

For this project, you will need to use both Arduino and Python. I will be guiding you through each step in this section. I advise you to first watch the YouTube video in the last section of this page to get an idea about how this project works.

Download the images of the IPL team logos. You have to download the latest logos as they may change. Resize the images to 100x100 pixels and convert them to 16 color bitmap format. Download a question mark vector image as well and follow the step mentioned above.

Python

You will be needing Python to prepare a python script to obtain data from the RSS XML file.
Make sure to install the latest version of Python if you don't have one already.
For this script, you will be needing to following Python modules:
  • PySerial - Python Serial Port Extension
  • PyTime - Aims to operate date/ time/ datetime by string
  • Urllib3 - User-friendly HTTP Client for Python
  • xml.dom.minidom - Minimal implementation of the Document Object Model interface
To learn how to use the modules, please follow the hyperlink. The websites provide complete documentation and instructions for installation. By reading the documentation, you will be able to find the specific functions that should be used to perform the tasks mentioned in this section.

*Note: I would recommend you to try doing this project in the Python IDLE before preparing a script so that you will understand how the data is processed in each function.

After you install the modules, create a new file in Python by going to File and selecting New File.
Import the following modules using the import function.
You have to parse the XML file so you have to import parseString from xml.dom.minidom. This can be done by typing in 'from xml.dom.minidom import parseString'.
Initialize the serial connection in the COM port your Arduino uses at 9600 baud rate and set a delay of 2 seconds for stability while the connection is achieved. To set delay, use time.sleep( ) function where the parameter is the number of seconds.
You will have to run your script on loop so that the scores will be updated on the TFT display. To keep your script running on loop while the serial connection is active, use 'while True:'. 
Request for the RSS URL by using PoolManager class from urllib3. The RSS URL is: http://static.cricinfo.com/rss/livescores.xml. Follow the hyperlink to see how it's done. The data will be received as bytes so it's time for you to convert them to string so that you can parse it. This can be achieved by using the data and decode methods.
Parse the xml from the string and retrieve the xml tags (<tag>data</tag>) that the parser finds with the TagName mentioned within the parameter. You have to use getElementsByTagName method for this and in this case, you will need the data within the 'title' tags. The TagName in this case will be 'title'.
If you are trying this in the Python IDLE, you will notice that the getElementsByTagName method will return a list. You will have to convert them to xml while running through a for loop. You have to use for x in xml to run through each items in the list. Use the replace( ) string method to replace the tags with whitespace.
We are utilizing the RSS file where the scores for all ongoing cricket matches are displayed and we will only need the IPL scores. You have to use if function to check if there are any IPL matches available. The team names may have some words similar like 'Royal' in Royal Challengers Bangalore and Royal Rajasthan but the states' names are unique for each team. You will use this in the if function to check if the parsed data contains any state name.
The next part is quite tricky so as I already mentioned, I advise you to watch my YouTube video on the last section of this page if you haven't done that already. 
Along with displaying the scores on the scoreboard, you will also have to display the respective teams' logos. This step must be automatic so that the logos are updated when the match changes.
The scoreboard will only display live scores and if you refer to the RSS URL, you will notice that the live matches have an '*'.
Write down all the possible match combinations and use them to write a unique character to the port in bytes which will then be received by the Arduino to perform a specific set of functions.
I will give you an example.
If the match happening today is CSK vs RCB, then your if function must be:
if (('Chennai' in xmlData) and ('Bangalore' in xmlData) and ('*' in xmlData)):
    ser.write('A'.encode( ))
    time.sleep(2)

The encode function is used to convert the string to bytes and the parameter is 'utf-8' by default. I have used 'A' because it is not part of the xmlData and there won't be any confusions when the data is written to the port.
Do this for all the possible match combinations. Remember, the characters you choose must never be a part of the xmlData. Some characters are E, F, G, I, J, q, w, etc. I have not used B or C as they are in Royal Challengers Bangalore or v because it is in Chennai Super Kings v Royal Challengers Bangalore.
If the xmlData does not contain any states' names or if there are no live matches available, you have to send another unique character. You will know why when you read the next section - 'Arduino'.
You are still within the for loop. The Arduino can read bytes from the Serial buffer and if you want to send data to the Arduino via Python, you have to break it down to letters and encode them.
The xmlData contains a line and you have to break them down to words first. For this, you have to use the split( ) string method which will split the string to a list where each word is a list item. You can specify the separator but in this case, we will be using the default one which is whitespace.
Now you have a list with each word as the item. Create a for loop to run through each item in the list so that you can encode and write each word to the port. Within the loop, use encode method and then write function. Before exiting the loop, you have to encode and write a whitespace so that the words displayed on the TFT display will have space within them and add a delay of 3 seconds to prevent overflow of Arduino buffer. Remember that we broke down the string using whitespace as the separator and the whitespace was removed leaving the words as items in the list. 
Finally, encode and write a 'z' to the port and set a delay of 2 seconds. Note that we do not exit the first for loop.
Now your python script is complete. It's time to work on the Arduino sketch.

Arduino

For this sketch, you will need the following libraries:
Before preparing the script, I advise you to refer to the ShieldILI9341 example sketch from the Adafruit_ImageReader examples folder. As I already mentioned in the Connections section, you have to define the pins.  Create the Image-reader object using the SD card file system. 

Within void setup( ), set the baud rate to 9600 bauds and initialize the screen. Set the text size to 2 pixels and rotate the screen by calling setRotation( ) method where the parameter will be 1. The screen should be black when starting up, so use fillScreen( ) method and set the parameter to 0. The text color should be white and set the cursor position to (150,0). You can choose from a range of colors assigned within the ILI9341 library or if you want something other than that, you must assign them by using their respective RGB565 format.
Colors assigned within the ILI9341 library:
  • Black - 0x0000
  • Navy - 0x000F
  • Dark Green - 0x03E0
  • Dark Cyan - 0x03EF
  • Maroon - 0x7800
  • Purple - 0x780F
  • Olive - 0x7BE0
  • Light Grey - 0xC618
  • Dark Grey - 0x7BEF
  • Blue - 0x001F
  • Green - 0x07E0
  • Cyan - 0x07FF
  • Red - 0xF800
  • Magenta - 0xF81F
  • Yellow - 0xFFE0
  • White - 0xFFFF
  • Orange - 0xFD20
  • Green Yellow - 0xAFE5
  • Pink - 0xFC18
Within the void loop( ), create a variable to store the incoming byte. Use the serial.available( ) function to get the number of bytes available for reading from the serial port and the variable must be assigned to store the incoming byte. Use serial.read( ) function to read the incoming serial data. If the incoming byte is 'z' - remember that we sent 'z' to the serial port in the python script after exiting the second for loop - then the TFT display must be cleared, 'VS' must be printed in (149, 60) and the cursor must be set to (0,150).
If the incoming byte is 'A' the logos of CSK and RCB must be printed on the TFT display by using the reader.printStatus( ) function. The coordinates are (10,10) and (210,10). Follow this step for all your unique characters by using else if( ) function. If the incoming byte is '?', a question mark vector image must be printed and the TFT display must print the following message: 'No Live Matches found at the moment. Please try again later'. If none of your unique characters are received, then use to else( ) function to print the incoming byte on the TFT display.
Set a delay of 100 milliseconds.
Now you have completed your sketch. Compile and upload the sketch to your Arduino microcontroller.

If anyone has any questions or suggestions about this project, please feel free to comment below.

Final Look


If anyone has any questions or suggestions about this project, please feel free to comment below.



Comments

Popular posts from this blog

51. Buzz wire game using Arduino

Hello everyone! This is my first Arduino project in 2020 and it is going to be a fun and simple project. You would have heard of the Buzz Wire, a steady hand game, and today you will be learning to make one using Arduino. Hardware components used in this project Arduino Nano USB Type A to mini B cable (for Arduino Nano) Solderless Breadboard - Mini and Full-size LEDs (x2) - Green and Red Resistors (x2) - 220 Ω  Active Buzzer module (KY-012) LCD display module with I2C interface - 16x2 Male-to-Male Jumper wires (x4) - 10cm Female-to-Male Jumper wires (x5) - 20 cm Jumpers (x5) - to reduce the usage of wires Copper wire  Tape (or any form of insulation)  Setup Your hardware setup must look somewhat similar to the ones in the images above. The beginning and end of the copper wire maze must be taped to prevent conductivity between the wire loop and maze. Connections LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5

71. Buzz Wire Game ( Version 2.0 ) using Arduino

Hey Everyone! I hope that everyone's safe during this pandemic. Today I am going to explain you about the second version of my Buzz wire game. People who are bored of staying indoors can find this game pretty interesting and fun to play.  If you are a beginner, you can start off with my first version of this project :  51. Buzz wire game using Arduino   Hardware components used in this project Arduino Uno Solderless Breadboard (x2) - Full/ Full+ LCD display module with I2C module - 16x2 Potentiometer - B20K Push-buttons (x3) Resistor - 220 Ω Active Buzzer module (KY-012) LED - Red Copper Wire - 19/ 20 gauge thick Male-to-Male Jumper wires - 10cm and 20cm Wire - Long enough to connect the loop of copper wire to ground Other tools required for this project Cutting pliers - To cut the right amount of copper wire Round-nose pliers - To bend the copper wire and make a maze and loop Hardware setup Connections Wire Maze - D2 Wire loop - Ground (GND) B20K Potentiometer S - A0 (+) - 5V (-)

86. RFID Health tag (Arduino and Python)

 Hey everyone, Sorry I have not uploaded in a while. Today, I will be sharing an interesting project with all of you. This RFID Health tag project is useful when it comes to keeping track of vaccinated individuals, their biodata and their health conditions and medications. For this project, you will be needing Arduino and Python. Read on further to see how I did this project. Hardware components used in this project Arduino Uno Solderless Breadboard - Half+ MRFC522 RFID reader RFID key tags (x5) Push-buttons (x2) Male-to-Male Jumper wires (x12) USB Type A/ B cable (for Arduino Uno) Software required Arduino IDE - latest version recommended Python 3.8 Schematic MFRC522 RFID reader SDA/ SS - D10 SCK - D13 MOSI - D11 MISO - D12 IRQ - Not connected GND - Ground RST/ RESET - D9 3.3V - 3.3V Push-buttons Submit button - D4 Retrieve button - D5 Coding Arduino For this project, you will be using the following libraries: MFRC522 by miguelbalboa -  https://github.com/miguelbalboa/rfid SPI - In-bu