Linux Format

Build a Chromecast

No Chromecast? One solution is to use a mobile app and Raspberry Pi to cast media across your network. Christian Cawley shows how it’s done.

- Christian Cawley has spent the past 15 years telling people how to do the same computing tasks but still has no idea how cars work.

No Chromecast? One solution is to use a mobile app and Raspberry Pi to cast media across your network. Christian Cawley shows how it’s done.

Google Chromecast is a great way to get media from your phone to your TV. Unfortunat­ely, it’s not ideal in some cases. For example, certain routers such as the Virgin SuperHub 3 won’t work out of the box with a first-generation Chromecast. Meanwhile, the Chromecast is low spec and limited in many ways.

Fortunatel­y, the Raspberry Pi is ready to come to the rescue, providing a Chromecast-like experience when paired with a dedicated mobile app. With a just few terminal commands, you can configure the Raspberry Pi to accept video, music, and audio content streamed from your Android phone or tablet, and dress it up with a slick home screen.

While this should work with any of the main Raspberry Pi models, we used a Raspberry Pi 3 B+, which delivered fast, stable streaming of high-definition video from the Android handset.

Streaming video, not apps

It’s important to emphasise that the Raspberry Pi plus Raspicast setup isn’t a complete replacemen­t for the Chromecast. For example, there’s no VR support, or Google Home; there’s no ambient mode, although it’s easy enough to configure a similar home screen, which we’ll also look at below.

In short, media streaming is replicated. Everything else you’ll need to add yourself, rely on existing streaming options, or quietly overlook.

Enable SSH

Start by ensuring the Raspberry Pi is connected to a display, and you have a mouse and keyboard attached. If this isn’t possible, you’ll need to set this up remotely, controllin­g your Raspberry Pi over SSH.

To do this, you’ll need to activate SSH on the Raspberry Pi. If this isn’t already enabled, you have two options. The first is to connect a keyboard, open the Raspberry Pi Configurat­ion tool in the Preference­s submenu on the desktop, click Interfaces and select SSH, clicking OK to confirm. A reboot may be required.

The second option is to insert your powered-down Raspberry Pi’s microSD card into your computer, browse to the /boot/ directory, and create an empty text file called ssh, with no file extension. Eject the card, replace in the Raspberry Pi and reboot; SSH will be enabled, ready for remote access. Note that you’ll need to know your Raspberry Pi’s hostname or IP address for SSH access. You’ll find the hostname by entering that word as a command. To see the IP address, either check your router’s admin screen or enter ifconfig . Look for an entry for eth0 (Ethernet) or wifi0 (wireless), and you’ll find the IP address labelled inet.

Fruit upgrade

It’s time to update your Raspberry Pi. We’re assuming you’re using the latest version of Raspbian Stretch for this, although other Pi distros should work fine. Open the Terminal (or connect via SSH) and enter

sudo apt-get update sudo apt-get upgrade

With your Pi’s repositori­es refreshed and any upgrades downloaded, it’s time to install some prerequisi­te packages:

sudo apt-get install libjpeg9-dev libpng12-dev

Two graphics-based packages are installed here: libjpeg9-dev and libpng12-dev. These enable JPEG and PNG images to be streamed from your Android device to your Raspberry Pi, and displayed on your TV.

Streaming to the (Open)Max

Also required is OpenMax, described by its developer as “a GPU accelerate­d image viewer for the Raspberry Pi.” It also includes graphic libraries for GIF and BMP images. Get OpenMax by cloning the GitHub directory:

git clone https://github.com/HaarigerHa­rald/omxiv

Once downloaded, change directory:

cd omxiv

Next, use the make command to build the software.

make ilclient make

You’ll need to wait a while for this to complete. This is a good time to install the Raspicast mobile app, as per the boxout ( belowright).

Once the tool is ready to install use sudo make install

Wait while this completes before proceeding.

With everything ready to roll on your computer, and the Raspicast app installed on your phone it’s almost time to start casting. First, open the app and tap the menu to find the SSH settings. Here, input the hostname or IP address of your Raspberry Pi. You’ll also need to add the username and password. Click OK and prepare to start streaming media from your phone.

Two options are available: streaming content stored on your phone from within the app, or by sharing the content from another app. To stream from Raspicast, tap the Cast button, and browse the media on your phone. Select the one you want to view, tap the Play button, and your Raspberry Pi will display the content on your TV.

For sharing (perhaps from YouTube), simply cue a video or song, tap the share button, and select Raspicast. You’ll spot two options: one to play immediate, and one to queue the clip to play later.

As versatile as ever, the Raspberry Pi makes a great Chromecast replacemen­t. Raspicast isn’t the only method to achieve this, however. If you have Kodi installed on your Raspberry Pi, several remote apps for the media centre, including the official option Kore, offer casting from your mobile. This is useful, because Raspicast won’t work on Raspberry Pi-based Kodi systems anyway.

Take me home

You might have a Raspberry Pi that receives media, Chromecast-style, from your Android device, but it doesn’t quite look the part. Chromecast has a slideshow of curated images for you to enjoy, for example, along with weather, and date and time informatio­n.

Want to make your Pi more like Chromecast? You need a kiosk app – one that enables custom images to be displayed as a slideshow. Many of these are available, but the simplest to set up is Andrew Delph’s Python slideshoww­ithtimeand­weather which is on GitHub.

Get started by adjusting the Raspberry Pi’s video memory. Open the configurat­ion tool with sudo raspi-config

Next, browse to Advanced Options>Memory Split. Here, change the value to 256. This ensures that the Pi’s GPU has enough available memory to handle the slideshow images. Click OK to continue, then follow the instructio­n to reboot. Upon restarting, open a new terminal window and clone the slideshow files from GitHub: git clone https://github.com/andrewdelp­h/pythonslid­eshow-with-time-and-weather.git

Once this is downloaded, rename the directory to a snappier title, such as pyss with the mv command. sudo mv python-slideshow-with-time-and-weather pyss

You’ll also need the pyowm tool. This is a wrapper for the OpenWeathe­rMap, which brings the necessary weather data onto your Raspberry Pi’s desktop:

pip install pyowm

Some additional configurat­ion is required to get this to work. First, you’ll need to remove some images. Open the pyss directory first and remove the four JPG files starting WIN_20160220.

Next, edit the ss.py file.

sudo nano ss.py

Here, look for the line that reads

observatio­n = owm.weather_at_place(‘Ottawa,CA’)

Change the city and country to match your own location. For example, a Londoner might use

observatio­n = owm.weather_at_place(‘London,UK’)

Press Ctrl+X to save and exit. In the terminal launch the slideshow:

python ss.py

A gallery of stunning images, the date and time, and current weather will be displayed on your Raspberry Pi Chromecast replacemen­t!

 ??  ?? Combine a simple slideshow plus weather informatio­n tool and media casting to turn your Pi into a Chromecast-like device.
Combine a simple slideshow plus weather informatio­n tool and media casting to turn your Pi into a Chromecast-like device.
 ??  ??
 ??  ?? A Chromecast device is nice enough, but it’s more satisfying to configure your Raspberry Pi to do the same job.
A Chromecast device is nice enough, but it’s more satisfying to configure your Raspberry Pi to do the same job.

Newspapers in English

Newspapers from Australia