Sitemap / Advertise

Introduction

Get informed when new episodes of your favorite shows are on release with their opening songs via Nano 33 IoT and Raspberry Pi.


Tags

Share

TV Series / Anime New Episode Release Date Notifier

Advertisement:


read_later

Read Later



read_later

Read Later

Introduction

Get informed when new episodes of your favorite shows are on release with their opening songs via Nano 33 IoT and Raspberry Pi.

Tags

Share





Advertisement

Advertisement




    Components :
  • [1]JLCPCB Custom PCB
  • [1]Arduino Nano 33 IoT
  • [1]Raspberry Pi Model 3 B+
  • [1]Nokia 5110 Screen Module
  • [1]Serial MP3 Player Module (OPEN-SMART)
  • [1]5mm Anode RGB LED
  • [2]Micro SD Card
  • [12]220Ω Resistor
  • [4]Button
  • [1]Power Jack

Description

Although there are myriads of web and mobile applications to track release dates of favorite shows, I wanted to create a device that notifies me when a new episode of a series or an anime in my list is on release from scratch - hardware and software - with various features.

First of all, I created a web application - TV Series / Anime Release Date Tracker - in PHP to create a series/anime list and gather information about their release dates. In that regard, I utilized the TVMAZE REST API that allows the application to obtain episode information by release date precisely, albeit without miscellaneous and perplexing coding steps. Then, I set up a LAMP (w/ MariaDB) server on Raspberry Pi to run the application. But, for those who do not have a Raspberry Pi nor want to use one as the host, I published a free version of the application with a user-friendly interface on my website. Also, you can find the source code of the application below.

After fulfilling transferring information with the web application, if there is a new episode on release, I decided to use an Arduino Nano 33 IoT as the development board to collate data generated by the application. You can find more information below on how I sorted out the response transferred by the application by using a delimiter. And, to manage features and modes I implemented on the Nano 33 IoT, I designed a user interface (menu) with a Nokia 5110 Screen and pushbuttons.

Lastly, to get informed when a new episode of a show in my list on release with its opening song, I used a Serial MP3 Player Module (OPEN-SMART) due to its simple-to-use UART command list. Furthermore, it let me add the MP3 Player mode to play all opening songs, which turned the device to an intriguing accessory for my room :)

After completing my design on a breadboard and testing the code, I designed a PCB (TV Series / Anime Release Date Notifier) with a unique retro telephone shape to create a brand-new looking and easy-to-use device.

Huge thanks to JLCPCB for sponsoring this project.

project-image
Figure - 50.1

Step 1: Designing and Soldering the TV Series / Anime Release Date Notifier PCB

I designed the TV Series / Anime Release Date Notifier PCB by using KiCad. I attached the Gerber file of the PCB below, so if you want, you can order this PCB from JLCPCB to replicate this project to get notified when there are new episodes of your favorite shows on release :)

project-image
Figure - 50.2

First of all, by using a soldering iron, I attached headers, pushbuttons, 220Ω resistors, the power jack, 5mm Anode RGB LED.

Component list on the PCB:

A1 (Headers for Arduino Nano 33 IoT)

J1 (Headers for Serial MP3 Player)

J2 (Headers for DS3231 - Not Required)

J3 (Headers for Nokia 5110 Screen)

J4 (Power Jack)

D1 (5mm Anode RGB LED)

K1, K2, K3, K4 (Pushbuttons)

R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12 (220Ω resistors)

project-image
Figure - 50.3


project-image
Figure - 50.4


project-image
Figure - 50.5

Step 2: Setting up a LAMP web server with MariaDB on Raspberry Pi

If you are a novice in programming with Raspberry Pi, you can inspect well-explained instructions and tutorials on the official Raspberry Pi website.

To go to the official Raspberry Pi setting up tutorial, click here.

project-image
Figure - 50.6

- Open a terminal window by selecting Accessories > Terminal from the menu.

- Install the apache2 package by typing the following command into the terminal and pressing Enter:

sudo apt-get install apache2 -y

project-image
Figure - 50.7

- To test the server, open Chromium by selecting Internet > Chromium Web Browser from the menu and enter http://localhost.

- If you want, you can use the IP address of your Raspberry Pi as well.

hostname -I

project-image
Figure - 50.8


project-image
Figure - 50.9

- Install the PHP package with the following command:

- Do not forget to update the Pi.

sudo apt-get update

sudo apt-get install php -y

project-image
Figure - 50.10

- Install the MySQL Server (MariaDB) and PHP-MySQL packages by entering the following command into the terminal window:

sudo apt-get install mariadb-server php-mysql -y

project-image
Figure - 50.11

- To create a new user, run the MySQL secure installation command in the terminal window.

sudo mysql_secure_installation

- You will be asked Enter current password for root (enter for none): — press Enter.

- Type in Y and press Enter to Set root password.

- Type in bot at the New password: prompt, and press Enter.

- Type in Y to Remove anonymous users.

- Type in Y to Disallow root login remotely.

- Type in Y to Remove test database and access to it.

- Type in Y to Reload privilege tables now.

- When completed, you will see this message - All done! and Thanks for using MariaDB!

project-image
Figure - 50.12

