radeusnox01
Posts: 3
Joined: Wed Dec 12, 2012 10:54 pm

Using Serial (UART) to start video files

Sat Dec 22, 2012 2:13 pm

I am starting a project using the raspberry pi as a video kiosk for displaying video presentations.

I have a device that sends information via Serial Comm. to the Rpi. It would have been easier (I may be mistaken) to play/control using GPIO of the pi to play different video files but since it is required that we use the said device (actually a voice recognition module that communicates using serial), I will be using the UART function of the Rpi.

Can this be done easily?

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using Serial (UART) to start video files

Sat Dec 22, 2012 6:53 pm

radeusnox01 wrote:I am starting a project using the raspberry pi as a video kiosk for displaying video presentations.

I have a device that sends information via Serial Comm. to the Rpi. It would have been easier (I may be mistaken) to play/control using GPIO of the pi to play different video files but since it is required that we use the said device (actually a voice recognition module that communicates using serial), I will be using the UART function of the Rpi.

Can this be done easily?
Yes.

But it really depends on what you call easy - one mans easy is another mans hard...

What I suspect you'll need to do is write a program that listens to the serial line - and then when they other end sends it some data, the program on the Pi interprets that data (e.g. "play filename") and does the right thing. e.g. launch omxplayer with the given filename, and/or returns an error/success code back to your device...

Easy..

Hard parts might include getting the voltage levels right (Pi is 3.3v) and writing the serial access software (I wrote my own serial library to make it easy - it's part of my wiringPi library)...

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13142
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Using Serial (UART) to start video files

Sat Dec 22, 2012 7:04 pm

on a similar note.
What would be really useful would be hardware for infra red serial data support!
That is the ability to receive the infrared pulses from a remote control, and be able to decode them as commands for the player.
In other words the ability to use a remote controller to control the video player (XMBC).

Most infrared controllers simply emit short infra red pulses, when received and stretched to one "bit time" (often one of a 1200 BPs serial data-stream, so 1/1200th of a second) then what you will end up is simply start/stop bit asynchronous data (often mistakenly called "RS232 data") which can be received easily enough with a UART set to 1200 Bps, and the correct parity settings.

In fact there are simple infra red receivers like the TSOP1738 who not only receive the infra red light pulses, but also do the pulse stretching for you, so what comes out of them can be directly tied to the RxD input of the PI. All you need is the IC, a 100 Ohm resistor and a 10uF elco for the decoupling of the 5V supply of the IC, and a 4K7 pullup to 3,3V on the output of the IC!

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using Serial (UART) to start video files

Sat Dec 22, 2012 7:24 pm

mahjongg wrote:on a similar note.
What would be really useful would be hardware for infra red serial data support!
That is the ability to receive the infrared pulses from a remote control, and be able to decode them as commands for the player.
In other words the ability to use a remote controller to control the video player (XMBC).

Most infrared controllers simply emit short infra red pulses, when received and stretched to one "bit time" (often one of a 1200 BPs serial data-stream, so 1/1200th of a second) then what you will end up is simply start/stop bit asynchronous data (often mistakenly called "RS232 data") which can be received easily enough with a UART set to 1200 Bps, and the correct parity settings.

In fact there are simple infra red receivers like the TSOP1738 who not only receive the infra red light pulses, but also do the pulse stretching for you, so what comes out of them can be directly tied to the RxD input of the PI. All you need is the IC, a 100 Ohm resistor and a 10uF elco for the decoupling of the 5V supply of the IC, and a 4K7 pullup to 3,3V on the output of the IC!
Think you might have missed all the LIRC stuff...

http://www.raspberrypi.org/phpBB3/viewtopic.php?t=7798
http://www.raspberrypi.org/phpBB3/viewt ... 37&t=18723

first 2 google hits..

And there's also that magic thing who's name I've forgotten that passes the signals back down the HDMI lead into the Pi which I believe works with the various media player distributions...

-Gordon
--
Gordons projects: https://projects.drogon.net/

radeusnox01
Posts: 3
Joined: Wed Dec 12, 2012 10:54 pm

Re: Using Serial (UART) to start video files

Sun Dec 23, 2012 6:45 am

gordon@drogon.net wrote: Yes.

But it really depends on what you call easy - one mans easy is another mans hard...

What I suspect you'll need to do is write a program that listens to the serial line - and then when they other end sends it some data, the program on the Pi interprets that data (e.g. "play filename") and does the right thing. e.g. launch omxplayer with the given filename, and/or returns an error/success code back to your device...

Easy..

Hard parts might include getting the voltage levels right (Pi is 3.3v) and writing the serial access software (I wrote my own serial library to make it easy - it's part of my wiringPi library)...

-Gordon
Thanks for the reply sir Gordon. I have looked at your wiringPi and downloaded it already to my Rpi using the older method (since the GIT-core thing gives some errors, i dont know why). I will try writing a simple test program first to get a hold of it (I'm new to programming) using the instructions you gave in your website. About the voltage levels, the VR comes with a module that has the option for 5v and 3.3v (good thing :D )

radeusnox01
Posts: 3
Joined: Wed Dec 12, 2012 10:54 pm

Re: Using Serial (UART) to start video files

Mon Dec 24, 2012 3:43 am

Ok, so I am able to run the serialTest code located on your website sir Gordon (http://unicorn.drogon.net/serialTest.c) and confirm a working serial communication.

Next is the code for the actual project. This is how i understood it to go:
//---------------------------------------------------------------------------------------------//
Open serial communication.

Send the hex value "0xAA21" from the Rpi to the VR module to start the recognition process.

Wait for the reply of the VR module (0xCC) confirming and starting recognition.

//continuous loop
Start receiving hex commands from the VR module to the RPi. (I will be using 5 commands which have equivalent values of 0x11, 0x12, 0x13, 0x14, and 0x15)

Using Switch/case statement (or is there something better?) to compare the received values and determine what to do.
//continuous loop

close serial communications

exit application

//-------------------------------------------------------------------------------------------//

Any suggestions, advice, or comment, or anything that needs to be done that i forgot to include?
Thanks in advance!

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using Serial (UART) to start video files

Mon Dec 24, 2012 7:44 am

radeusnox01 wrote:Ok, so I am able to run the serialTest code located on your website sir Gordon (http://unicorn.drogon.net/serialTest.c) and confirm a working serial communication.

Next is the code for the actual project. This is how i understood it to go:
//---------------------------------------------------------------------------------------------//
Open serial communication.

Send the hex value "0xAA21" from the Rpi to the VR module to start the recognition process.

Wait for the reply of the VR module (0xCC) confirming and starting recognition.

//continuous loop
Start receiving hex commands from the VR module to the RPi. (I will be using 5 commands which have equivalent values of 0x11, 0x12, 0x13, 0x14, and 0x15)

Using Switch/case statement (or is there something better?) to compare the received values and determine what to do.
//continuous loop

close serial communications

exit application

//-------------------------------------------------------------------------------------------//

Any suggestions, advice, or comment, or anything that needs to be done that i forgot to include?
Thanks in advance!
Sounds fine to me..

You may need to be careful after the initial open - I've found (as have others!) that the Pi will send a single character 0xF1 down the serial line at 115200 baud... So your initial handshake with the device may have to loop and send the initial command more than once to make sure communications are established...

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “General programming discussion”