Saturday, March 2, 2013

Running the QT5 Cinematic Experience Example on Raspberry Pi

I first saw the QT5 Cinematic Experience video here: 

  • http://www.youtube.com/watch?v=wulbR2R1GpM

The video show cased Raspberry Pi running a very fancy QT5 example. I decided I wanted to give this a try on my Pi as well. Unfortunately it was not very straightforward. If you tried to google for instruction on run QT5 on the Raspberry Pi, it'll take you in circles. 

  • http://qt-project.org/wiki/RaspberryPi_Beginners_guide
    • This instruction assumes you have a main Linux machine that can be used for cross compiling.
  • http://qt-project.org/forums/viewthread/21080
    • This instruction asks you to download the snapshot. However the location no longer exists. 
  • I also tried to use cross-ng to compile my own cross compiler. 
  • Before the cross compiler finishes compiling, I found an existing cross compiler for the Pi. 
  • I then checked out the Qt5 source and tried to compile that using  the cross compiler I downloaded without success.

Took me a couple nights before I figured out exactly what I need to do (turned out to be very simple). Someone backed up a copy of the Qt5 snapshot, and we can simply install from there instead of attempting to build your own cross compiler, cross compiling in Cygwin or Linux, and such. The information came from mainly the following two sources. 

  • http://www.raspberrypi.org/phpBB3/viewtopic.php?f=66&t=15861&p=299166&hilit=qt5#p299166
  • http://quitcoding.com/?page=work#cinex

The following outlines the steps I took to get the QT5 Cinematic Experience demo running:

  1. On the Pi: sudo vi /etc/apt/sources.list
  2. Append: deb http://twolife.be/raspbian/ wheezy main
  3. Exit vi
  4. Issue: sudo apt-get update
  5. Issue: sudo apt-get upgrade // this will take a while. More than an hour for me. 
  6. Issue: sudo apt-get install libqt5-* // this installs all libqt5 libraries
  7. Download the Cinematic Experience source here: http://quitcoding.com/?page=work#cinex
  8. Unzip the source into a folder of your liking. 
  9. Navigate into your unzipped directory. 
  10. Issue: qmake // this will generate the make file 
  11. Issue: make // compile
  12. Issue: ./Qt5_CinematicExperience // run!

Saturday, January 12, 2013

Raspberry Pi: Programming with ALSA

As covered in a previous article, Raspberry Pi can be used to capture and playback audio using a USB sound card. One can do the capture using ALSA utility aplay and arecord, or programmatically using the ALSA API. 

Example recording can be found in list 4 here: 
http://www.linuxjournal.com/article/6735?page=0,2

To accommodate for my setup, I had to: 
  1. Change the hardware from "default" to "plughw:0,0" in snd_pcm_open(). 
  2. I also replaced the write() with an fwrite() to output to a file. 
To install the relevant headers, I had to install the following package: 

sudo apt-get install libasound2-dev

Finally, to do the compile, don't forget to link to the ALSA library using the -l option: 
gcc record.c -lasound

The example code performs the capture at 44100Hz, signed 16 bit, 2 channels, and output to simple raw format without any file headers. To verify the recording, I had to specify all the parameters using aplay: 
aplay -f s16_le -r 44100 -c 2 test.out

Thursday, January 10, 2013

Raspberry Pi Remote Camera Proof of Concept Implementation

As discussed before, the Raspberry Pi has a hardware accelerated H264 encoder and decoder. This allows us to build a remote camera solution. Given that the camera module has not been released, I faked the camera input using an rolling frame buffer.

Implementation can be seen here:
http://www.youtube.com/watch?v=5ac3nU-B4WQ

Implementation details:
  • 720p @ 30fps 
  • UDP transport
The end result is actually quite smooth. Clearly this example can be further extended into video conference application and such. 



Raspberry Pi recording/playback with Sound Blaster Play

Raspberry Pi doesn't come with an andio in jack. Audio in can only be supported using external USB sound card. I bought a Sound Blaster Play for this purpose. 

To enable USB audio output: 
sudo vi /etc/modprobe.d/alsa-base.conf

And comment out line: 
# options snd-usb-audio index=-2

This will enable USB audio output by default. Reboot now: 
sudo reboot

Now to record: 
arecord -D plughw:0,0 -f cd test.wav

To playback: 
aplay test.wav

Note that when recording using a non-standard format: 
arecord -D plughw:0,0 -f s16_le -r 8000 -c 1 -t raw test.raw

Don't forget to insert the -D plughw:0,0 option to force data translation: 
aplay -D plughw:0,0 -f s16_le -r 8000 -c 1 -t raw test.raw

Thursday, December 20, 2012

Git & BitBucket

To use BitBucket and Git:

  1. Create a repository on BitBucket first. 
  2. Create a new folder of interest in your development environment. 
  3. Add some files. 
  4. Type "git init" to initialize the current folder as repository. 
  5. Type "git add ." to add all files. 
  6. Type "git commit -m "Initial."" to perform initial commit. 
  7. Type "git push https://bitbucket.org/user/new_repo master" to push changes into your new BitBucket repository. 

Sunday, October 7, 2012

Raspberry Pi Setup

After loading the Raspberry Pi image, the device boots into the raspi-config tool. But since the Pi is powered off a USB port off my desk (not recommended by the manual, presumably because the USB port may or may not supply enough current), I'd like to do some additional setup to facilitate my development process: 

1. Wifi setup

Wifi setup was fairly straight forward with a compatible Wifi dongle. I bought the Asus N10 from a local retailer and followed the instruction here: http://www.raspberrypi-tutorials.co.uk/set-raspberry-pi-wireless-network/

More specifically, all I had to do was: 

sudo vi /etc/wpa.config

And add: 

network={
ssid="MY_SSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="WPA-PASSWORD"
}

Then: 

sudo vi /etc/network/interfaces

And add: 

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa.config

And restart the network interface: 

sudo /etc/init.d/networking restart

Now I can ssh into the Pi using Putty. 

Edit: 
I tried to set this up with using a keyboard connected, the Pi had problem reading the conf file and led to wpa_supplicant failure, even though the dongle was detected correctly (ifconfig shows wlan0). 

I think this is relating to the default keyboard layout of the Pi and the fact I'm using an international keyboard. 

I connect the Pi locally using an ethernet cable, ssh'ed into the Pi and re-wrote the config file and issued ifdown and ifup to wlan0. The interface came up correctly. 

2. Disable overscan 

When my Pi boots up there's a black margin around the console. I'm not sure why this happens, but all I had to do was to disable overscan: 

sudo vi /boot/config.txt

Uncomment the following line: 

disable_overscan=1

Power cycle the Pi. 

3. Extend the partition

By default the image has a partition of < 60M. To extend that: 

sudo raspi-config

And select: 

expand_rootfs

Wait and reboot. Note that the resizing on the next boot will take a bit of time. My 16GB took about 15 minutes or more. 

4. Mount the Windows share drive: http://www.swerdna.net.au/susesambacifs.html

mount -t cifs -o username=guest,password=guest //192.168.1.100/share /mount/share

5. Install pv (file copy with progress indicator): http://www.commandlinefu.com/commands/view/5107/copy-a-file-using-pv-and-watch-its-progress

sudo apt-get install pv
pv source > destination



Free Private Online Repository

I recently discovered a free online code hosting service: Bitbucket (https://bitbucket.org/). 

Most other services I looked at previously forces the code to be open sourced if not paid. The biggest bonus for Bitbucket is that it provides free private online repository service (but only with up to a limited developers per project). 

However, for my purpose (private projects on the sides and such), it's sufficient.