Convergence
multimedia and home automation (at a very low cost)
………………………………………………………………………
1.Aim of the project
The mission of this project is to define an optimal hw-sw configuration for a home PC.
Hereafter, you can find the needed specifications:
- TV-set connection as:
- mediaplayer
- DVB-T receiver (TBI)
- SAT receiver (TBI)
- phone line connection (PSTN) to forward VOIP in/out coming calls (TBI)
- voice control commands (home light control, knowledge easy access, …) [Ref.5]
- webradio/media with external audio amplifier connection
- anti theft home security system (TBI) [Ref.1]
- remote login/connection [Ref.2]
- infrared remote control/ed
- remote control via smartphone app [Ref.4]
2.Project implementation with Raspberry PI
2.1.Choice of the sw
2.1.1.Available Operating Systems
This distribution is derived from Debian, and it has been created specifically for RaspberryPI systems.
This distribution is still derived from Debian, but built around XBMC mediacenter. It’s slightly more unstable, but it can handle more components in an easier way (the Raspbmc Settings internal module is already enabled to manage external USB DAC, firewall, ssh, remote control, etc.) [Ref.3]
How to write down an image
To install an O.S. image on an SD card, you can follow the official RaspberryPI organization online guide
2.1.2.Available Applications/oth.
- Desktop environment (e.g. LXDE, with xserver-xorg, xinit, xserver-xorg-video-fbdev, lxde, lxde-common)
2.2.Needed elements
- power supplier
- box (minimum size 60x90x25mm)
- SD card (suggested 8GB)
- external HDD/USB key (self-powered or connected to self-powered usb hub)
- self-powered USB hub (to enhance driving capability of the system)
- analog modem (only for pstn interface purposes)
- USB2Serial converter
- DTT receiver
- SAT receiver
- wireless keyboard with touchpad
- Composit (or HDMI) to VGA converter (not needed if a hi-res TV-set is available or using a SSH remote connection)
- USB external audio DAC
- ethernet connection
- Heatsinks set for overclocking (e.g.:https://www.futurashop.it/index.php?route=product/product&filter_name=raspberry&page=3&product_id=6358 )
- Expansion Shield with IN/OUT ports (e.g.:https://www.futurashop.it/index.php?route=product/product&filter_name=raspberry&page=3&product_id=6419 )
- Phototransistor TSOP38238
- External audio amplifier and speakers
- static IP address or equivalent
In red: implemented elements in the first phase of the project
3.SW evaluation
3.1.Raspbian
(linux distribution)
“Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware. An operating system is the set of basic programs and utilities that make your Raspberry Pi run. However, Raspbian provides more than a pure OS: it comes with over 35,000 packages, pre-compiled software bundled in a nice format for easy installation on your Raspberry Pi.” [Ref.10]
3.1.1.Setting up the system
For keyboard set up, from the shell, run:
raspi-config
To run GUI:
startx
3.1.2.Programs to install
(keep the sequence)
From the shell, install synaptic:
sudo apt-get install synaptic
From Synaptic, install:
tightvncserver
php5
php-pear
From the shell, install asterisk (check if ok with sudo asterisk -r) and FreePBX, following the installation steps
Store the following in /etc/apt/sources.list.d/mene.list:
deb http://archive.mene.za.net/raspbian wheezy contrib
and import the archive signing key:
and import the archive signing key:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 5243CDED
Installation (use kodi in last versions, instead of xbmc):
sudo apt-get update
sudo apt-get install xbmc
sudo apt-get install xbmc
From Synaptic, install:
gnash
vlc
csh
nedit
gimp
hplip-gui (for Hp printers)
libreoffice
gufw (graphic interface to set up firewall)
linphone
3.1.3.Issues
a) No possible to get external usb audio card working. To bypass this issue, you can try to install Raspbmc Settings Add-on (some incompatibility problems):
wget http://download.raspbmc.com/downloads/bin/xbmc/raspbmc-plugin.tar.gz
sudo tar -xzf raspbmc-plugin.tar.gz -C ~/.xbmc-current/xbmc-bin/share/xbmc/addons
rm raspbmc-plugin.tar.gz
sudo initctl stop xbmc
sudo initctl start xbmc
b) There are some problems installing asterisk from PIStore, so it’s better to proceed from synaptic
c) PulseAudio (some problems during installation [Ref.8], [Ref.9]): usb audio card is not working anyway
3.2.Raspbmc (*)
(linux distribution)
Raspbmc is an XBMC and linux-based OS distribution for Raspberry Pi, created and maintained by Sam Nazarko.
Here you can find a description of XBMC in the distribution.
To reconfigure keyboard:
sudo dpkg-reconfigure keyboard-configuration
To reconfigure locales:
sudo dpkg-reconfigure locales
To get shell line:
Activate/disable services from XBMC
Select Program -> Raspbmc Settings:
Be sure the vnc server is disabled, because it’s too heavy and it brings out only xbmc screen!
cronjob scheduler
Disable Firewall (to allow connection from external network, but sometimes it seems irrelevant)
System, Audio Output:
Install from CLI:
csh
lxde (sudo apt-get install lxde)
tightvncserver
synaptic
(midori: NO, because this installation makes unstable the system)
3.3.Downloading images
3.4.Asterisk
(not yet implemented)
Asterisk and the Apache web server need considerable amount of RAM. Especially on the 256MB model RAM might become quite low when running X Windows at the same time. To overcome this, you can either shut down X Windows (or not boot into X Windows at all), and use the FreePBX web GUI from another computer on the network.
If you want to work with X Windows, shut down Apache from a root shell:
service apache2 stop
Asterisk can be shut down with:
amportal stop
To start them again run:
service apache2 start
amportal start
3.5.XBMC
If you choose a distribution without XBMC/KODI included (e.g. Raspbian), you can install prebuilt XBMC packages. Please, go here.
To run XBMC after installation: xbmc-standalone
Repositories:
Setting usb audio card (*)
To set external usb audio card to be used for videos too, you have to set up dvdplayer option. [Ref. 11]
If not already done, create a text file called advancedsettings.xml and place it in /home/pi/.xbmc/userdata
Content should be:
Code:
<advancedsettings>
<video>
<defaultplayer>dvdplayer</defaultplayer>
</video>
</advancedsettings>
To safely unmount drives
From System > File Manager, select the disk to umount and press "C" on your keyboard, there should be an option to securely unmount it
To backup/reload XBMC/KODI configuration
- Login to the pi and, from the /home/pi/ folder, type:
tar -czf backup.tar.gz .xbmc/
or
tar -czf backup.tar.gz .kodi/
- Transfer that file to a secondary machine (ftp, sftp, or scp are all available options)
To put back the backup on the system:
- Move the tar file you copied in step 2 above to the Raspberry Pi
- Run the following commands:
sudo initctl stop xbmc; tar -xzf backup.tar.gz; rm backup.tar.gz; sudo initctl start xbmc
4.Voice control/recognition
To get voice recognition and synthesis, we can install local or remote services.
There are lot of projects getting voice synthesis (festival, mbrola, sphinix, espeak), but I chose to implement Voicecommand from Steven Hickson’s project. [Ref. 12] (*)
This project is using google APIs to manage voice recognition and synthesis, and it is able to control Raspberry PI I/O pins according voice commands.
Installation ([Ref. 13]) (*)
sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh
Voicecommand setup instructions
voicecommand -s
Update Instructions
cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh
Hereafter the dependencies required to run and build:
sudo apt-get install libboost1.50-dev libboost-regex1.50-dev youtube-dl axel curl xterm libcurl4-gnutls-dev mpg123 flac sox
How to run voicecommand in background:
1) set the .command.conf file
2) run:
voicecommand &>/dev/null
CTRL-z
bg
2b) you cannot run voicecommand in background, then closing the remote SSH session
Ps: think of a cronjob to run voicecommand if it crashed
How to make some other tests:
Microphone capture and getting device name:
e.g.:
Different text2speech systems:
Lamps and multimedia voice control: http://computers.tutsplus.com/articles/how-to-control-a-lamp-with-voice-commands-and-a-raspberry-pi--mac-60825
5.Security
The security surveillance mode can be performed via video/audio devices.
Currently, I’m not implemented it.
1) webcam
2) microphone
6.Remote login
Knowing public IP address and setting up the modem port forwarding, you can access your media system via remote login, to check and control it.
Setting up Dynamic DNS service updates
If you don’t have a public static IP address, you can use a software that will update your current IP address, using an external full service provider [Ref. 14]:
- You can compile & install their own updating daemon or you can install ddclient from the standard repository or you can set up your modem if noip is available in its settings(*)
- sudo apt-get install ddclient
- answer to the questions during installation (username, pwd, protocol dyndns2, etc.)
- then sudo nano /etc/ddclient.conf
- protocol=dyndns2
- use=web, web=checkip.dyndns.com/, web-skip='IP Address'
- server=dynupdate.no-ip.com
- login=yourusername
- password=yourpassword
- yourhostname.no-ip.org
- to set the number of seconds between updates, add: daemon=600
- to use ssl, add: ssl=yes
- restart the client: sudo /etc/init.d/ddclient restart
- to ensure the configuration is working: sudo ddclient -daemon=0 -debug -verbose -noquiet
How to get external IP address
Instead of using a full service provider, you can manage to know your own public IP address using free services, like myexternalip.com, and writing some scripts with the commands provided, saving your IP in the Internet.
Hereafter, some other examples:
How to upload the IP address file to the internet without any supplier
- You can make a script to get the current external IP address and to save it to the internet
- You can set up a Cron to run the previous script periodically (e.g. 15 minutes)
- Set the modem/router to port forwarding TCP port:22 to the Raspy internal IP (needed to assign internal fixed IP, e.g. 192.168.1.xxx)
crontab -e
Vnc (*)
sudo apt-get update
sudo apt-get install vnc-server
sudo apt-get install vnc-server
After vncserver installation, run vncserver to set password:
vncserver
Run the VNC client using the chosen password for the server on port number 5901.
To stop the vnc server on the raspberry:
vncserver -kill :x
where x is the display number.
To make vnc server always available at start up, use cron command:
crontab -e
and add line:
@reboot /usr/bin/vncserver (NOT working, at this moment!!!)
As you can see, before you use apt-get, try to run update command first, otherwise you may encounter some 404 not found errors.
sudo apt-get update
FreeNX
As an alternative to VNC, there are some other tools (e.g. FreeNX):
http://www.tiaowiki.com/w/Install_NX_Server_on_Raspberry_Pi (needs compilation)
Command:
sudo apt-get install xutils-dev expect xorg-dev libjpeg8-dev libpng12-dev
NX server also requires CUPS, xfonts-base and x11-xserver-utils, thus you need to install it as well:
sudo apt-get install cups
sudo apt-get install xfonts-base
sudo apt-get install x11-xserver-utils
sudo apt-get install xfonts-base
sudo apt-get install x11-xserver-utils
Teamviewer
- Teamviewer is not supported for ARM architecture (but for win8/surface)
- Try to run tar.gz package without any installation, downloading it from: http://www.teamviewer.com/en/download/linux.aspx
7. IR Remote Control/ed
Receiver (*):
- connect the IR receiver (TSOP38238) according schematics (3.3V, GND, GPIO18)
- open the “Raspbmc Settings” (Raspbmc distribution) and be sure the “Enable GPIO TSOP IR Receiver” option is not set. Otherwise, unset it and restart XBMC
- connect to the Raspberry via SSH
- sudo modprobe lirc_rpi
- sudo kill $(pidof lircd)
- mode2 -d /dev/lirc0
- pressing buttons on the remote will display pulse/space codes on the monitor
- via SSH, type the command “irrecord –list-namespace”, to know the allowed key names for the following process
- type the command “irrecord -d /dev/lirc0 ~/lircd.conf” to generate the config file
- open “Raspbmc Settings” and enable “Enable GPIO TSOP IR Receiver”
- set the “GPIO Remote Profile” to “Custom (lircd.conf)”
Transmitter (*):
- connect the IR Transmitter schematics (5V, GND, GPIO22)
- open the “Raspbmc Settings” (Raspbmc distribution) and be sure the “Enable GPIO TSOP IR Receiver” option is not set. Otherwise, unset it and restart XBMC
- Add this to your /etc/modules file:
lirc_dev
lirc_rpi gpio_out_pin=22
- Change your /etc/lirc/hardware.conf file to:
LIRCD_ARGS="--uinput"
DRIVER="default"
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
- connect to the Raspberry via SSH
- sudo modprobe lirc_rpi
- sudo kill $(pidof lircd)
- mode2 -d /dev/lirc0
- pressing buttons on the remote you want to clone, will display pulse/space codes on the monitor
- via SSH, type the command “irrecord –list-namespace”, to know the allowed key names for the following process
- type the command “irrecord -d /dev/lirc0 ~/lircd.conf2” to generate the config file with the given names of step j (even if not the final ones)
- copy from begin remote to end remote from lircd.conf2 to lircd.conf file (already set in IR Receiver setting) and set the remote control name after the keyword name, and the final button names
- Now restart lircd so it picks up these changes:
sudo /etc/init.d/lirc restart
- run one of the programmed buttons with:
irsend SEND_ONCE Remote_Name PROGRAMMED_BUTTON
Issue: problems to make it works at the same time as the XBMC remote control, so as soon as you’ll enable again the Raspbmc IR Receiver, the IR Transmitter will stop working.
Solution:
http://www.lirc.org/html/configure.html (?) http://www.raspberrypi.org/forums/viewtopic.php?f=37&t=51900 (?)
sudo /etc/init.d/lirc restart
8. DVB-T receiver
To implement a DVB-T receiver, you can follow the tutorial [Ref. 21]
Here you can find compatible DVB-T USB devices for Linux kernels.
9. Issues
Hereafter, you can find some popular issues.
1) No more space left on SD root partition:
a) apt-get clean
b) "Expand Filesystem" option in raspi-config
2) Audio problem using external usb card
cat /proc/asound/cards
lsmod | grep "snd"
lsmod | grep "snd"
Run:
alsamixer
and choice the right card (F5)
3) Setting date/time
If the procedure to localize your system is not working, you can run the command:
tzselect
Add the corresponding TZ=’xxx/yyy’; export TZ in your .profile file, then log out and log in
3) High CPU usage (>30%)
Disable the weather visualization in home page of XBMC
Disable the vnc server from XBMC (better to install in LXDE instead)
Due to a bug in udisks, changing /etc/udisks-glue.conf is useless.
To get a spindown timeout of 30 minutes (1800 seconds):
sudo /etc/rc.local
sudo udisks --set-spindown /dev/sda --spindown-timeout 1800
Others from literatures:
5) Back up of your SD card (Linux):
1) Shrink down (200 MB) the main partition of the SD card using Gparted, with respect to maximum SD card capacity.
2) Get the dev name of the SD card:
df -h
3) Make the dump:
sudo dd bs=4M if=/dev/mmcblk0 | gzip > pi.gz
4) To flash the new card:
gzip -dc pi.gz | sudo dd bs=4M of=/dev/mmcblk0
To check the job progress, write this command in another terminal:
sudo pkill -USR1 -n -x dd
6) Overclocking
If your device is in stuck due to OC:
a) get the SD card
b) put it in your pc
c) visit the boot partition and edit the config.txt file to set the parameters correctly
7) Raspberry Pi Won't Record from USB Microphone (http://www.raspberrypi.org/forums/viewtopic.php?t=39480&p=345955)
9.Raspberry PI pin diagram
10.Power consumption
Using an energy counter I measured the energy used by the system (RaspberryPI, self powered USB hub, plm for internet connection) and the average power was less than 5W.
This result would confirm it is cheap and convenient to keep the system up 24/7.
11.References
[Ref.1]: Raspberry Pi as low-cost HD surveillance camera
[Ref.2]: Attivare servizio DDNS su No-Ip o altri siti free
[Ref.3]: Raspbmc
[Ref.4]: XBMC Raspberry Pi remote control using a smart phone
[Ref.5]: Raspberry Pi debutta nella robotica
[Ref.6]: XBMC for Raspberry Pi
[Ref.7]: Raspberry Pi USB Webcam User guide
[Ref.8]: Installare e configurare PulseAudio su Debian
[Ref.9]: How-To: Pulseaudio
[Ref.10]: Welcome to Raspbian
[Ref. 11]: USB Audio with Add-Ons
[Ref. 12]: Voice Command v3.0 for the Raspberry PI
[Ref. 13]: Voice Control on the Raspberry PI
[Ref. 14]: Dynamic DNS
[Ref. 15]: RPi Wheezy VNC
[Ref. 16]: Configuring ddclient to update your dynamic DNS at noip.com
[Ref. 17]: Using an IR Remote with a Raspberry Pi Media Center
[Ref. 18]: GPIO IR receiver with RASPBMC
[Ref. 19]: Setting Up LIRC on the RaspberryPI
[Ref. 20]: Raspberry Pi Universal Remote
[Ref. 21]: Tutorial: Raspbmc PVR TinyUSB2 DVB-T & TVHeadend All-in-one
[Ref. 22]: External USB Drive - Automatic spindown using udisks-glue
Legend
TBI: To Be Implemented
(*): chosen implementation
“Convergence-Multimedia and home automation” by Alex Pojer is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.