- To create a database (tvseries) to save variables generated by TVMAZE REST API, run this MySQL command in the terminal window:

sudo mysql -uroot -p

- Enter the root password - bot

- You will be greeted by the message Welcome to the MariaDB monitor.

- Follow the lines below after the MariaDB [(none)]>: prompt to create the tvseries database in MariaDB:

create database tvseries;

GRANT ALL PRIVILEGES ON tvseries.* TO 'root'@'localhost' IDENTIFIED BY 'bot';

FLUSH PRIVILEGES;

- Exit the MariaDB prompt with Ctrl + D.

project-image
Figure - 50.13

- To obtain data from TVMAZE REST API by merely using the file_get_contents() function in PHP, install the php-curl package:

sudo apt-get install php-curl

project-image
Figure - 50.14

- Then, restart the apache server to be able to use the installed packages on the localhost:

sudo service apache2 restart

Step 3: Getting information from TVMAZE REST API on your favorite series/anime

TVMAZE provides a free and easy-to-use REST API, which allows users to search shows by name, date, episode number, etc. You can inspect the available endpoints and queries:

Go to TVMAZE REST API.

project-image
Figure - 50.15

I used the Episode by Date option to retrieve all episodes from a given show that have aired on a specific date.

To be able to obtain information by release dates, you need to search your favorite shows on TVMAZE and use the TV ID indicated in their links.

- URL: /shows/:id/episodesbydate?date=:date

- Date: ISO 8601 format

- Example: http://api.tvmaze.com/shows/1/episodesbydate?date=2013-07-01

project-image
Figure - 50.16

If there is an episode aired on the given date, the API returns an array of full episode info.

project-image
Figure - 50.17

Otherwise, the API returns an HTTP 404.

project-image
Figure - 50.18

Below, you can inspect my favorite series/anime list I created to track whether there is a new episode of one of them that is on release with my project.

I added The Late Late Show to test my code since it is a daily show.

1) One Piece

TV ID: 1505

https://www.tvmaze.com/shows/1505/one-piece

project-image
Figure - 50.19

2) My Hero Academia

TV ID: 13615

https://www.tvmaze.com/shows/13615/boku-no-hero-academia

project-image
Figure - 50.20

3) Westworld

TV ID: 1371

https://www.tvmaze.com/shows/1371/westworld

project-image
Figure - 50.21

4) The Simpsons

TV ID: 83

https://www.tvmaze.com/shows/83/the-simpsons

project-image
Figure - 50.22

5) The Late Late Show with James Corden

TV ID: 2831

https://www.tvmaze.com/shows/2831/the-late-late-show-with-james-corden

project-image
Figure - 50.23

Step 4: Developing the TV Series / Anime Release Date Tracker (application) running on Raspberry Pi in PHP and creating the series table to insert data

I developed the TV Series / Anime Release Date Tracker in PHP and explained the source code of the application in the Code Explanation section below for those who are interested.

However, if you are not fond of web development with PHP, you can download the application in Downloads - named TV-Series-Anime-Episode-Tracker.zip - and upload it to Raspberry Pi without diving in PHP coding.

Upload:

By the following steps, install the TV Series / Anime Release Date Tracker on the localhost:

- Download the application - TV-Series-Anime-Episode-Tracker.zip - including index.php and query.php files.

project-image
Figure - 50.24

- Extract the TV-Series-Anime-Episode-Tracker.zip.

project-image
Figure - 50.25

- Move the application folder (TV-Series-Anime-Episode-Tracker) from Downloads to the server (/var/www/html) by using the terminal since the apache server is a protected location.

sudo mv /home/pi/Downloads/TV-Series-Anime-Episode-Tracker/ /var/www/html/

project-image
Figure - 50.26

- Go to the TV Series / Anime Release Date Tracker:

http://localhost/TV-Series-Anime-Episode-Tracker/

Features:

1) After installation, open the application to create a table named series in the database (tvseries). When you first open the index.php file, the application creates the table named series automatically and informs the user - Database Table Created!

project-image
Figure - 50.27

2) If the database table (series) is created successfully in the database, the application informs the user - Database Table Found!

project-image
Figure - 50.28

3) After creating the database table (series), to insert variables required for TVMAZE REST API for each show in your list, take the following steps:

- Run this MySQL command in the terminal window:

sudo mysql -uroot -p

- Enter the root password - bot

- Select the tvseries database:

USE tvseries;

- Insert required variables - series name, TV ID, status - to the table for each show. The status variable is used by the application to notify the user without recurring when a new episode is on release on a given date.

INSERT INTO `series` (`series_name`, `tv_id`, `status`) VALUES ('One Piece', '1505', 'Pending');

project-image
Figure - 50.29

5) On the query.php, the application makes requests to TVMAZE REST API to detect whether new episodes of shows in the database are on release. If TVMAZE REST API returns an array of full episode info of a released episode, the application prints information collatable by Arduino Nano 33 IoT for once to prevent a recurrence.

http://localhost/TV-Series-Anime-Episode-Tracker/query.php

%Series_Name%Season%Episode_Number%Episode_Name%

%The Late Late Show%2020%91%Jason Schwartzman, Alicia Key%

project-image
Figure - 50.30

6) Otherwise, the application prints No Entry Found!

