Pharo PI

Torsten Bergmann
Concerning Pharo
Published in
15 min readOct 25, 2015

Working with Pharo on the Raspberry Pi

Hardware is getting cheaper and many new small devices like the famous Raspberry Pi provide new computation power that was one once only available on regular desktop computers. This capable little device called “Pi” enables people of all ages to explore computing and combined with powerful software environments like Pharo the Pi can be used for interesting projects.

Getting the “hard stuff” first

Buying Hardware

Our journey starts with looking for the right “Raspberry Pi” device. The Pi itself as a credit card-sized single-board computer is cheap but powerful enough to do some real work.

Just Google and dig in the different stores and online shops to buy a Pi - for the lazy just get one at Amazon. Note that there are different models around varying in speed and features. From the first Pi generation the author of this article only tested the Raspberry Pi B+ with 512MB RAM. It was already satisfying in speed for most purposes.

Meanwhile I’m the proud owner of a Raspberry Pi 2 — a model with 1GB of RAM that now has an ARM-Cortex CPU following the ARM v7 architecture. Regular price range is still between 35 and 45 dollars.

Raspberry Pi 2 Modell B — ARM Cortex-A7 Quad-Core 900MHz 1GB RAM

To be able to wireless connect the Pi to a local network I additionally bought a Wireless USB adapter. Here the Edimax EW-7811UN with 150Mbps served me very well as it is small and worked out of the box and without further configuration (beside connecting to WLAN).

EDIMAX EW-7811UN Wireless USB Adapter, 150 Mbit/s, IEEE802.11b/g/n

To keep the desktop as cable free as possible I also ordered a Wireless optical mouse. The small USB Wireless Receiver of the mouse perfectly fitted the Pi style and made the USB port still look compact and smart.

JETech® M0770 2.4Ghz Wireless Mobile Optical Mouse with 6 Buttons, 3 DPI Levels, USB Wireless Receiver

Also a micro SD card added a few more bucks to the overall bill. If you buy the Official Micro SD Card for the Raspberry Pi the card with 8GB in size is already pre-loaded with the Official Raspberry Pi NOOBS (New Out of Box Software).

8GB NOOBS card for the Raspberry Pi Model B+

Following the “Plug and play” concept one can quickly plug the mouse wireless receiver and the wireless network adapter into two of the four USB ports. It’s also easy to connect the computer to a regular TV set and plugin a USB keyboard for typing.

To Power on the Raspberry Pi device one just have to connect to power supply. This can be done with a regular Micro USB Power adapter (5V, 2.0A) or a portable battery power bank as known from regular smartphone recharging.

Case, touch and display in one

Having the Pi computer around “naked” without any covering case is not good for the devices lifetime. So we need a stable box to put it in and there is now an official Pi Case available. But even with a great looking plastic case I thought connecting to a regular Monitor or TV is still disturbing and too heavy for my needs. I wanted to stay as small and compact as possible, even for the display.

A quick search in the Internet revealed that there are several options for combining the Pi with small displays. Especially a small touch display from Tontec waked my interest because:

  • it is a small 3,5 inch screen that fits the size of the pi board perfectly
  • screen resolution is 480 x 320 pixel, 16 bit, 65K color
  • it is an LCD display and touch panel in one, so the resistive touch screen can be used as an input method
  • there is no need for an additional external cable or adapter, the screen is powered by the GIPO pins on the Pi
  • as it comes with an acryl case it provides a stable and secure home for the Pi board
  • the product was designed especially for Raspberry 2 and Raspberry Pi B+ allowing a transparent acrylic enclosure of the hardware
  • an open source Linux driver is already available
Tontec® 3.5 Inches Touch Screen for Raspberry Pi Display Monitor 480x320 LCD Touchscreen Kit

Assembling a small Raspberry pi computer with this great box enclosure solution can be done in a few minutes and the result is compact and still lightweigth. A full computer that fits into your hand …

To make things complete I also ordered touch pens allowing for precise movement and selections on the touch screen. One can get a bundle of 5 Stylus pens for less than a dollar. Originally these pens were provided as spare parts for Nintendo DS handheld kids game console.

Stylus Pen for Nintendo NDS Lite

Now we are ready from the hardware side.

Let’s get some “software”

Preparing the SD Card

To run some software on the Pi we need a basic operating system to boot. Fortunately for the Pi there is a well prepared software distribution called NOOBS (“ New Out Of Box Software”) for the Pi. After downloading it from the web we initially have to put it on an SD card. You can leave out this step if you already have the official Raspberry Pi SD card with the NOOBS Software preinstalled.

Assuming we have a new SD card we should initially format it. There is a nice software called “SD Formatter” that you can download and install on your desktop machine (here I use Windows). Make sure you select the correct drive letter, enter a label and click Format to format the card.

