pi_robot – Playing with Raspberry Pi, iPad and some Code

Raspberry Pi Homeserver

The Raspberry Pi is still one of the most popular mini computers, not only among hobbyists. Cost-effective (about 30 to 40,- EUR depending on the model), flexible in the field of application and at the latest since the Raspberry Pi 3 Raspberry Pi 3 equipped with enough CPU power and memory to solve even more complex tasks.

With the 1.2 GHz quad-core ARM Cortex-A53 CPU, 1 Gig RAM, 40 GPIO pins, Ethernet port, WLan, Bluetooth, 4 USB ports and a Full HDMI port you can have a lot of fun. My operating system is Raspbian, a Debian Linux offshoot.

Table of contents:

Playing with Raspberry Pi, iPad and some Code

I use the GPIO pins among other things for an external reset button, which shuts down the Raspberry Pi cleanly if desired, without scrapping the partition of the MicroSD card MicroSD card, which happens quickly if you simply pull the power plug. For this purpose I programmed a small Java software, which is loaded automatically when starting the Pi, and handles the events on the GPIO ports. To access the GPIO of the Raspberry Pi, I use the open source library of -= The Pi4J Project =-, which greatly simplifies access using the Java programming language.

So the switch for shutting down the Pi is connected with a few lines of code. On the hardware side, a pin (in the example GPIO_00) is connected to a voltage, and it switches the whole thing in such a way, that the voltage is pulled from 1 to 0 by pressing the button of the switch. Then you only need to set a GpioPinListenerDigital to this port and fire it at PULL_DOWN.

GpioController gpio = GpioFactory.getInstance();
final GpioPinListenerDigital shutdownListener = new GpioPinListenerDigital() {
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent arg0) {
if (arg0.getState() == PinState.LOW)
{ commandShutdownPi(); }
final GpioPinDigitalInput pinShutdown = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);

The commandShutdownPi() function does nothing but execute the shutdown command. It couldn't be easier.

Runtime.getRuntime().exec("sudo shutdown -h now");

The program (Jar file) must then only be opened with root rights (for full access to the GPIO interface) at system startup of the Pi. This can be easily done by adding the following entry to the crontab (/etc/crontab).

@reboot root java -jar /home/pi/Desktop/Apps/pi.jar &

Raspberry Pi SmarthomeIn the pi.jar together with the different GPIO pins I also realized other gadgets, like for example an IR reader and transmitter (infrared diodes at GPIO_02 and _03) to receive commands from the remote control of the TV and to emulate remote controls (fo example Remote Control of the DVD player).

For this there are already all kinds of libraries and tutorials on the Internet, just like for radio transmitters (RFM12B), which can be used to remote control e.g. radio light switches and sockets. Have a look at the project pages of WiringPi and Pi4J. There are several code examples to realize this. Also check out my other smarthome projects.

HomeServer, MediaCenter and SmartTV

AmazonRelatively simple and fast, the Raspberry Pi can also be transformed into a home server, a media centre or smart TV. There are also innumerable images on the subject, which you only have to install, but making your own is the nicer alternative. To keep the effort as low as possible, I use the free OMX player for Linux or the Raspberry Pi version to play MP3, MP4, AVI and other audio and video files. In combination with the Python program Livestreamer not only local videos and music can be played, but also live streams from the Internet.

In the end my small program pi_robot.jar consists of 2 essential modules. On the one hand there is a server client module. This listens on port 4444 and accepts connections from the LAN of the iPad (see below), receives control commands like playing movies and forwards them to the second module, the actual robot, which executes the commands and delivers a result.

For the communication between iPad and Raspberry Pi I decided for the time being for a plaintext transmission in CSV format (semicolon as limiter). To start a movie from a hard disk, I send a command like "openmedia;/path/to/videodatei.avi;2" from the iPad to the Pi. The first part of the command is the actual control command, the second part is the absolute path to the video file, and the third part is passed with 0, 1 or 2 and specifies the audio port to be used during playback. (0=HDMI, 1=AUX, 2=both). All very simple and simple.