project-image
Figure - 50.31

Code Explanation:

1) index.php

- Define the database connection settings - "localhost", "root", "bot", "tvseries".

- In the checkDatabase() function, detect whether there is a database table in the given name - series.

- In the createTable() function, create the series table if not found in the database and inform the user.

project-image
Figure - 50.32

2) query.php

- In the query class, define the path to TVMAZE API to make requests.

- In the define_user() function, get connection settings and the table name.

- In the check_ep_release_date() function, using the file_get_contents() function, detect whether a new episode is on release for a given TV ID on the current date. Change the status variable in the database from Pending to Released if a new episode is on release to prevent a recurrence.

- In the track_db_entries() function, execute the check_ep_release_date() for each show registered in the database table - series.

project-image
Figure - 50.33


project-image
Figure - 50.34

Step 4.1: Executing web application without Raspberry Pi

For subscribers to my website (TheAmplituhedron), I developed a free version of the TV Series / Anime Release Date Tracker for those who do not have a Raspberry Pi nor want to use one as a host for this project.

It provides a user-friendly interface for managing the database. If you want to use this interface with your project instead of using the terminal on Raspberry Pi to insert data, please contact me.

Go to the application:

https://www.theamplituhedron.com/dashboard/TV-Series-Anime-Episode-Tracker/

project-image
Figure - 50.35

Step 5: Setting up Arduino Nano 33 IoT

If you are a novice in programming with Arduino Nano 33 IoT: do not worry, it is simple to use with Arduino IDE. Just download the required drivers - Arduino SAMD Core - as well-explained here.

project-image
Figure - 50.36

To be able to connect to the WiFi via Arduino Nano 33 IoT, download the WiFiNINA library from here.

project-image
Figure - 50.37

To print text and draw graphics on the Nokia 5110 Screen, download the LCD5110_Basic library from here.

I used the second serial port (Serial1) on the Arduino Nano 33 IoT to communicate with the Serial MP3 Player.

Serial Ports on the Arduino Nano 33 IoT:

"The USB connector of the board is directly connected to the USB host pins of the SAMD21. This routing enables you to use the Arduino NANO 33 IoT as a client USB peripheral (acting as a mouse or a keyboard connected to the computer) or as a USB host device so that devices like a mouse, keyboard, or an Android phone can be connected to the Arduino NANO 33 IoT. This port can also be used as a virtual serial port using the Serial object in the Arduino programming language. The RX0 and TX1 pins are a second serial port available as Serial1."

Then, Arduino Nano 33 IoT is ready to execute the project code :)

Step 6: Sending commands to the Serial MP3 Player (OPEN-SMART)

I created a playlist consisting of opening songs of my favorite series/anime list in this project:

1) One Piece - Opening | Listen

2) My Hero Academia - Opening | Listen

3) Westworld - Opening | Listen

4) The Simpsons - Opening | Listen

5) The Late Late Show - Opening | Listen

If you want, you can download my playlist in a zipped folder - opening_songs.zip.

It is effortless to use a Serial MP3 Player with Arduino Nano 33 IoT as long as you know the UART commands required to trigger the right functions. I used a Serial MP3 Player module with Speaker by OPEN-SMART. So, if you have a Serial MP3 Player with a different brand name, these commands shown below will not work for you.

Follow the instructions from the guidance:

"The module is a kind of simple MP3 player device which is based on a high-quality MP3 audio chip. It can support 8k Hz ~ 48k Hz sampling frequency MP3 and WAV file formats. There is a TF card socket on board, so you can plug the micro SD card that stores audio files. MCU can control the MP3 playback state by sending commands to the module via UART port, such as switch songs, change the volume and play mode, and so on. You can also debug the module via USB to UART module. It is compatible with Arduino / AVR / ARM / PIC."

"Make sure your micro SD card is formatted as FAT16 or FAT32 and there are some songs in it. You should create folders “01” and “02”, and put some songs with the name 001xxx.mp3 / 002xxx.mp3 / 003xxx.mp3 in them."

In other words, to be able to execute commands accurately, save your songs in a folder named as '01' and add consecutive numbers to song names - 001One Piece-Opening.mp3, 002My Hero Academia-Opening.mp3, etc.

project-image
Figure - 50.38

To send UART commands to the Serial MP3 Player with Arduino Nano 33 IoT, I created a function named as send_command_to_MP3_player. It transfers each byte in the requested command to the Serial MP3 Player via the second serial port on RX0 and TX1 pins - Serial1 - depending on the length of the requested command - 4, 5, or 6.

As shown below, separate the command you want to send to the Serial MP3 Player by bytes - 0x7e. All commands start with '7E' and end with 'EF'. The second byte is the number of the bytes in between - '02', '03', '04'. Below, download the Serial MP3 Player manual by OPEN-SMART to inspect all commands and get more detailed instructions.


