How to bind actions to (hot)keys?
I want to define a key for starting the lxterminal on my Raspberry PI.
This is how you can do it:
- Open the LXDE configuration file:
sudo nano ~/.config/openbox/lxde-rc.xml
- In the <keyboard>(…)</keyboard> section add the following lines of code:
- Reboot the PI:
sudo shutdown -r now
When it’s back up-and-running, pressing the <F4>-key will launch the LX Terminal and the <F5>-key will launch the Root Terminal.
How to open your Raspbmc favorites with one keypress?
- navigate to the folder /home/pi/.xmbc/userdata/keymaps
- edit a file called keyboard.xml (create one if it doesn’t exist yet!)
- add the following text to the file:
(of course you can replace <F1> by a different key)
- Reboot the PI:
sudo shutdown -r now
Now your ‘favorites menu’ will appear anytime you press your <F1>-key!
How to use your Android phone as a remote control for your Raspbmc Media Center?
On your Android phone go to https://play.google.com/store/apps/details?id=org.xbmc.android.remote and install the Official XBMC Remote app.
Run the app and choose ‘Add new host‘.
Then you have to enter the local IP-address of your PI, for instance: 192.168.0.105.
Port number: 80
After entering the new host info choose ‘Remote Control‘ and there you go!
How to install Raspbmc Media Center on your Raspberry PI?
- insert a SD-card in your reader
- first click:
‘Restore SD card for formatting‘
- then check ‘I accept the licence agreement’ and click:
- take the card out of the reader, put it in your Raspberry PI and boot it (the installation will take quite a while, 20+ minutes!)
- after the installation is done you will get the main XBMC screen, go to Settings > International and adjust your location / time zone
How to install OpenElec / XBMC Media Center on your Raspberry PI?
You can turn your PI into a Media Center for playing Music, Videos and showing Pictures using the OpenElec image.
Here’s how to install it.
- if you want to make a ssh connection to your PI use: usercode = root; password = openelec (usercode and password cannot be changed!)
- you cannot use any remote desktop with OpenElec (it doesn’t support X!)
To stream music, videos and pictures from your (SAMBA) network drive:
- on the XBMC screen navigate to System > OpenElec > Services and ENABLE Samba
How to use Unix on your Raspberry PI?
This will be a useful (growing) collection of Unix / Raspbian commands to use with your Raspberry PI.
- get the current frequency of the RPi CPU:
/opt/vc/bin/vcgencmd get_config arm_freq
- measure the temperature of the RPi CPU:
- get the current firmware version of your RPi:
- find the MAC address of your RPi:
- show all installed packages:
find a specific package:
dpkg –get-selections | grep <package name>
- list all files in a directory (last modified files last):
- check for distro upgrades for your RPi:
sudo apt-get dist-upgrade
- remove an (apt-get) application from your RPi:
sudo apt-get –purge remove <app name> && sudo apt-get autoremove –purge
- update your system software and remove orphans:
sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoremove –purge
- switch to ‘super user‘ terminal window (means you don’t have to use the ‘sudo’ prefix in front of all the following commands)
- synchronize the date and time of your RPi:
sudo dpkg-reconfigure tzdata
- find the IP-address of your RPi:
- list all loaded drivers:
- list all connected USB devices
- edit the Raspberry PI boot configuration file:
sudo nano /boot/config.txt
- change the system configuration of your RPi:
- reboot your RPi:
- list the most active system processes (quit by pressing ‘q’)
How to run COOL apps on your Raspberry PI?
This will be a useful (growing) collection of interesting / useful apps to run on your Raspberry PI.
- audio utilities for your PI:
sudo apt-get install alsa-util
- play mp3 files on your PI:
sudo apt-get install mpg321
- wav to mp3 converter:
sudo apt-get install lame
- play all kinds of media files on your PI using the VLC media player:
sudo apt-get install vlc
- libreoffice (a great opensource MicroSoft Office / Open Office clone):
sudo apt-get install libreoffice-writer libreoffice-calc libreoffice-impress libreoffice-draw libreoffice-base libreoffice-math libreoffice-filter-mobiledev
Just delete the modules you don’t want to install from the above list:
libreoffice-writer: Word processor
libreoffice-math: Equation editor
libreoffice-filter-mobiledev: Mobile Devices filters
- Chromium (Google web browser):
sudo apt-get install chromium
- Joe’s Editor: user friendly Unix text editor (my favorite!):
sudo apt-get install joe
- Midnight Commander (MC) is a “Swiss army knife” for the Linux console and other terminal environments
sudo apt-get install mc
- RDP remote desktop server for connecting to your PI remotely:
sudo apt-get install xrdp
How to show some system info with a Python script?
- Create a Python script, for instance in a directory called /home/pi/Code (create the directory if it doesn’t exist yet):
sudo nano /home/pi/Code/system_info.py
- Add the following code to the file:
“Returns a tuple (total ram, available ram) in megabytes. See www.linuxatemyram.com”
s = subprocess.check_output([“free”,”-m”])
lines = s.split(‘\n’)
return ( int(lines.split()), int(lines.split()) )
return 0def get_process_count():
“Returns the number of processes”
s = subprocess.check_output([“ps”,”-e”])
return 0def get_up_stats():
“Returns a tuple (uptime, 5 min load average)”
s = subprocess.check_output([“uptime”])
load_split = s.split(‘load average: ‘)
load_five = float(load_split.split(‘,’))
up = load_split
up_pos = up.rfind(‘,’,0,len(up)-4)
up = up[:up_pos].split(‘up ‘)
return ( up , load_five )
return ( ” , 0 )
“Returns the number of network connections”
s = subprocess.check_output([“netstat”,”-tun”])
return len([x for x in s.split() if x == ‘ESTABLISHED’])
“Returns the temperature in degrees C”
s = subprocess.check_output([“/opt/vc/bin/vcgencmd”,”measure_temp”])
“Returns the current IP address”
arg=’ip route list’
data = p.communicate()
split_data = data.split()
ipaddr = split_data[split_data.index(‘src’)+1]
“Returns the current CPU speed”
f = os.popen(‘/opt/vc/bin/vcgencmd get_config arm_freq’)
cpu = f.read()
print ‘Free RAM: ‘+str(get_ram())+’ (‘+str(get_ram())+’)’
print ‘Nr. of processes: ‘+str(get_process_count())
print ‘Up time: ‘+get_up_stats()
print ‘Nr. of connections: ‘+str(get_connections())
print ‘Temperature in C: ‘ +str(get_temperature())
print ‘IP-address: ‘+get_ipaddress()
print ‘CPU speed: ‘+str(get_cpu_speed())
- Save the file and make it executable:
sudo chmod +x system_info.py
- Execute the script:
There are many more system settings that could be added to the script! 😉
How to create a backup image of your SD card while your Raspberry PI is running?
You can create a backup (.img) of your SD card to a network / USB drive while the card is inserted in your Raspberry PI!
- make sure you have access to your network drive / usb drive;
to see the devices type:
sudo cat /etc/fstab
- create an img of the card currently in the PI to your network drive / USB drive using the dd command:
sudo dd if=/dev/mmcblk0p2 of=/home/pi/networkdrive/my.img bs=1M
(replace /dev/mmcblk0p2 with your own SD card and /home/pi/networkdrive/my.img with your own network drive / USB drive + image file name)