FatCat970
Posts: 5
Joined: Sun Jul 15, 2012 9:16 am

Pi with video?

Wed Jul 18, 2012 11:56 am

Would it be at all possible to use switches linked to the gpio port via an interface such as Pi-Face or the Gert board to trigger video to run on the Pi.

So for example could a school kid set up a bedroom alarm that would play a video telling their younger brother to get out of the room.

Any ideas?

obarthelemy
Posts: 1399
Joined: Tue Aug 09, 2011 10:53 pm

Re: Pi with video?

Wed Jul 18, 2012 12:06 pm

Yes, certainly. I have no clue how to do it though.

Alternatively, you could also be nice to your little brother :lol: Show him what's in your room and explain to him why he shouldn't mess with it, and how HE would feel if you got into his room and made a mess. Technology is rarely a solution to social problems.

MadCow42
Posts: 106
Joined: Sun Jul 01, 2012 12:48 am

Re: Pi with video?

Wed Jul 18, 2012 3:04 pm

You wouldn't even need an extra board - just connect a switch between a GPIO pin and the 3v3 pin.

A little Python programming with RPi.GPIO, and you're done - probably 10 lines of code max. (if you're not using the latest RPi.GPIO that allows you to enable the internal pull-down resistors on the GPIO pin, tie the pin to ground with a 10kOhm resistor instead).

Kevin

MadCow42
Posts: 106
Joined: Sun Jul 01, 2012 12:48 am

Re: Pi with video?

Wed Jul 18, 2012 4:17 pm

Actually, 6 lines of code. :) (not tested, but for educational purposes)

Code: Select all

import os
import RPi.GPIO as GPIO

GPIO.setup(11, GPIO.IN)    # depending on what pin you're using for input
while 1:
    if GPIO.input(11) == False: # or True, depending if your circuit is normally-open or normally-closed
        os.system("vlc \"my video filename and location.mpg\"")  #or whatever video app you're using, and the proper command line command to start your video
        # you could do some fun logging here so you can keep track of when it was triggered, or even send yourself an email alert, take a picture with a webcam... the options are endless.
    # you'd probably want to do a time.sleep(0.05) or something here so you don't peg your system to the max in this loop... make sure to import time at the top.
The best way to learn programming is to have a task that you want desperately to accomplish. Interacting with the "real world" is a cool motivator to get started, with very tangible results.

Kevin.

FatCat970
Posts: 5
Joined: Sun Jul 15, 2012 9:16 am

Re: Pi with video?

Thu Jul 19, 2012 5:05 am

Thanks for the help. I now have a clear goal. I do not yet have a Pi but I can continue doing some prep until it arrives at my door.

FatCat970
Posts: 5
Joined: Sun Jul 15, 2012 9:16 am

Re: Pi with video?

Fri Jul 20, 2012 1:16 am

Anyone fancy giving this a go on their Pi? My board will not be here any time soon. Bit of a cheeky question but I am sure someone else would like to find out it it works as well.

MadCow42
Posts: 106
Joined: Sun Jul 01, 2012 12:48 am

Re: Pi with video?

Fri Jul 20, 2012 1:57 pm

FatCat970 wrote:Anyone fancy giving this a go on their Pi? My board will not be here any time soon. Bit of a cheeky question but I am sure someone else would like to find out it it works as well.
It'll work. I'd do it myself to show you, but I've never even had a monitor hooked up to my Raspberry - it runs headless.

Kevin.

Return to “General programming discussion”