// Define the required MP3 Player Commands.
// You can inspect all given commands from the project page: 
// Select storage device to TF card
static int8_t select_SD_card[] = {0x7e, 0x03, 0X35, 0x01, 0xef}; // 7E 03 35 01 EF
// Play the song with the directory: /01/001xxx.mp3
static int8_t play_song_1[] = {0x7e, 0x04, 0x41, 0x00, 0x01, 0xef}; // 7E 04 41 00 01 EF
// Play the song with the directory: /01/002xxx.mp3
static int8_t play_song_2[] = {0x7e, 0x04, 0x41, 0x00, 0x02, 0xef}; // 7E 04 41 00 02 EF
// Play the song with the directory: /01/003xxx.mp3
static int8_t play_song_3[] = {0x7e, 0x04, 0x41, 0x00, 0x03, 0xef}; // 7E 04 41 00 03 EF
// Play the song with the directory: /01/004xxx.mp3
static int8_t play_song_4[] = {0x7e, 0x04, 0x41, 0x00, 0x04, 0xef}; // 7E 04 41 00 04 EF
// Play the song with the directory: /01/005xxx.mp3
static int8_t play_song_5[] = {0x7e, 0x04, 0x41, 0x00, 0x05, 0xef}; // 7E 04 41 00 05 EF
// Play the song.
static int8_t play[] = {0x7e, 0x02, 0x01, 0xef}; // 7E 02 01 EF
// Pause the song.
static int8_t pause[] = {0x7e, 0x02, 0x02, 0xef}; // 7E 02 02 EF
// Next song.
static int8_t next_song[] = {0x7e, 0x02, 0x03, 0xef}; // 7E 02 03 EF
// Previous song.
static int8_t previous_song[] = {0x7e, 0x02, 0x04, 0xef}; // 7E 02 04 EF

project-image
Figure - 50.39

Step 7: Programming Arduino Nano 33 IoT

- Include the required libraries.

- Define your WiFi settings - SSID and password.

- Enter the IPAddress of your Raspberry Pi.

- Define the pathway of the application (query.php) in Raspberry Pi.

- Initialize the Ethernet client library.

- Define the Nokia 5110 screen settings.

- Define the graphics for related screen modes - tv and music.

- To create different graphics (monochrome images), go to Monochrome Image Converter.

- Define the required MP3 Player Commands.

- Define menu options and modes using volatile booleans.

- Define the control buttons and RGB LED pins.

- Initiate serial communication for the Serial MP3 Player Module on the second serial port - Serial1.

- Connect to the WiFi network.

- Verify connection on both the serial monitor and Nokia 5110 Screen.

- In the read_buttons() function, get data from the control buttons - Right, OK, Left, and Exit.

- In the change_menu_options(), increase or decrease the option number using the Right and Left buttons.

- In the interface() function, print the interface (menu).

- If the Init Tracker mode is selected, connect to the web application named TV Series / Anime Release Date Tracker.

- If there are incoming bytes available, get the response from the web application.

- Using the endsWith() function, detect whether the response has the percentage symbol (delimiter) in it or not.

- If included, split the response string by a predefined delimiter in a simple way. '%'(percentage) is defined as the delimiter in this project.

- Glean information as substrings - Series_Name, Season, Episode, Episode_Name.

- Print information and play the opening song of the released series/anime until ceased.

- Wait until the Exit button is pressed.

- If there is a blank response, print No Released Episode Detected :(

- Draw the TV icon while counting to the new request.

- Wait until the next request.

- If the MP3 Player mode is selected, draw the music player icon. Control the MP3 Player with the control buttons - Right, Left, OK.

- If the Sleep mode is selected, activate the sleep mode in 10 seconds and print the remaining seconds.

project-image
Figure - 50.40


project-image
Figure - 50.41


project-image
Figure - 50.42


project-image
Figure - 50.43


project-image
Figure - 50.44


project-image
Figure - 50.45


project-image
Figure - 50.46

Connections and Adjustments


// Connections
// Arduino Nano 33 IoT:           
//                               Nokia 5110 Screen
// D2  -------------------------- SCK (Clk)
// D3  -------------------------- MOSI (Din) 
// D4  -------------------------- DC 
// D5  -------------------------- RST
// D6  -------------------------- CS (CE)
//                               RGB
// D9  -------------------------- R
// D10 -------------------------- G
// D11 -------------------------- B
//                               LEFT_BUTTON
// A0 --------------------------- S
//                               OK_BUTTON
// A1 --------------------------- S
//                               RIGHT_BUTTON
// A2 --------------------------- S
//                               EXIT_BUTTON
// A3 --------------------------- S
//                               DS3231 (Optional for Nano and Not Required for Nano 33 IoT)
// A4 --------------------------- SDA  
// A5 --------------------------- SCL

After finishing and uploading the code to the Arduino Nano 33 IoT, I attached all required components to the board via headers.

I also provided a connection slot for a DS3231 RTC Module for those who want to change the Arduino Nano 33 IoT with the Arduino Nano. But, you need to enter release dates manually for each show to the Arduino Nano without being able to obtain data from the web application to create a countdown timer with the RTC.

project-image
Figure - 50.47

Note: You can connect either a speaker or headphones to the Serial MP3 Player to listen to soundtracks in the playlist. I connected the speaker delivered in addition to the Serial MP3 Player (OPEN-SMART).

project-image
Figure - 50.48


project-image
Figure - 50.49

Modes and Features

1) While the device tries to connect to the WiFi network, it displays Waiting... Attempting to connect to WiFi.

project-image
Figure - 50.50

