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

kraken.jpgRelatively 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.

kraken l.jpg

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 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

This might also be interesting for you

Training in limited space / fat burning 2.0

It will soon be summer again for sure! Then the days will be hot again, 30 degrees and more. If you haven't reached your beach figure yet, you should do something about it, if you want to spend the summer holidays at the sea and have a good figure 😉 But also all those who … Continue reading "Training in limited space / fat burning 2.0"

Ideas for children Toys from the 3D printer

3D printers have become an integral part of our everyday lives. In addition to toys, animals and figures from the printer, it is relatively easy to upgrade pieces of furniture in the children's room or print lamps, photo frames and containers. Lego bricks and marble run are no problem, as even more useful things from … Continue reading "Ideas for children Toys from the 3D printer"

Program your own Screen Recorder / Capture Software

While searching for an easy to use screen recorder tool, I stumbled across all kinds of free and paid software solutions. From my point of view, pretty much all of them were either completely overloaded, difficult or complicated to use. Others were just expensive in relation to the functionality. My conclusion: Program yourself! Table of … Continue reading "Program your own Screen Recorder / Capture Software"

Sushi: Maki and Nigri homemade

Sushi is a Japanese dish made from cold, sour rice. Other ingredients to complement it include nori (dried and roasted seaweed), raw or smoked fish (e.g. tuna or salmon), raw seafood (e.g. prawns) and vegetables (e.g. avocado, cucumber, carrot or tofu). The Sushi is prepared in bite-sized pieces and served visually appealing. Table of contents:Make … Continue reading "Sushi: Maki and Nigri homemade"

Arduino Fitnessboard v1 - Experiment

On the weekend I fortunately had some time for handicrafts and a nice idea for a fitness board for training at home, which is operated from the push-up position. A video can be found further down in this article and on the Youtube channel of tedokai.de. Table of contents:Building  an Arduino Fitness BoardFitnessboard - RequirementsFitnessboard … Continue reading "Arduino Fitnessboard v1 - Experiment"

Leave a Reply

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

I have read and accepted the privacy policy!