Raspberry Pi Presentation Machine With Remote Control

7,330

96

7

Published

Introduction: Raspberry Pi Presentation Machine With Remote Control

About: I like to learn, like to make, like to share.

Have you ever thought of having a little presentation box that you can just plug into the projector and start talking?

I have to give lecture in powerpoint frequently. Most of the time, I face different problems using the projector and PC. Sometimes my files get infected by virus and I am unable to find any presentation file while plugging my pen drive into the PC.

To get rid of this problem, I was thinking of an easy solution and suddenly an idea came to my mind. Why am I not using my Raspberry Pi as a presentation machine? Thereafter, I started working to make a little presentation box and finally, I made it. Now, I just plug the device into any projector and the presentation starts automatically from my pen drive. I can control the presentation using a remote. No keyboard and mouse is required.

Busy life, easy solution!!!

Here, I will share the complete recipe for my magic box (the presentation machine). So, keep reading.

Demo Video:

Step 1: Bill of Materials

1. A Raspberry Pi with an SD card(seeedstudio.com): Any version should work fine but for the higher version you will get higher speed. I recommend PI 3 if you want to buy a new one. I have one Pi 1 B version and using it for the project without buying a new one and it is working perfectly.

2. Minimum 2Ah Li-ion Battery (sparkfun.com): The capacity of the battery depends on your requirement. From a 2Ah battery, you can get 2 hours backup. If you required more then use a higher capacity battery.

3. 5V/1A Li-ion Charger and Booster (sparkfun.com):This module converts 3.7V to 5V and also has an integrated Li-ion charger circuit. You can also low price power bank module which has the same functionality. You can buy one from ebay.com at $3.

4. 1838B IR receiver: You can find it easily form any local electronic component shop. In fact, any three pin IR receiver should work which has an in-built decoder.

5. Car MP3 Remote: I select it for its small form factor. Any remote like your old TV remote will work. So, choose one as your convenience. I will show you how you can record your own remote in the next step.

6. Mini SPDT Switch: For on/off the raspberry pi as pi has no built-in on/off switch. You can collect it from any local electronic shop.

7. 3D printed case: I am preferring your own 3D printed case instead of a ready-made case because we will add battery and charger circuit inside the case. A ready-made case has no enough space for placing the battery. I will give you the 3D file in next step.

Tools Required

1. A soldering iron with solder

2. Some wire and wire cutter

3. Access to a 3D printer

4. A cup of coffee.

Step 2: Connecting IR Receiver to Raspberry Pi

I am assuming that you installed a fresh copy of Raspbian operating system to the SD card. If not so, please visit the link: https://www.raspberrypi.org/downloads/ and follow the instructions. I am also assuming you have some previous experience working with Raspberry Pi. If you are new to Raspberry Pi follow the getting started guide link given below:

https://www.imore.com/how-get-started-using-raspberry-pi

https://opensource.com/article/16/12/getting-started-raspberry-pi

https://www.raspberrypi.org/forums/viewtopic.php?t=4751

I am sure you are now more experienced about raspberry pi. So, let's start working.

The IR sensor has just three pins, that will connect with three pins on the GPIO connector. To do the connecting, we can use female to female jumper leads. These make a good reliable connection as the IR sensor has unusually thick leads for an IC. You can also solder the IR receiver with GPIO for permanent connection.

Make the connections as shown the schematic. The receiver has three terminal (VCC, GND, and SIGNAL).

Connect:

VCC pin of IR receiver to 3.3V pin of Raspberry Pi

GND pin of IR receiver to any Ground pin of Raspberry Pi