Formatter tool on Windows

I use the Quick format option here but the tool also allows for a full erase option. When the tool finishes the SD card is formatted with FAT32 file system.

Putting NOOBS on the SD card

Just visit the Raspberry Pi download page to download the NOOBS distribution. You can use the version NOOBS 1.4.1 or the newer NOOBS 1.4.2. The download is large as anything is bundled in 800 MB (NOOBS_v1_4_1.zip) or 900MB (NOOBS_v1_4_2.zip) file.

Just extract the contents of the NOOBS ZIP file on the SD card drive letter so it is available on the drive:

Extracted contents of the NOOBS archive on the SD card

Now we are ready to insert the SD card into our Pi. Ready for a first boot …

Booting NOOBS and Raspbian

For the assembled Pi with the small and shiny display initially the system is configured to use the default HDMI connector as a display device.

So the first time you boot a fresh NOOB system from the SD card you need your Pi to be connected to a regular TV or monitor using a HDMI cable. Also make sure a keyboard and the mouse is connected to our new toy.

We can power on the Pi device by connecting to a power source. Now you should be able to see how NOOBS starts up. The initial screen allows you to select the language and keyboard layout. As I use a german keyboard I switched the keyboard to the appropriate ISO code “de”.

The NOOBS installer primarily allows you to select predefined installations. We will follow the recommended way to install Raspbian only and click on “Install” to continue.

NOOBS 1.4.1

Now the installer installs the Raspbian operating system (a linux variant based on Debian) on the SD card. Time to get another coffee until the installation finishes and the system reboots.

Pi Software configuration tool

After the first restart the Raspbian operating system (from NOOBS 1.4.1) now boots into the raspbian configuration tool “raspi-config”. If you use the newer Raspbian from NOOBS 1.4.2 then the system directly boots into the desktop. You can always start the tool from the commandline:

sudo raspi-config

Here one is able to set different options:

I use “Internationalization options” and “Change keyboard layout” to set to the right keyboard (a Logitech Cordless keyboard with german layout).

In the “Advanced Options” I enable the loading of the SPI kernel as a default one to use during next boot. This enables the Serial Peripheral Interface (SPI) that is used by the display device according to the Tontech product site.

Now we “Finish” the tool and reboot.

Login

Now for NOOBS 1.4.1 the raspbian operating system is asking for the credentials to login. By default you can login with the user “pi” by using “raspberry” as password. If you like you can invoke the settings tool again and change afterwards:

 sudo raspi-config

Using the command line is nice — but we would like to use a graphical desktop environment now. Just enter

startx

to start the X desktop environment. As explained before with NOOBS 1.4.2 you do not need this step as the system initially boots directly to the desktop.

The Raspbian desktop

The raspi config tool in NOOBS 1.4.2 allows you the way the system boots:

  • Console
  • Console Autologin
  • Desktop
  • Desktop Autologin

I prefer the last setting as it allows to boot into the desktop system and as we will see later directly into our Pharo application.

Connect to a network and update

We now need to install some software from the web — so it is time to connect the Pi to a network using a network cable.

In the upper right area of the desktop you will find an icon that allows you to connect your Pi also to a local WLAN. For the time being and for the initial installation I still use the network cable.

After the initial setup will be done I would recommend to use the Pi with a wireless network later. Connecting via WLAN is easier to handle as you do not need to plug any network cable into the Pi device later when you move it around.

In the upper left are of the desktop you will find an icon to open a new terminal. Use it and enter the following expression to update your systems package list:

sudo apt-get update

Now upgrade all your installed package to their latest version:

sudo apt-get upgrade

Ideally you reboot after updating

sudo reboot

Installing Pharo

It’s time to install Pharo now. Pharo is a lively development and runtime environment based on the Smalltalk language. It is free and open source with a strong and dedicated community. Beside being a very productive and pure object oriented environments Pharo allows you to run bit identical on several platforms by using a powerful Smalltalk virtual machine. This makes it ideal for our goal as we can develop on a fast desktop machine if we like and deploy later on the Pi. It is also possible to code and use it on the Pi directly.

You can read more about Pharo on http://www.pharo.org. This is also the place where you can grab a copy for your Mac, Linux or Windows machine.

Also do not forget to check out the free books http://books.pharo.org and http://pharo.pharocloud.com/pharobooks.

PHARO VIRTUAL MACHINE

Pharo in the tradition of Smalltalk runs with a virtual machine to abstract from the underyling native system platform and provide a common interface for the Pharo layer. This way Pharo programs are portable and allow for easy reuse.

Usually one can get Pharo virtual machine (VM) and necessary support files

