Raspberry PI Adventures

Featured

raspberry_pi_logoIn this blog I will keep you informed about my Raspberry PI adventures!

You will find useful and interesting tips and tricks for beginning Raspberry PI users.

For questions and / or comments feel free to send an email to: info@cagewebdev.com

HOW TO…

  1. …open your Raspbmc favorites with one keypress?
  2. use your Android phone as a remote control for your Raspbmc Media Center?
  3. install Raspbmc Media Center on your Raspberry PI?
  4. …install OpenElec / XBMC Media Center on your Raspberry PI?
  5. …use Unix commands on your Raspberry PI?
  6. …run cool apps on your Raspberry PI?
  7. …show some system info with a Python script?
  8. bind actions to (hot)keys?
  9. …create a backup image of your SD card while your Raspberry PI is running?
  10. …play internet radio on your Raspberry PI?
  11. …take screenshots on your Raspberry PI?
  12. …execute a shell script on your Raspberry PI?
  13. …check your Raspberry PI’s file system?
  14. expand the root partition of your Raspberry PI’s SD card?
  15. send a boot email from your Raspberry PI?
  16. …access your Windows shares from your Raspberry PI?
  17. …update your Raspberry PI’s firmware?
  18. …list the installed packages on your Raspberry PI?
  19. …run Processing on your Raspberry PI?
  20. …add menu items to the start menu of your Raspberry PI?
  21. …add the PI Store to your Raspberry PI?
  22. duplicate your Raspberry PI’s SD-card?
  23. …to add a new shortcut to your Raspberry PI’s desktop?
  24. …get the audio working on your Raspberry PI?
  25. …use a remote desktop with your Raspberry PI?
  26. …play Flash movies (YouTube!) in Midori on your Raspberry PI?
  27. …create a simple Python web server on your Raspberry PI?
  28. …put your Raspberry PI in TURBO Mode?
  29. …mount your network drive on your Raspberry PI?
  30. remove applications from your Raspberry PI?
  31. …update the system software on your Raspberry PI?

ENJOY!

Raspberry PI

Raspbmc – open your favorites with one keypress

raspberry_pi_logo
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:
    <keymap>
      <global>
        <keyboard>
          <F1>ActivateWindow(Favourites)</F1>
        </keyboard>
      </global>
    </keymap>
    (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!

Raspberry PI – using your Android phone as a remote control for Raspbmc

raspberry_pi_logo
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
Usercode: xbmc
Password: [empty]

After entering the new host info choose ‘Remote Control‘ and there you go!

xbmc

Enjoy!

Resources:
https://play.google.com/store/apps/details?id=org.xbmc.android.remote
http://wiki.xbmc.org/index.php?title=Raspbmc/FAQ

Raspberry PI – installing Raspbmc media center

raspberry_pi_logo
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:
    ‘Install
  • 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

Useful resources:
http://wiki.xbmc.org/index.php?title=Raspberry_Pi
http://www.raspbmc.com/wiki/user/windows-installation/

Raspberry PI – installing OpenElec / XBMC media center

raspberry_pi_logo
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.

notes:

  • 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

Great resources:
http://squirrelhosting.co.uk/hosting-blog/hosting-blog-info.php?id=9
http://www.gaducated.com/the-perfect-xbmc-setup-on-the-raspberry-pi/

Raspberry PI – using Unix commands

raspberry_pi_logo
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:
    /opt/vc/bin/vcgencmd measure_temp
  • get the current firmware version of your RPi:
    /opt/vc/bin/vcgencmd version
  • find the MAC address of your RPi:
    cat /sys/class/net/eht0/address
  • show all mounts:
    df -h
  • show all installed packages:
    dpkg –get-selections
    find a specific package:
    dpkg –get-selections | grep <package name>
  • list all files in a directory (last modified files last):
    ls -lrt
  • 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)
    sudo -i
  • synchronize the date and time of your RPi:
    sudo dpkg-reconfigure tzdata
  • find the IP-address of your RPi:
    sudo ifconfig
  • list all loaded drivers:
    sudo lsmod
  • list all connected USB devices
    sudo lsusb
  • edit the Raspberry PI boot configuration file:
    sudo nano /boot/config.txt
  • change the system configuration of your RPi:
    sudo raspi-config
  • reboot your RPi:
    sudo reboot
  • list the most active system processes (quit by pressing ‘q’)
    top