2) After establishing a successful connection, the device informs the user with this message - Connected to WiFi!!!

project-image
Figure - 50.51

3) Then, the device prints the interface (menu) presenting available modes - A.Init Tracker, B.MP3 Player, and C.Sleep. To switch among modes, use the Right and Left buttons. Subsequently, press the OK button to select a mode.

project-image
Figure - 50.52

A.Init Tracker

A.1) After selecting the A.Init Tracker mode, the device attempts to connect to the localhost hosted by the Raspberry Pi. If successful, it informs the user with this message - Connected to the server!!! Conversely, the device displays this message - Connection Error!!!

project-image
Figure - 50.53


project-image
Figure - 50.54

A.2) If the application (TV Series / Anime Release Date Tracker) sends a data string that of a released episode of a registered series/anime in the database, then the device:

- Prints the episode information - Series Name, Season, Episode Number, and Episode Name:

One Piece, 10x54, Luffy's Determination

- Plays the opening song of the released series/anime,

- And, turns the RGB to the color assigned to the released series/anime.

For instance, I assigned these colors below for each show in my list:

- One Piece -> Red

- My Hero Academia -> Green

- Westworld -> Blue

- The Simpsons -> Yellow

- The Late Late Show -> Purple

Unless the Exit button is pressed, the device keeps displaying the episode information and showing the assigned color.

The device notifies the user for once for each released episode to prevent any recurrence.

project-image
Figure - 50.55

A.3) After the Exit button is pressed, the device draws the television icon while waiting for the next request to the application.

project-image
Figure - 50.56

A.4) If there is no released episode of a registered series/anime in the database, the device displays this message - No Released Episode Detected :( - and then; draws the television icon until the next request to the application.

project-image
Figure - 50.57


project-image
Figure - 50.58

A.5) The device returns to the interface (menu) if the Exit button is pressed while displaying the television icon.

B. MP3 Player

I implemented this feature as a subsidiary and fun one to turn this device into an intriguing accessory for my room.

B.1) After selecting the B.MP3 Player mode, the device draws the music note icon and lets the user play all opening songs by using the control buttons:

- Right - Next Song

- Left - Previous Song

- OK - Pause

B.2) The device returns to the interface (menu) if the Exit button is pressed.

project-image
Figure - 50.59


project-image
Figure - 50.60

C.Sleep

C.1) After selecting the C.Sleep mode, the device enables the sleep mode in 10 seconds and prints the remaining seconds on the screen.

project-image
Figure - 50.61


project-image
Figure - 50.62

C.2) While maintaining the sleep mode, the device applies a given color pattern to the RGB as a nightlight.

project-image
Figure - 50.63


project-image
Figure - 50.64

C.3) The device returns to the interface (menu) if the Exit button is pressed.

Videos and Conclusion

After completing all steps above, I decided to fasten the device to my bookcase by using a hot glue gun. It works stupendously :)

project-image
Figure - 50.65


project-image
Figure - 50.66

Code

Series_Release_Date_Notifier.ino

Download




         ////////////////////////////////////////////////////  
        //        TV Series / Anime New Episode           //
       //             Release Date Notifier              //
      //           -------------------------            //
     //              Arduino Nano 33 IoT               //           
    //               by Kutluhan Aktar                // 
   //                                                //
  ////////////////////////////////////////////////////

// Get informed when new episodes of your favorite shows are on release with their opening songs via Nano 33 IoT and Raspberry Pi. 
//
// I developed a corroborating web application in PHP for this project, named TV Series / Anime Release Date Tracker. 
// You can either use a Raspberry Pi as the server, explained in the project tutorial, or TheAmplituhedron with the real-time database interface if you are a member. 
//
// For more information:
// https://www.theamplituhedron.com/projects/TV-Series-Anime-New-Episode-Release-Date-Notifier/
// 
// You can use the mentioned web application in free version on TheAmplituhedron as the host server if you are a subscriber:
// https://www.theamplituhedron.com/dashboard/TV-Series-Anime-Episode-Tracker/
//
// Connections
// Arduino Nano 33 IoT:           
//                                Nokia 5110 Screen
// D2  --------------------------- SCK (Clk)
// D3  --------------------------- MOSI (Din) 
// D4  --------------------------- DC 
// D5  --------------------------- RST
// D6  --------------------------- CS (CE)
//                                RGB
// D9  --------------------------- R
// D10 --------------------------- G
// D11 --------------------------- B
//                                LEFT_BUTTON
// A0 --------------------------- S
//                                OK_BUTTON
// A1 --------------------------- S
//                                RIGHT_BUTTON
// A2 --------------------------- S
//                                EXIT_BUTTON
// A3 --------------------------- S
//                               DS3231 (Optional for Nano and Not Required for Nano 33 IoT)
// A4 --------------------------- SDA  
// A5 --------------------------- SCL



// Include required libraries:
#include <SPI.h>
#include <WiFiNINA.h>
#include <LCD5110_Basic.h>


char ssid[] = "[_SSID_]";        // your network SSID (name)
char pass[] = "[_PASSWORD_]";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;                // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

// Note: Uncomment equivalent connection settings provided under related lines for using the web application hosted on TheAmplituhedron if you are a subscriber.