But the regular Pharo virtual machines for Linux will not work for the Pi — we need a virtual machine with support for the ARM processor architecture.

The Pi virtual machine is accessible only from the Pharo Continuous integration (CI) server: http://ci.pharo.org

(Update 2019: grab the VM from http://files.pharo.org/vm/pharo-spur32/linux/armv6/)

There you will find a build called “RaspberryPi” with “RaspberryPi-Publish”. At the time of this writing this was available from

https://ci.inria.fr/pharo/view/RaspberryPi/job/RaspberryPi-Publish/ws/

and and the latest zip with the VM was available on

https://ci.inria.fr/pharo/view/RaspberryPi/job/RaspberryPi-Publish/ws/61.zip

Lets create a new folder in our home folder for it:

mkdir pharo
cd pharo

to download:

wget https://ci.inria.fr/pharo/view/RaspberryPi/job/RaspberryPi-Publish/ws/61.zip

and extract the file:

unzip 61.zip

Alternatively you can grab the VM also from

http://files.pharo.org/vm/pharoS/raspbian/latest.zip

which should give you the latest one.

PHARO IMAGE AND CHANGES FILE

But the virtual machine is not enough. Beside the native virtual machine we need the Pharo Smalltalk image — a platform independent file that includes the whole Pharo environment. It is some kind of snapshot of the object memory of a lively Pharo system.

The so called Pharo ZeroConf scripts can help easily in retrieving such a file:

wget -O- get.pharo.org/stable | bash

This will download Pharo 4.0 image and changes file as 4.0 this is the latest release of the community at the time of this writing. Our folder should now have to new files:

  • Pharo.image
  • Pharo.changes

If you would like to use the latest Pharo image (which is 5.0 alpha at the time of this writing) you should use

wget -O- get.pharo.org/alpha | bash

Note that such an alpha version of Pharo might be unstable and is only recommended for experienced Smalltalk and Pharo developers.

PHARO SOURCE FILE

Beside the the virtual machine, the image and changes file we need another one: the sources file which will later allow you to browse the full source code in the Pharo environment:

wget http://files.pharo.org/sources/PharoV40.sources.zip
unzip PharoV40.sources.zip

As we have extracted the ZIP files we can remove the now unnecessary archive files to save a little bit of space:

rm 61.zip
rm PharoV40.sources.zip

We are ready. Lets use the following commandline to start Pharo on the Pi (running the virtual machine with the image file):

./PharoS Pharo.image &
Pharo running on the Raspberry Pi

We will not go into the details of developing an application with Pharo here and instead use an already prepared one. The Smalltalk language is easy to learn — but as a pure object oriented environment you may have to (re)learn the way of coding. Pharo is not only a lively environment where you can code but also a very dynamic environment where you can change anything: starting from the tools up to the language itself. Did you know that object oriented programming, user interfaces with windows and icons, Unit testing and Extreme Programming — it all can be traced back to have its roots in Smalltalk. Once you get used to the environment a little bit you will notice why all of its revolutionary ideas and tools had such a big influence on many known IT technologies.

I kindly refer to the documentation and books available for more details.

Prepare an application

In Pharo 4 there is a “Tool” called “Configuration Browser” that you can use to load some prepared Pharo packages/projects. You can access this tool by clicking in an empty area within the Pharo window to open the world menu.

Open the Configuration Browser

If you already work with Pharo 5alpha there is a similar tool called “Catalog Browser”.

In the config browser search for a project called “Pomodoro”. It is a simple Pomodoro timer that I would like to use for demoing a possible app. When you install it the Pomodor morph will open on the desktop.

Now open a Playground and evaluate the following expressions:

PolymorphSystemSettings showDesktopLogo: false.

This will hide the Pharo logo. Make sure that the Pomodoro Timer stays visible in the top left corner of the Pharo window.

From the world menu of the Pharo windows (clicking in an empty part of the screen) you can now save the whole image. Click on “Save and Quit”.

To check if anything is ready just check that the image was stored correctly by restarting Pharo with the image again:

./PharoS Pharo.image eval "Display fullscreen: true" &

You should now see Pharo starting in full screen mode and the Pomodoro Timer at the top left of your screen.

Now we want that the Pi starts this command line directly when it boots so that our Pharo application is presented to the user first. We can accomplish that using a .desktop file:

sudo mkdir ~/.config/autostart
sudo vi ~/.config/autostart/Pharo.desktop

As we place this file in the autostart directory of the current user it will be run after the X desktop started.

Put the following contents into the file:

[Desktop Entry]
Name=Pharo
Comment=Run Pharo
Type=Application
Exec=/home/pi/pharo/PharoS /home/pi/pharo/Pharo.image eval “Display fullscreen: true”
Terminal=false

Now when you reboot your Pi the Pharo application will start with the X-Desktop:

The Pomodoro timer

Setting up the Pi display

As we are now ready with our application on the regular Pi display we would now like to use the small display of our assembled Pi box.

We can follow the driver setup instructions provided by the display manufacturer. In my case I had to do the following:

  1. Update the Raspbian packages

Lets use the latest packages available, we just update our Raspbian system:

sudo apt-get update
sudo apt-get upgrade
sudo reboot

2. Update the Firmware

We also want to update the firmware of our small device and reboot afterwards:

sudo rpi-update
sudo reboot

3. Enable SPI and set overlay for Tontec Screen

We already enabled the SPI on the raspberry config tool. So lets open the boot configuration file:

sudo vi /boot/config.txt

and add the following lines at the bottom

dtparam=spi=on
dtoverlay=mz61581

Again save and reboot your device.

4. Set Tontec screen as the default display instead of HDMI

As we now want to display the desktop on the small device display we have to switch to the second framebuffer device. Edit the following configurration file

sudo vi /usr/share/X11/xorg.conf.d/99-fturbo.conf

and change the option from

“fbdev” “/dev/fb0”

to

“fbdev” “/dev/fb1”

And finally after a new reboot our Pharo application is booting and running on the Raspberry Pi:

Pharo Pomodoro running on the Raspberry Pi

We can now use our small pen to control and interact with our Pharo Pomodoro timer. As in this demo app no keyboard is required we can disconnect the keyboard and mouse.

Using the Pen to interact

Tips and Tricks

As our small demo app requires no keyboard or mouse control so we can use the touch display and remove the keyboard and mouse connections from the USB ports.

You will also notice that using the fingers instead of the pen on the touch device is still hard. The Pomodoro control window is not very large in the default configuration and should ideally have the size of the shiny small Pi screen now. Note that the Pomodoro app was originally written by the author on a Windows machine. But I think it demonstrated how easy it is to (re)use a Pharo based application by deploying it on the Raspberry Pi.

I leave it up to the reader to experiment with Pharo and Smalltalk and it’s current UI framework Morphic, but still I want to give a few tips:

  • While Pharo allows to develop direct and lively on the Raspberry device itself I would recommend to develop on a fast desktop machine and later move the image to the Rasperry Pi.

Initially you should create a morph that has the size of the small display so you can layout your application correctly:

BorderedMorph new 
extent: 480@320;
position: 0@0;
color: Color white;
lock: true;
openInWorld

By locking the morph it will be sticky to the background and will not move when accidentially gestures interactions hit the graphical bounds of the morph.

The Pharo environment
  • I dislike connecting my Pi to a bigger display or manually switching to the appropriate framebuffer device in the configurations. Therefore setting up a VNC server directly in the installed Raspbian allows to lively connect to the Pi when available from the network. This way one can connect to the Pi and Pharo using a VNC Client right from a normal desktop PC.
  • If your application requires a strong binding to the Pi or you want to call some functions on Raspbian I would recommend to have a look at the OSProcess package for Pharo. It allows to run native Unix commands from Pharo and also works on the Pi.
  • There are other nice display available in all sizes. We concentrated on a small 3.5’’ display in this article. Primary reason is that the Tontec 3.5 display also additionally gives a housing to the Pi and can be easily sticked to a wall using screws. So to roll out your Pharo/Pi based solution anything you need is a power plug nearby the plastic case and a location within your local WiFi range.
  • Pharo has some nice web frameworks like Teapot or Seaside. They allow you to easily run a webserver on your Pi. Implementing a simple control interface in Pharo’s Morphic, Spec or Bloc/Brick UI frameworks allow you to control the service right from the touch display.
  • Using Pharo’s built in “Zinc HTTP components” it is easy to retrieve resources or data from the web and process or display it on the Pi:
(ZnEasy getPng: ‘http://pharo.org/web/files/pharo.png') 
asMorph openInWorld
(ZnEasy get: ‘http://catalog.pharo.org/catalog/json')
contents inspect.

You can even use Pharo as server backend providing the data to your Pi deployed application. With web frameworks like Teapot, Seaside, Aida, Zinc, …Pharo has a lot of options to offer. Again you can implement locally in a lively Pharo image and quickly host your Pharo image in the cloud using PharoCloud.com, Clever-Cloud.com or other cloud providers.

Conclusion

This article has shown how you can combine the small Raspberry Pi device with a touch display and use the amazing Pharo lively development environment to quickly deploy an application on the Pi. Combining both technologies allows for new interesting projects due to easy application development and quick 1:1 deployment on the Raspberry Pi.

--

--