The HMedia System (Home Media System) is a project that I took up during the summer break right after my graduation. The objective of this project was to control a homemade 16 by 8 LED matrix integrated with a media player on the computer using an app developed for my Android phone. The LED matrix is capable of displaying the system time, a custom text message or the frequency spectrum from the current music file being played. The entire work involving the making of the LED matrix, the media player and the Android application has been documented here. You are free to use and/or modify the source code and control your media player. The LED matrix is just an add-on. If you are interested in soldering components and programming microcontrollers, then it will come as an interesting project for you. Everything was written in and for Ubuntu but it should work just as fine in any other Linux distribution or Windows.
The LED Matrix
The LED matrix here is an array of 128 LEDs arranged in a 16 by 8 pattern. The construction of the matrix is a tedious job. The LEDs are first arranged on a Veroboard and then soldered one by one. The anodes of the LEDs on a row and the cathodes of the LEDs on a column are connected (Row column addressing technique). This allows the microcontroller, an ATMEL ATMega32 to control all the 128 LEDs using just 24 I/O pins.
A 2D array is maintained which stores the value of each LED, 1 denoting on and 0 denoting off. To control the individual LEDs, the columns are made high (+5V) from 1 to 16 and the rows are made low (0V) from 1 to 8. So, at an instant only the particular LED pointed to by the location (row, column) is set to on/off depending on the value in the 2D array. All the LEDs are cycled through one by one at a very high rate thereby giving the impression that all the LEDs are glowing. The only drawback of this method is that the brightness of the LEDs decrease because the LEDs are only turned on for a short amount of time. The iteration of the LEDs is achieved using a timer interrupt.
The UART of the microcontroller is used to communicate with the computer.
The Media Player
The media player is written entirely in qt and uses the BASS media library to play audio files and get the audio spectrum. It includes most of the basic functions of a media player and a simple playlist. It also has a TCP/IP Server which can accept socket requests from clients on the network (to communicate with the Android app). It uses the qextSerialPort class to communicate with the LED matrix over the serial port.
The Media Player program can be divided into three parts –
- The UI thread
- The Media player thread
- The Client-Server thread
The Media player thread which begins as soon as the program starts is responsible for playing the music files. Along with it, it also sends the current track position and status to the connected clients via the TCP/IP socket connection. It is also responsible for generating the audio spectrum of the current file being played using a Fast Fourier Transform method already implemented in the BASS media library.
The Client-Server threads are created when incoming connections are accepted by the TCP/IP server running in the UI thread. Every time a new connection request is received by the server, a new Client-Server thread is created which then handles all the communication with that particular client. This thread has slot-signal connections with the Media Player thread for sending the current track information to the client and slot-signal connections with the UI thread for sending the strings received from the Android device.
The UI thread essentially performs all the GUI related events, runs the TCP/IP server and also parses the strings sent from different clients through the Client-Server thread. It also has an option to switch between the spectrum display mode and the time display mode (for the LED matrix).
The Android App
The Android application (written in Java and built in Eclipse) is just a simple application which makes a TCP/IP request to the server when the user presses the Connect button. If the connection is successful, the current playlist and track data is displayed on the app screen and the user can control the media player.
qt Files –
ATMega32 (Microcontroller) Files –
Android Files –