The finished server software pi_robot.jar is also started from the crontab like the GPIO handlers @reboot. However, I have added an export DISPLAY here, so that I can access the keyboard and mouse via the java.awt.robot(), and the corresponding drivers are loaded even if no keyboard or mouse is connected to the Raspberry Pi. Especially if you want to connect the Pi directly to your TV in your living room, this makes sense. Who wants to have keyboard and mouse lying around in the living room?!

Starting pi_robot.jar from /etc/crontab
@reboot pi export DISPLAY=:0.0 && java -jar /home/pi/Desktop/Apps/pi_robot.jar &

iPad-App for controlling the Raspberry Pi

Due to the fact that I don't want to have a keyboard and mouse on the Pi, I decided to bore the software so that it can also emulate keyboard and mouse inputs.


Raspberry Pi iPad KeyboardIn this case, the iPad should take full control of the Pi with all its functions.

The control of the web browser, the volume control of the pi, and all OMX player functions (louder, quieter, forward, back, pause, etc...) have also been integrated.

So that the cigarette box sized computer now serves as a home server, media center, SmartTV and much more.

Mediacenter with Raspberry Pi and iPadAt the moment I'm doing some fine-tuning. In the "Miscellaneous" tab of the iPad app I have integrated a function for shutting down the Pi, as well as some buttons for fast web access to popular websites.

Since there are still some small troubles and a password protection should still be integrated, I will not publish the app and the control software for the Raspberry Pi at this time.

I've also integrated a small messenger module to send messages via telegram, which I'll also introduce if necessary. I'll follow and refine the project as time allows, and then publish it here. Feedback, ideas, questions or remarks to this project you can post in the comments. With you happy coding. 🙂

Author: Sascha from Tinkering-Sascha.com

Author: Sascha

Some words about myself. My name is Sascha - i'm in my mid-30s and a software developer and martial artist from germany. Besides programming and martial arts some of my interests and hobbies are cooking, fitness and hearing loud heavy metal music. :D

Related postings

Backing rolls, yeast-raised pastries and brioche as tasty as from the baker

Better bake something yourself – today you’ll find here tasty recipes for bread rolls, baguettes, brioche and other yeast pastries! Beautiful recipes from the category cooking & baking as from the baker. Table of contents:Baking bread rolls and baguettesRecipe: Brioche-knot / Brioche-braidsYeast plait and pudding piecesLogi-Bread – A tasty and carbohydrate-reduced breadThe list of ingredients … Continue reading “Backing rolls, yeast-raised pastries and brioche as tasty as from the baker”

Build your own washbasin for your toddlers

Since our little daughter (and probably also every other toddler) would like to do everything herself, we try our best to fulfill her wish. Of course we do not want to slow down this zest for action in the bathroom when washing our hands or brushing our teeth and so a wooden children’s chair was … Continue reading “Build your own washbasin for your toddlers”

Unity 2D Platformer – Level Generator

For some time now I have been experimenting here and there with the 2D and 3D engine Unity. Especially the programming of a 2D-Platformers has been very interesting for me. However, programming a 2D game (if you are a programmer) is not the biggest problem, but in my opinion the look, because I am not … Continue reading “Unity 2D Platformer – Level Generator”

Telegram Messenger and the Bot API

Telegram is basically a messenger similar to Whatsapp or Threema , free and easy to use. I don’t want to say that it is better or worse than other messengers, but I like the Telegram Bot API so much that I want to write a little tutorial here. Table of contents:Using Telegram Messenger and the … Continue reading “Telegram Messenger and the Bot API”

3D Printing – 27 Inch iMac Stand Repair

As already known for a long time, the stand of the iMacs (27 inch) from 2012 to mid-2014 is often broken. With these models it happens (not all of them) that the hinge is worn out and the screen position can’t be changed anymore or, as in my case, the screen constantly tilts forward. 3D … Continue reading “3D Printing – 27 Inch iMac Stand Repair”

Leave a Reply

Your email address will not be published. Required fields are marked *

I have read and accepted the privacy policy!