SIGNAL pin to GPIO 18 of Raspberry Pi (Add a transistor to increase the range. Amplifying the current output from signal pin increases the IR LED's signal strength)

After making the connection go to the next step to configure the software.

Step 3: Configuring Raspberry Pi for IR Remote

Each button of an IR remote control has a string of specific encoding. When a button is pressed, the IR transmitter in the remote control will send out the corresponding IR encoding signals. On the other side, when the IR receiver receives certain encoding signals, it will decode them to identify which button is pressed.

For my project, I used the lirc library to read infrared signals returned by buttons of the remote control and translate them to button values. Then I used pylirc (Python) to simplify the process for reading values from the remote control.

LIRC is a package that allows you to decode infrared signals of many (but not all) commonly used remote controls. LIRC runs as a daemon that will decode IR signals received by the device drivers and provide the information on a socket. We will then write a program in the user space to monitor this socket for input events using the LIRC client library.

To configure your Raspberry Pi for remote control follow the steps:

1. Download the LIRC library using the following command from terminal

sudo apt-get install lirc

2. Set up LIRC

Add the two lines below to /etc/modules. This will start the modules upon boot. Pin 18 below will be used to take the output from the IR sensor. Use the following command:

sudo nano /etc/modules

and add this two lines in the file opened

lirc_dev
lirc_rpi gpio_in_pin=18

Type, Ctrl + X and then Y to save and exit. Also, edit your /boot/config.txt file. Open the file using the command:

sudo nano /boot/config.txt

and add the following line to the file:

dtoverlay=lirc-rpi,gpio_in_pin=18

Then, edit /etc/lirc/hardware.conf using the command:

sudo nano /etc/lirc/hardware.conf

and paste the following code exactly as shown below.

# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"
 
# Don't start lircmd even if there seems to be a good config file
# START_LIRCMD=false
 
# Don't start irexec, even if a good config file seems to exist.
# START_IREXEC=false
 
# Try to load appropriate kernel modules
LOAD_MODULES=true
 
# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
 
# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
Press Ctrl +X and Y to save and exit. Type following command to reboot.
sudo reboot

3. Test the configuration

To perform a quick test to see if LIRC is working, we need to stop the LIRC daemon and start mode2. mode2 shows the pulse/space length of infrared signals.

To start the LIRC in mode2 type the following command

sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0

When buttons are pressed on your remote, mode2 will give a similar output to what is shown below.

pulse 627
space 514
pulse 624
space 513
pulse 599
space 521
pulse 618
space 1668
pulse 589
space 532

If you receive such output by pressing a button then Congratulation! Your configuration and connections are working!! Go forward!!!

Step 4: Recording IR Codes From a Remote

The irrecord command will help us discover the IR codes used by our remote and assist with creating a lircd.conf file which will be used by LIRC.

To record the IR code type the following command from the terminal:

irrecord -d /dev/lirc0 ~/lircd.conf

Once started, irrecord will show detailed instructions on how to setup your remote. However, here is summary;

1.When asked, press all buttons on your remote until asked to stop.

2.Assign a pre-defined name to each button. running irrecord --list-namespace will display a list of available names. You can set any name for any button but the name must be from the list (you can use the name from the following code). After successfully recording the config file for the Adafruit MinRemote looks like this;

# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Tue Oct  8 07:05:38 2013
#
# contributed by
#
# brand:                       /home/pi/lircd.conf
# model no. of remote control:
# devices being controlled by this remote:
#
 
begin remote
 
  name  /home/pi/lircd.conf
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100
 
  header       9006  4447
  one           594  1648
  zero          594   526
  ptrail        587
  repeat       9006  2210
  pre_data_bits   16
  pre_data       0xFD
  gap          107633
  toggle_bit_mask 0x0
 
      begin codes
          KEY_1                    0x08F7
          KEY_2                    0x8877
          KEY_3                    0x48B7
          KEY_4                    0x28D7
          KEY_5                    0xA857
          KEY_6                    0x6897
          KEY_7                    0x18E7
          KEY_8                    0x9867
          KEY_9                    0x58A7
          KEY_0                    0x30CF
          KEY_DOWN                 0xB04F
          KEY_LEFT                 0x10EF
          KEY_UP                   0xA05F
          KEY_RIGHT                0x50AF
          KEY_BACK                 0x708F
          KEY_ENTER                0x906F
          KEY_SETUP                0x20DF
          KEY_PAUSE                0x609F
          KEY_PAUSE                0x807F
          KEY_STOP                 0x609F
          KEY_VOLUMEUP             0x40BF
          KEY_VOLUMEDOWN           0x00FF
      end codes
 
end remote

Now replace the existing conf file (which is most likely empty) with the new one you just created by the following command:

sudo cp lircd.conf /etc/lirc/lircd.conf

Now, restart LIRC by the following command:

sudo /etc/init.d/lirc restart

Test the new remote conf file

You can use irw to test the new config file. irw sends data from Unix domain socket to stdout You should get a similar output as below.
pi@raspberrypi ~ $ irw
pi@raspberrypi:~ $ irw
0000000000000001 00 KEY_CHANNELDOWN /home/pi/lircd.conf
0000000000000002 00 KEY_CHANNEL /home/pi/lircd.conf
0000000000000003 00 KEY_CHANNELUP /home/pi/lircd.conf
0000000000000004 00 KEY_PREVIOUS /home/pi/lircd.conf
0000000000000005 00 KEY_NEXT /home/pi/lircd.conf
0000000000000006 00 KEY_PLAYPAUSE /home/pi/lircd.conf
0000000000000007 00 KEY_VOLUMEDOWN /home/pi/lircd.conf
0000000000000008 00 KEY_VOLUMEUP /home/pi/lircd.conf
0000000000000009 00 KEY_EQUAL /home/pi/lircd.conf
000000000000000a 00 KEY_NUMERIC_0 /home/pi/lircd.conf
0000000000000014 00 BTN_0 /home/pi/lircd.conf
0000000000000015 00 BTN_1 /home/pi/lircd.conf

If you get the above result then Congratulation! You successfully setup the remote control.

Step 5: Controlling Keyboard & Mouse Using Remote

In this stage, I will show you how you can create virtual keystrokes and mouse clicks from the remote control. I will use Python code to do the job.

Install pylirc

First, download pylirc. Pylirc is LIRC Python wrapper and it's required to access LIRC from Python programs. To install Pylirc you should type following command from terminal

sudo apt-get install python-pylirc

Create a lircrc.conf file. The lircrc file is used to map the key symbols defined in lircd.conf to application-specific strings. Thus, this file cannot be configured until lircd has been configured to provide proper key symbols as displayed by irw. We already setup a lircd in the previous step.

The lircrc file should be placed in the home directory as ~/.config/lircrc. Optionally you can create a system-wide configuration file located in /etc/lirc/lircrc which will be used when no lircrc file can be found in the user's home directory. The idea is to have configuration information of all clients in one place. That lets you keep a better overview of clients and simplifies the use of modes explained later.

Following is the syntax of the lircrc file itself. The file consists of one or more of the following constructions:

begin
        prog    = ...
        remote  = ...
        button  = ...
        [button = ...] (optional, for key sequences)
        repeat  = ...
        delay   = ...
        ignore_first_events = ...
        config  = ...
        [config = ...] (optional, for toggle button behaviour)
        mode    = ...
        flags   = ...
end

The complete lircrc file I prepared for my project is as follows:

begin        
	button = KEY_PAUSE
        prog   = irexec
        repeat = 0
        config = pause
    end
begin
        button = KEY_SETUP
        prog   = irexec
        repeat = 0
        config = setup
    end
begin
        button = KEY_LEFT
        prog   = irexec
        repeat = 0
        config = left
    end
begin
        button = KEY_RIGHT
        prog   = irexec
        repeat = 0
        config = right
    end
begin
        button = KEY_DOWN
        prog   = irexec
        repeat = 0
        config = down
    end

begin
        button = KEY_UP
        prog   = irexec
        repeat = 0
        config = up
    end
begin
        button = KEY_VOLUMEUP
        prog   = irexec
        repeat = 0
        config = volumeup
    end
begin
        button = KEY_VOLUMEDOWN
        prog   = irexec
        repeat = 0
        config = volumedown
    end
begin
        button = KEY_0
        prog   = irexec
        repeat = 0
        config = zero
    end
begin
        button = KEY_1
        prog   = irexec
        repeat = 0
        config = one
    end
begin
        button = KEY_2
        prog   = irexec
        repeat = 0
        config = two
    end
begin
        button = KEY_3
        prog   = irexec
        repeat = 0
        config = three
    end
begin
        button = KEY_4
        prog   = irexec
        repeat = 0
        config = four
    end
begin
        button = KEY_5
        prog   = irexec
        repeat = 0
        config = five
    end
begin
        button = KEY_6
        prog   = irexec
        repeat = 0
        config = six                   
    end
begin
        button = KEY_7
        prog   = irexec
        repeat = 0
        config = seven                  
    end
begin
        button = KEY_8
        prog   = irexec
        repeat = 0
        config = eight                  
    end
begin
        button = KEY_9
        prog   = irexec
        repeat = 0
        config = nine                   
    end

To know details about lircrc, you may visithttp://www.lirc.org/html/configure.html. You can modify my file I attached herewith to make it easy.

Install PyUserInput

PyUserInput is a cross-platform python module to take control of the mouse and keyboard in python that is simple to install and use.

PyUserInput is registered on PyPI (Python Package Index) and updated periodically, so tools such as pip or easy_install should work. Type the following command from terminal.

pip install PyUserInput

Step 6: Python Program for Simulating Keyboard & Mouse Using Remote Control

Here is the complete python program to emulate keyboard & mouse from remote key-press.

#!/usr/bin/env python

import pylirc, time
from pykeyboard import PyKeyboard
from pymouse import PyMouse

k = PyKeyboard()
m = PyMouse()

blocking = 0;

x = 0
y = 0

def setup():
	pylirc.init("irexec") #pylirc.init("pylirc", "./conf", blocking)

def key_press(config):
	if config == 'pause':
		k.tap_key(k.function_keys[5]) 
		print 'Pause'
		
	if config == 'setup':
                k.press_key(k.shift_key)
		k.tap_key(k.function_keys[5])
		k.release_key(k.shift_key)
		print 'Setup'

	if config == 'left':
                global x
                x -= 50
                global y
                m.move(x,y)                      
		print 'left'

	if config == 'right':
		x += 50               
                m.move(x,y)
                print 'right'

        if config == 'up':
                y -= 20
                m.move(x,y)                      
		print 'up'

	if config == 'down':
		y += 20               
                m.move(x,y)
                print 'down'
                
	if config == 'zero':
                k.press_key(k.control_key)
	        k.tap_key('b')
	        k.release_key(k.control_key)
		print 'blank screen'
		
	if config == 'one':
                k.tap_key(k.escape_key)
		print 'one'
		
	if config == 'two':
                k.tap_key(k.up_key)
		print 'up arrow'
		
	if config == 'three':
                
		print 'Green'
		
	if config == 'four':
                k.tap_key(k.left_key)
		print 'left arrow'
		
	if config == 'five':
                x_dim, y_dim = m.position()
                m.click(x_dim, y_dim, 1)
		print 'Green'
		
	if config == 'six':
                k.tap_key(k.right_key)
		print 'right arrow'
		
	if config == 'seven':
                m.scroll(-3, 0)
		print 'Green'
		
	if config == 'eight':
                k.tap_key(k.down_key)
		print 'down arrow'
		
	if config == 'nine':
                m.scroll(+3, 0)
		print 'Green'

	if config == 'volumeup':
                x += 10               
                m.move(x,y)
		print 'Blue OFF'

	if config == 'volumedown':
                x -= 10               
                m.move(x,y)
		print 'Light Blue'

def loop():
	while True:
		s = pylirc.nextcode(1)
		
		while(s):
			for (code) in s:
				print 'Command: ', code["config"] #For debug: Uncomment this
#				line to see the return value of buttons
				key_press(code["config"])
			if(not blocking):
				s = pylirc.nextcode(1)
			else:
				s = []

def destroy():
	pylirc.exit()

if __name__ == '__main__':
	try:
		setup()
		loop()
	except KeyboardInterrupt:
		destroy()

Save the file as remote.py to the directory /home/pi in your raspberry pi. Make the file executable by the following command:

sudo chmod +x remote.py

Make a script to the same directory by the following command:

sudo nano myapp.sh
Add the following lines in the script:
sleep 5
cd /
cd home/pi
sudo python remote.py
cd /

Press Ctrl + X to save and exit. Make the file executable by typing the following command from the terminal:

sudo chmod +x myapp.sh

Open the autostart file by the command:

sudo nano /.config/lxsession/LXDE-pi/autostart

Add the following two lines at the end of the file:

@libreoffice --show /media/pi/VERBATIM/presentation.ppt --norestore
@sh /home/pi/myapp.sh

Press Ctrl + X to save and exit. Here the file name which we want to load at startup is presentation.ppt. If you like another name make the change here. /media/pi/ is the path of USB flash drive and VERBATIM is the name of the flash drive. We are opening the presentation with LibreOfficewhich is preinstalled in raspberry pi. We are also starting myapp.sh which will run remote.py program after 5 seconds of loading GUI. Without GUI keyboard and mouse module will not work.

Step 7: Hacking the Raspberry Pi for Power Supply

As we are going to add the battery inside the case of the raspberry pi, the default micro USB port is not a good option. A good option is providing power using GPIO but it bypasses the fuse and may be damaged your Pi in case of any fault in the power supply. So, for better safety, I soldered two jumper wire at the bottom of the Pi. The image and the schematic are attached for better understanding. Connect two jumper wires accordingly. We will connect these wire to a 5V supply to provide power.

Step 8: Making the Connection of Battery

We already completed all software configuration. Now we need to connect the battery and boost converter circuit to the Raspberry Pi. First, connect the positive terminal of the battery to the B+ (or IN+) of the boost converter and negative terminal of the battery to the B- (or IN-) pin of the boost converter. Connect an SPDT micro switch to the positive output of the boost converter. Then connect another terminal of the switch to the positive input of the raspberry pi. Connect ground pin of the boost converter directly to the ground pin of the Raspberry Pi. I attached some snapshots for clear understanding.

Step 9: Putting All Inside the Box

3D print the case from the link: https://www.thingiverse.com/thing:215673. Thanks to ElliottMoo for his nice design. Scale the upper part 30% along Y axis to make enough place to attach the battery.

After making all the connection I place the battery to the upper part of the box using a double-sided tape. Then I placed boost converter using hot glue keeping the charging port outside. Again, I fix the switch with hot glue. Finally, I place the raspberry pi in the bottom part of the box.

Share

    Recommendations

    • Clocks Contest

      Clocks Contest
    • Woodworking Contest

      Woodworking Contest
    • Oil Contest

      Oil Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    7 Comments

    This should be a comercial product. Great solution to several problems. Good work!

    Thank you, Thank you. You have presented solutions to two problems for several of my Raspberry Pi projects. Your remote control solution is way more elegant and functional than using a Flirc and I am going to have to give it a try. I will try to adapt it for my WiFi HiFi NFS media player attached to my stereo as the Flirc can only do single keystrokes. I have been thinking of adding a battery pack to a couple of Raspberry PI projects (car computer and a several remote sensors).

    1 reply

    Thank you too.

    Thanks

    Did not find link to case or directions for printing? Did I miss it?

    1 reply

    Thanks for your comment. Unfortunately, I forgot to add the link of the 3D design file. Now it is updated with the link.