Blog

Interesting topics about electronics, product development and more.

Writing applications for the Raspberry Pi

by Timo Stehmann11. June 2013 22:33

For those who don't know what the Raspberry Pi is: The Raspberry Pi is a single-board PC. It is based on an ARM processor and uses an SD card as "hard-drive". Compared to PCs of 10 to 20 years ago, this is an amazing device. Now you can buy a PC for less than R600.

 

The Raspberry Pi.

However, this is not the whole story. You still need to add the cost for an enclosure and USB power supply. If you don't have a display with HDMI input you also need to buy an HDMI to VGA converter. In addition, there are only two USB ports and if you want to connect more USB devices it is advisable to get a self-powered USB hub. This all adds up and in the end it can cost more than R1300 to have a fully functional PC based on the Raspberry Pi (excluding display, keyboard and mouse). Not that cheap anymore if you consider that you can buy a PC on specials for about R3000. However, the reduced cost does attract attention and often emotions and not common sense favour the Raspberry Pi. So ... how to develop software for the Raspberry Pi?

 

Build environment for the Raspberry Pi

I needed to port software written for modern PCs to the Raspberry Pi. It is possible, but as your applications grows I can just see the source code being infected with #ifndef RASPBERRY (yes, this is C++) to filter out features that require too much resources on the Raspberry. It is not advisable to compile directly on the Raspberry. The first problem is to set-up and environment to cross-compile for the Raspberry on a decent PC. For this, a Linux environment is required. There two ways to go about this. Either you already have a PC with Linux, if not, you can run it as a virtual machine on your Windows machine. I used an Ubuntu 10.04 virtual machine. Complete Ubuntu images are available for free on the net and can be run using VMPlayer, which is also available for free. Why Ubuntu 10.04? Well, I had less problems with it and I also use it to compile applications for other Linux distributions. When developing C++ applications for Linux it is advisable to use older Linux distributions, because they use older libraries, which will work on newer and older versions of Linux. Ubuntu 10.04 is also an LTS (long-term support) version.

The next step is the set-up of a build environment for your application. In my case I use C++ with Qt. Qt is a great platform for cross-platform development, even for the Raspberry. Even if you don't use Qt for your applications, it can still be useful to use Qt make tools (e.g. qmake, etc.). The following link has a detailed description on how to set-up your build environment using "Qt Raspberry beginner's guide".

The second problem is to obtain the required packages for the Raspberry Pi to compile your applications. Remember: you are cross-compiling and can be difficult to get the required Linux packages on your build machine. Using "sudo apt-get install" will not work. One possible way to get around this problem is to use your Raspberry Pi:

 

The chances are good that your PC is running on a network. If not ... what is wrong with you??? Sorry, just joking. You can set-up a samba server on your Raspberry and connect it to the network (i.e. network hub). The shared directory on your Raspberry can then be mounted on your Linux PC or virtual machine. I just shared the root directory of my Raspberry Pi. If you go this route, then there is no need to download the Raspberry image onto your Linux PC and mount it as described in the Qt beginner's guide. Instead of mounting the Raspberry image, it is possible to mount the Raspberry shared root directory. If you require any additional packages, then you can just install them directly on your Raspberry.

Here is the Samba config file I used (/etc/samba/smb.conf) on the Raspberry:

[global]
workgroup = LINUX
server string = %h
wins support = no
dns proxy = no
security = user
encrypt passwords = yes
panic action = /usr/share/samba/panic-action %d
[Root]
comment = Root
path = /
writable = yes
browseable = yes
read only = no
guest ok = yes
force user = root

Then on your Linux PC or VM you can mount the Raspberry drive:

sudo mount -t cifs -o guest  //192.168.0.2/Root/ /mnt/rasp-life

Note: use the correct IP address (in my case it was 192.168.0.2) and you can change the name of the mount (in my case I used rasp-life). Use /mnt/your-mount-name instead of /mnt/rasp-pi-rootfs/ in the Qt Raspberry Pi beginner's guide.

 

Building apps using Qt

As mentioned earlier, Qt is a great platform to develop cross-platform GUI applications. When writing software make sure to use the correct qmake to generate Makefiles for the cross-compiler. The steps outlined in the Qt Raspberry Pi beginner's guide will create the correct qmake executable for you. Use this qmake to generate your Makefiles. You can even specify a target directory on your Raspberry Pi to install your compiled application. If you use Qt, make sure to compile xcb support. Your Raspberry will most probably not have the required packages. You can install them with "apt-het install xcb" command on your Raspberry.

 

Using the Raspberry Pi in commercial applications

There are two ways to use the Raspberry: integral part of your product (i.e. shipped together with your product) or as a target platform for people who have a Raspberry Pi. The first approach is of course preferable since you have full control over the device and can ship it with all the required packages to run your software. The second approach is more problematic. If you want to use the general IO pins on the Raspberry, then this becomes even more problematic. The IO functionality of the Raspberry seems to change for different versions and it is not always clear how it changed. If you are just using the IO pins to generate logic high and low levels, then there should not be a problem. However, more complex interactions, like SPI interfacing, could be problematic. I do not have enough experience regarding the IO functionality. However, from what I read I am not feeling comfortable to use them for commercial applications where the Raspberry is not shipped as part of your product.

The Raspberry can require a lot of additional hardware. As mentioned earlier: HDMI to VGA converter, USB hub, power supply, etc. Packaging all this can be a challenge. It does not help to put the Raspberry in its own enclosure if there are 3 to 4 external hardware components ... it just looks bad.

Still, adding the cost of a display, keyboard and mouse, the total cost for a Raspberry-based solution can be signifcantly cheaper compared to other solutions. However, it can introduce additional overhead. Especially, if a product is targeted for other platforms (i.e. Windows and other "standard" Linux PCs). Consider your options carefully and if it is viable hop onto the Raspberry bandwagon.

 

Tags:

Software

Permalink | Comments (0)

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading