Introduction
In this fourth article of the series Essential Raspberry Pi Peripherals we will see how to install the Pi Camera and the 2.4" Touch Panel on the Raspberry PI 2 . In the next article we will use this base setup to make a PI Camera where the PiFace CAD LCD display is be replaced by the 2.4" Touch Panel.
The components we are using are shown in the image below including a small and almost inexpensive (about 5$) LinkSys WiFi USB dongle and a class 10 8Gb Micro SD card.
Note: if you have only one of the two devices you can follow this guide excluding the parts that refers to the other (the camera or the touch panel) alternatively.
But it's not all! As we are trying to modernise the PiFace CAD based Raspberry Camera, why not starting with Jessiehttps://www.raspberrypi.org/downloads/raspbian/, the new, updated Debian Linux distribution for the Raspberry PI 2?
Raspbian Jessie installation
Jessie is the latest updated distribution of the Raspian version, a Debian distro for the Raspberry PI. This new version in my opinion it is the worth to use it because the new 4.x Linux kernel and a series of improvements specific for the Raspberry PI platforms gives the clear impression to be a mature version than the previous. After creating the bootable image on a microSD card you should just insert it in the board and power it on. There is plenty of tutorials online on how to prepare the Raspbian bootable microSD card but the better way, covering all the desktop platforms is on the raspberrypi.org site from where you can also download the last updated Jessie image file.
Just from the first boot you immediately see that process is extremely fast. Better if you have done this with the previous Linux versions to see the difference.
The most notable feature is the new version of the Raspberry setup directly accessible from the setup. All the options available in the raspi-config command are now accessible through a more comfortable user interface.
The four images above shows the four sections of the Graphical User Interface version of the Raspberry PI settings with the suggested settings for the setup we need.
Note: as far as I know it is not mentioned anywhere but confirming every panel you are asked for reboot despite the changes you apply. I suggest to follow this method (that means four reboot if you change at least one parameter on every panel to be sure that changes are saved permanently. For those who has problems with the previous wheezy version on the locale and keyboard settings, this issue has been solved. After setting the parameters in the fourth panel Localisation the settings are correct and the terminal warning of a wrong locale never appear.
Camera setup
After the linux installation, power off the Raspberry PI and connect the camera cable to the camera plug as shown in the following images. Pay attention to the side of the flat cable else the camera is not recognized by the system. If your Raspberry PI does not recognises the camera, the most probable issue depends on the incorrect cable orientation.
The camera software installation is easy. The most complete and simple tutorial to follow is in the Element14 Pi Camera introductory guide.
After the installation and testing as shown in the tutorial, it is not needed you go ahead, we will step back to this device when all the parts are set correctly.
Two words before the touch panel installation...
I think that the 2.4 inches HAT component from 4D and Element14 is really a great device. For the project we aim to make it sounds simply perfect! It is true that this small screen, despite the small size and the resolution limits is able to show the Raspberry PI desktop acting as primary screen. The following video gives an idea of what you can see after the setup.
As a matter of fact, what we need is something more specific for this kind os screen.
Last tip before the touch panel installation
The last couple of things you should do before proceeding to the next step installing the touch panel is to be sure that the network is connected and check your Raspberry PI IP address. You can use the ifconfig command from the terminal and write down the assigned IP address: maybe on the eth0 or wlan0 interface, depending on how you have connected the Raspberry PI to your network.
It is also strongly recommended that you enable the Raspberry PI for remote access before starting the setting of the touch panel. In my case I have used the SSH connection from Mac but any other method to access the PI remotely is good. This will be very useful for any further setup and programming.
Installing the touch panel
At this point our system is ready for the last step, the touch panel setup and installation. It is not needed that you insert the device in the Raspberry PI GPIO pin array for first. You can do it at the end of the installation, as you prefer it's up to you.
There is a very good tutorial for the basic setup of this device accessible from the introductory document of the product page 2.4" HAT Primary Display for the Raspberry Pi (the same pdf document can also be downloaded from the bottom of this post).
Follow the installation instructions until you are asked for the last reboot after inserting the touch panel in the Raspberry PI. After the reboot we see the desktop running on the touch panel.
Note: There is an easy-to solve issue in the installation manual: you are asked to set the sudo su before the installation commands; this means that all the further commands are sent as super user. The last command in the manual is preceded by sudo again: write the command without the sudo word because you are already in a super-user environment. That's all.
Using the Raspberry PI with the 2.4" HAT Touch Panel
Nice eh? Yes but almost unusable. This is the reason that we do somethings to make it better...
Touch Panel post-install notes
The installation of the touch panel replace some components of the original Jessie Linux Kernel with custom ones. This means that some features you have set in the kernel maybe lost. In particular, the Raspberry PI Consiguration settings (the four panels explained above) should be reviewed and applied again (depends on the settings you have used before).
When also this operation has been completed and the last reboot has been executed we are ready to move to the next step.
Forget Kivy (for now
The Kivy installation has been already explained in the previous article of this series Essential Raspberry Pi Peripherals #3: The kivy framework for small display and touch screens Just to avoid difficulties due the limitations of the 2.4" Touch Pane, Not only but the Raspbian Jessie kivy installation has been updated, extremely simplified and optimised: it can be done in few stepsSo, why not? Unfortunately the 4D Touch Panel is connected to the GPIO and can't be managed by the fast video channel used by Kivy (that means no hardware acceleration). If you try installing this framework, running the provided examples everything seems working but the screen does not change. We should find a different way to solve the User Interface design for a more comfortable use of the screen.
The PyGame Framework for UI design
The reason we can use the PyGae Framework depends on the possibility to address the UI design in Python without the graphic acceleration.
Again, if we try to launch one of the games examples we find in the Python Games folder of the Raspbian installation we see nothing.
As a matter of fact we have missed to address the graphic interface to the display on /dev/fb1 framebutter. To have the Python graphic framework working properly we should add on top of every program the following two lines:
import os os.environ["SDL_FBDEV"] = "/dev/fb1"
In the next post we will see in detail how to create a touch user interface to manage the Raspberry PI camera to shoot images.