// Enter the IPAddress of your Raspberry Pi.
IPAddress server(192, 168, 1, 22);
/* 
// name address for TheAmplituhedron. Change it with your server if you are using a different host server than TheAmplituhedron.
char server[] = "www.theamplituhedron.com";
*/

// Define the pathway of the application in Raspberry Pi.
String application = "/TV-Series-Anime-Episode-Tracker/query.php";
/*
// Define your hedron if you are using TheAmplituhedron as the host server for this project:
String HEDRON = "[_HEDRON_]";
// Define the pathway of the web application. If you are using TheAmplituhedron as the host server for this project as I did, just enter your hedron. Otherwise, enter the pathway on your server.
String application = "/dashboard/TV-Series-Anime-Episode-Tracker/" + HEDRON;
*/

// Initialize the Ethernet client library
WiFiClient client;
/* WiFiSSLClient client; */

// Define screen settings.
LCD5110 myGLCD(2,3,4,5,6);

extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
// Define the graphics for related screen modes.
extern uint8_t tv[];
extern uint8_t music[];

// Define the required MP3 Player Commands.
// You can inspect all given commands from the project page: 
// Select storage device to TF card
static int8_t select_SD_card[] = {0x7e, 0x03, 0X35, 0x01, 0xef}; // 7E 03 35 01 EF
// Play the song with the directory: /01/001xxx.mp3
static int8_t play_song_1[] = {0x7e, 0x04, 0x41, 0x00, 0x01, 0xef}; // 7E 04 41 00 01 EF
// Play the song with the directory: /01/002xxx.mp3
static int8_t play_song_2[] = {0x7e, 0x04, 0x41, 0x00, 0x02, 0xef}; // 7E 04 41 00 02 EF
// Play the song with the directory: /01/003xxx.mp3
static int8_t play_song_3[] = {0x7e, 0x04, 0x41, 0x00, 0x03, 0xef}; // 7E 04 41 00 03 EF
// Play the song with the directory: /01/004xxx.mp3
static int8_t play_song_4[] = {0x7e, 0x04, 0x41, 0x00, 0x04, 0xef}; // 7E 04 41 00 04 EF
// Play the song with the directory: /01/005xxx.mp3
static int8_t play_song_5[] = {0x7e, 0x04, 0x41, 0x00, 0x05, 0xef}; // 7E 04 41 00 05 EF
// Play the song.
static int8_t play[] = {0x7e, 0x02, 0x01, 0xef}; // 7E 02 01 EF
// Pause the song.
static int8_t pause[] = {0x7e, 0x02, 0x02, 0xef}; // 7E 02 02 EF
// Next song.
static int8_t next_song[] = {0x7e, 0x02, 0x03, 0xef}; // 7E 02 03 EF
// Previous song.
static int8_t previous_song[] = {0x7e, 0x02, 0x04, 0xef}; // 7E 02 04 EF

// Define menu options and modes using volatile booleans.
volatile boolean TV = false;
volatile boolean Music = false;
volatile boolean Sleep = false;
volatile boolean Activated = false;

// Define the control buttons.
#define B_Exit A3
#define B_Right A2
#define B_OK A1
#define B_Left A0

// Define RGB LED pins.
#define redPin 9
#define greenPin 10
#define bluePin 11

// Define data holders:
int Right, OK, Left, Exit;
int selected = 0;

void setup() {
  // Buttons:
  pinMode(B_Exit, INPUT);
  pinMode(B_Right, INPUT);
  pinMode(B_OK, INPUT);
  pinMode(B_Left, INPUT);
  // RGB:
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  adjustColor(0, 0, 0); // Black
  
  // Initiate screen.
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  Serial.begin(9600);

  // Initiate serial communication for the Serial MP3 Player Module.
  Serial1.begin(9600);

  // Select the SD Card.
  send_command_to_MP3_player(select_SD_card, 5);
  
  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); myGLCD.print("Connection Failed!", 0, 8); while (true); }
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    myGLCD.print("Waiting...", 0, 8);
    myGLCD.print("Attempting to", 0, 16);
    myGLCD.print("connect to", 0, 24);
    myGLCD.print("WiFi !!!", 0, 32);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }

  // Verify connection on both the serial monitor and Nokia 5110 Screen.
  Serial.println("Connected to wifi");
  myGLCD.clrScr();
  myGLCD.print("Connected to", 0, 8);
  myGLCD.print("WiFi!!!", 0, 16);
  delay(2000);
  myGLCD.clrScr();
}