Raspberry PI – running COOL apps

raspberry_pi_logo
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.

MEDIA

  • audio utilities for your PI:
    sudo apt-get install alsa-util
    more…
  • play mp3 files on your PI:
    sudo apt-get install mpg321
    more…
  • wav to mp3 converter:
    sudo apt-get install lame
    more…
  • play all kinds of media files on your PI using the VLC media player:
    sudo apt-get install vlc

ACCESSORIES

  • 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-calc: Spreadsheet
    libreoffice-impress: Presentation
    libreoffice-draw: Drawing
    libreoffice-base: Database
    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
    more…

Raspberry PI – showing some system info with a Python script

raspberry_pi_logo
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:
    import subprocess
    import os
    def get_ram():

        “Returns a tuple (total ram, available ram) in megabytes. See www.linuxatemyram.com”
        try:
            s = subprocess.check_output(["free","-m"])
            lines = s.split(‘\n’)       
            return ( int(lines[1].split()[1]), int(lines[2].split()[3]) )
        except:
            return 0def get_process_count():
        “Returns the number of processes”
        try:
            s = subprocess.check_output(["ps","-e"])
            return len(s.split(‘\n’))       
        except:
            return 0def get_up_stats():
        “Returns a tuple (uptime, 5 min load average)”
        try:
            s = subprocess.check_output(["uptime"])
            load_split = s.split(‘load average: ‘)
            load_five = float(load_split[1].split(‘,’)[1])
            up = load_split[0]
            up_pos = up.rfind(‘,’,0,len(up)-4)
            up = up[:up_pos].split(‘up ‘)[1]
            return ( up , load_five )       
        except:
            return ( ” , 0 )

    def get_connections():
        “Returns the number of network connections”
        try:
            s = subprocess.check_output(["netstat","-tun"])
            return len([x for x in s.split() if x == 'ESTABLISHED'])
        except:
            return 0

    def get_temperature():
        “Returns the temperature in degrees C”
        try:
            s = subprocess.check_output(["/opt/vc/bin/vcgencmd","measure_temp"])
            return float(s.split(‘=’)[1][:-3])
        except:
            return 0

    def get_ipaddress():
        “Returns the current IP address”
        arg=’ip route list’
        p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
        data = p.communicate()
        split_data = data[0].split()
        ipaddr = split_data[split_data.index('src')+1]
        return ipaddr

    def get_cpu_speed():
        “Returns the current CPU speed”
        f = os.popen(‘/opt/vc/bin/vcgencmd get_config arm_freq’)
        cpu = f.read()
        return cpu

    print ‘Free RAM: ‘+str(get_ram()[1])+’ (‘+str(get_ram()[0])+’)’
    print ‘Nr. of processes: ‘+str(get_process_count())
    print ‘Up time: ‘+get_up_stats()[0]
    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:
    python /home/pi/Code/system_info.py

There are many more system settings that could be added to the script! ;-)

Raspberry PI – binding actions to (hot)keys

raspberry_pi_logo
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:
    <keybind key=”F4″>
      <action=”Execute>
        <command>lxterminal</command>
      </action>
    </keybind>
    <keybind key=”F5″>
      <action=”Execute>
        <command>gksu /usr/bin/x-terminal-emulator</command>
      </action>
    </keybind>
  • 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.

 

Raspberry PI – creating a backup image while the Raspberry PI is running

raspberry_pi_logo
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/fstabs
  • 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)

Good luck!