void loop() {

    read_buttons();
  
    change_menu_options();

    interface();

    if(TV == true){
      do{
        myGLCD.invertText(true);
        myGLCD.print("A.Init Tracker", 0, 16);
        myGLCD.invertText(false);
        delay(100);
        if(OK == HIGH){
          myGLCD.clrScr();
          Activated = true;
          while(Activated == true){
            // Connect to the web application named TV Series / Anime Release Date Tracker. Change '80' with '443' if you are using TheAmplituhedron as the host.
            if (client.connect(server, 80)) {
              Serial.println("connected to server"); // if you get a connection, report back via serial:
              myGLCD.print("Connected to", 0, 8);
              myGLCD.print("the server!!!", 0, 16);
              // Make an HTTP request:
              client.println("GET " + application + " HTTP/1.1");
              //client.println("Host: www.theamplituhedron.com");
              client.println("Host: 192.168.1.22");
              client.println("Connection: close");
              client.println();
            }else{
              myGLCD.print("Connection", 0, 8);
              myGLCD.print("Error!!!", 0, 16);
            }
            delay(2000); // Wait 2 seconds after connection...
            // If there are incoming bytes available, get the response from the web application.
            String response = "";
            while (client.available()) { char c = client.read(); response += c; }
            if(response != "" && response.endsWith("%")){
              // Split the response string by a pre-defined delimiter in a simple way. '%'(percentage) is defined as the delimiter in this project.
              int delimiter, delimiter_1, delimiter_2, delimiter_3, delimiter_4;
              delimiter = response.indexOf("%");
              delimiter_1 = response.indexOf("%", delimiter + 1);
              delimiter_2 = response.indexOf("%", delimiter_1 +1);
              delimiter_3 = response.indexOf("%", delimiter_2 +1);
              delimiter_4 = response.indexOf("%", delimiter_3 +1);
              // Glean information as substrings.
              String Series_Name = response.substring(delimiter + 1, delimiter_1);
              String Season = response.substring(delimiter_1 + 1, delimiter_2);
              String Episode = response.substring(delimiter_2 + 1, delimiter_3);
              String Episode_Name = response.substring(delimiter_3 + 1, delimiter_4);
              // Print information.
              myGLCD.clrScr();
              myGLCD.print(Series_Name, 0, 0);
              myGLCD.print(Season + " x " + Episode, 0, 16);
              myGLCD.print(Episode_Name, 0, 32);
              // Play the opening song of the released series / anime until ceased:
              if(Series_Name == "One Piece") { send_command_to_MP3_player(play_song_1, 6); adjustColor(255,0,0); }
              if(Series_Name == "My Hero Academia") { send_command_to_MP3_player(play_song_2, 6); adjustColor(0,255,0); }
              if(Series_Name == "Westworld") { send_command_to_MP3_player(play_song_3, 6); adjustColor(0,0,255); }
              if(Series_Name == "The Simpsons") { send_command_to_MP3_player(play_song_4, 6); adjustColor(255,255,0); }
              if(Series_Name == "The Late Late Show") { send_command_to_MP3_player(play_song_5, 6); adjustColor(80,0,80); }
              // Wait until the Exit button pressed...
              volatile boolean song = true;
              while(song == true){
                read_buttons();
                if(Exit == HIGH){ song = false; send_command_to_MP3_player(pause, 4); adjustColor(0,0,0); }
              }
              myGLCD.clrScr();
            }else{
              // Print information.
              myGLCD.clrScr();
              myGLCD.print("No Released", 0, 0);
              myGLCD.print("Episode", 0, 16);
              myGLCD.print("Detected :(", 0, 32);
              delay(5000); // Wait 5 seconds to display information...
              myGLCD.clrScr();
            }
            // Draw TV icon while counting to the new request...
            myGLCD.drawBitmap(8, 0, tv, 60, 48);
            delay(10 * 1000); // Wait until next request...
            myGLCD.clrScr();
            // Exit.
            read_buttons();
            if(Exit == HIGH){ Activated = false; myGLCD.clrScr(); }
          }
        }
      }while(TV == false);
    }

    if(Music == true){
      do{
        myGLCD.invertText(true);
        myGLCD.print("B.MP3 Player", 0, 24);
        myGLCD.invertText(false);
        delay(100);
        if(OK == HIGH){
          myGLCD.clrScr();
          Activated = true;
          while(Activated == true){
            read_buttons();
            // Draw music player icon.
            myGLCD.drawBitmap(8, 0, music, 60, 48);
            // MP3 Player:
            if(Right == true) send_command_to_MP3_player(next_song, 4);
            if(Left == true) send_command_to_MP3_player(previous_song, 4);
            if(OK == true) send_command_to_MP3_player(pause, 4);
            // Exit.
            if(Exit == HIGH){ Activated = false; myGLCD.clrScr(); send_command_to_MP3_player(pause, 4); }
          }
        }
      }while(Music == false);
    }

    if(Sleep == true){
      do{
        myGLCD.invertText(true);
        myGLCD.print("C.Sleep", 0, 32);
        myGLCD.invertText(false);
        delay(100);
        if(OK == HIGH){
          // Activate the sleep mode in 10 seconds.
          myGLCD.clrScr();
          myGLCD.print("Entering", CENTER, 0);
          myGLCD.print("Sleep Mode", CENTER, 8);
          myGLCD.print("in", CENTER, 16);
          myGLCD.print("Seconds", CENTER, 40);
          // Print remaining seconds.
          myGLCD.setFont(MediumNumbers);
          for (int s=10; s>=0; s--){ myGLCD.printNumI(s, CENTER, 24, 2, '0'); delay(1000); }
          myGLCD.enableSleep();
          Activated = true;
          while(Activated == true){
            // Color Pattern:
            adjustColor(255,0,0);
            delay(500);
            adjustColor(0,255,0);
            delay(500);
            adjustColor(0,0,255);
            delay(500);
            adjustColor(255,255,0);
            delay(500);
            adjustColor(80,0,80);
            delay(500);
            // Exit.
            read_buttons();
            if(Exit == HIGH){ Activated = false; myGLCD.clrScr(); myGLCD.disableSleep(); myGLCD.setFont(SmallFont); adjustColor(0,0,0); }
          }
        }
      }while(Sleep == false);
    }

}

void read_buttons(){
  // Read the control buttons:
  Right = digitalRead(B_Right);
  OK = digitalRead(B_OK);
  Left = digitalRead(B_Left);
  Exit = digitalRead(B_Exit);
}

void send_command_to_MP3_player(int8_t command[], int len){
  Serial.print("\nMP3 Command => ");
  for(int i=0;i<len;i++){ Serial1.write(command[i]); Serial.print(command[i], HEX); }
  delay(1000);
}

void interface(){
   // Define options.
   myGLCD.print("Menu Options :", 0, 0);
   myGLCD.print("A.Init Tracker", 0, 16);
   myGLCD.print("B.MP3 Player", 0, 24);
   myGLCD.print("C.Sleep", 0, 32);
}

void change_menu_options(){
  // Increase or decrease the option number using Right and Left buttons.
  if(Right == true) selected++;
  if(Left == true) selected--;
  if(selected < 0) selected = 3;
  if(selected > 3) selected = 1;
  delay(100);
  // Depending on the selected option number, change boolean status.
  switch(selected){
    case 1:
      TV = true;
      Music = false;
      Sleep = false;
    break;
    case 2:     
      TV = false;
      Music = true;
      Sleep = false;
    break;
    case 3:
      TV = false;
      Music = false;
      Sleep = true;
    break;
  }
}

void adjustColor(int red, int green, int blue){
 red = 255 - red;
 green = 255 - green;
 blue = 255 - blue;
 analogWrite(redPin, red);
 analogWrite(greenPin, green);
 analogWrite(bluePin, blue);
}


index.php

Download



<?php

$conn_database = mysqli_connect("localhost", "root", "bot", "tvseries");

function checkDatabase($table, $conn){
		$sql = "SHOW TABLES FROM `tvseries` LIKE '$table'";
	    $check = mysqli_num_rows(mysqli_query($conn, $sql));
		return ($check > 0) ? true : false;
}

function createTable($table_name, $conn){
	if(!checkDatabase($table_name, $conn)){
		$sql = "CREATE TABLE `$table_name`(
		id int(11) AUTO_INCREMENT PRIMARY KEY NOT NULL,
		series_name varchar(255) NOT NULL,
		tv_id varchar(255) NOT NULL,
		status varchar(255) NOT NULL
	    );";
			
		if(mysqli_query($conn, $sql)){
			echo "Database Table Created!";
		}else{
			echo "Error!";
		}
	}else{
		echo "Database Table Found!";
	}
}

createTable("series", $conn_database);

?>


query.php

Download



<?php

error_reporting(0);

class query{
	
	const ROOT = "https://api.tvmaze.com/shows/";
	const PATH = "/episodesbydate?date=";
	
	public $conn, $table_name;
	
	public function define_user($conn, $table_name){
		$this->conn = $conn;
		$this->table_name = $table_name;
	}
	
	private function check_ep_release_date($API_ID, $series_name, $status){
		$date = date("Y-m-d");
		$URL = self::ROOT.$API_ID.self::PATH.$date;
		
		if($get_content = json_decode(file_get_contents((String)$URL))){
			if($status != "Released"){
				echo "%".$series_name."%".$get_content[0]->season."%".$get_content[0]->number."%".$get_content[0]->name."%";
				$sql = "UPDATE `$this->table_name` SET `status`='Released' WHERE series_name='$series_name'";
				mysqli_query($this->conn, $sql);
			}
		}else{
			if($status != "Pending"){
				$sql = "UPDATE `$this->table_name` SET `status`='Pending' WHERE series_name='$series_name'";
				mysqli_query($this->conn, $sql);
			}
		}
	}
	
	public function track_db_entries(){
		$sql = "SELECT * FROM `$this->table_name` ORDER BY `id` DESC";
		if($result = mysqli_query($this->conn, $sql)){
			$check = mysqli_num_rows($result);
			if($check > 0){
				while($row = mysqli_fetch_assoc($result)){
					$this->check_ep_release_date($row['tv_id'], $row['series_name'], $row['status']);
				}
			}else{
				echo "No Entry Found!";
			}
		}else{
			echo "No Database Found!";
		}
	}
}

// Define the connection settings and the table name.
$conn_database = mysqli_connect("localhost", "root", "bot", "tvseries");
$table = "series";

// Define the object to check release date for each registered series / anime.
$q = new query();
$q->define_user($conn_database, $table);
$q->track_db_entries();

?>


Schematics

project-image
Schematic - 50.1


project-image
Schematic - 50.2


project-image
Schematic - 50.3


project-image
Schematic - 50.4

Downloads

Gerber Files

Download


Fabrication Files

Download


TV-Series-Anime-Episode-Tracker.zip

Download


opening_songs.zip

Download


Serial MP3 Player A v1.1 Manual.pdf

Download


tv.c

Download


music.c

Download