PureBasic for Raspberry PI

Not so long ago, PureBasic version 6.00 was released, which, among other things, added support for ARM processors. Raspberry PI is on the list of platforms, but other similar single board computers should probably be supported. I have tested the work on most Raspberry PI models, including the simplest – Zero and the top one at the moment – 4B. All were running Raspberry Pi OS April 4th 2022. As expected, PureBasic started up and ran fine on all test Raspberry PIs.

A little explanation for those who don’t know what PureBasic is.

PureBasic is a compiled programming language created in the early 2000s for the Amiga computer. As it has evolved, other platforms have been added including Windows, Linux and Mac OS X for Intel, AMD, ARM and PowerPC processors. In my opinion, this is one of the best modern BASIC dialects. Not the last role in this was played by a cross-platform library with almost 2 thousand functions of various directions. Among them there are functions for working with raster, vector, 2D and 3D graphics. Support for databases such as MySQL, SQLite, PostgreSQL, ODBCD and others. Working with files, networking (FTP, HTTP/HTTPS, Mail), GUI and more. The presence of multithreading support allows you to fully engage all processor cores in resource-intensive calculations. For a complete list of features, see the online documentation. https://www.purebasic.com/documentation/

Thanks to the cross-platform library, it is possible to transfer applications originally developed for a Windows or MacOS X computer to the Raspberry Pi.

The PureBasic programming language is quite simple and not hard to learn. Almost everything you need can be found in the help included in the distribution. It is in English, but the network has translated into Russian.

PureBasic is suitable for those who need to develop an application for the Raspberry Pi or other platforms, without the need to learn the features of the operating system and the functioning of the computer. The cross-platform library will cope with the solution of most application-level tasks without the need to use OS functions.

To install PureBasic on Raspberry Pi, you should download it from the official website https://www.purebasic.com You need to choose the version that matches the bitness of the operating system. That is, for a 32-bit OS, an archive for arm32 is required, and for a 64-bit OS, arm64.

Installation is performed by extracting the archive to any folder (for example, to the home of the current user) for which there are access rights. Further actions are described in the INSTALL file from the archive.

Fragment from the INSTALL file


Unpack Purebasic

  • Create in “Private Folder” an Apps folder

  • Unpack Purebasic into this folder

  • Rename folder with versions number. Example “purebasic” -> “purebasic-v572”

Install developer packages

  • Info: Required Webkit not available on Ubuntu bigger version 18.04. Support of Webkit2gtk with Purebasic v6.00 (Ubuntu 20.04/gtk3)

  • Start Terminal and install packages

Update compiler and default libraries

sudo apt-get install build-essential gcc g++

Developer Libraries

sudo apt-get install libxxf86vm-dev libxine2-dev unixodbc-dev libsdl1.2-dev libsdl2-dev libssl-dev

sudo apt-get install libgtk2.0-dev libgtk-3-dev

  • Ubuntu 18.04
    sudo apt-get install libwebkitgtk-dev libwebkitgtk-3.0-dev

  • Ubuntu 20.04 / Raspberry PI Desktop
    sudo apt-get install libwebkit2gtk-4.0-dev

  • Raspberry PI Desktop / Movie Library
    sudo apt-get install libvlc-dev

Developer Libraries For Games

sudo apt-get install libgl1-mesa-dev libgl1-mesa-glx

Subsystem qt

sudo apt-get install qtbase5-dev qttools5-dev qtmultimedia5-dev qtdeclarative5-dev libqt5svg5-dev libqt5webkit5-dev libqt5multimedia5-plugins

Canberra for PB-IDE (Raspberry PI not needed)

sudo apt install libcanberra-gtk-module

Ubuntu missing default libs (Without developer packages)

sudo apt-get install libgtk2.0


sudo apt install qt5-default

To compile applications, you need to install several developer (dev) packages. Their list is given in the INSTALL file and depends on the type of applications being developed. Or you can install all required packages (overkill in many cases) by typing the following line in a terminal.

sudo apt-get install build-essential gcc g++ libxxf86vm-dev libxine2-dev unixodbc-dev libsdl1.2-dev libsdl2-dev libssl-dev libgtk2.0-dev libgtk-3-dev libwebkit2gtk-4.0-dev libvlc-dev libgl1-mesa-dev libgl1-mesa-glx qtbase5-dev qttools5-dev qtmultimedia5-dev qtdeclarative5-dev libqt5svg5-dev libqt5webkit5-dev libqt5multimedia5-plugins

The entire process from downloading PureBasic to installing packages and running the test application can be seen in the video.

The examples folder contains several dozen different sample programs. The launch of some of them is shown in the video.

The Linux version of PureBasic provides a choice of three GUI subsystems – GTK2, GTK3 (default) and Qt. This does not require any changes to the code. It is enough to specify the subsystem in the compiler settings.

On the Raspberry Pi 4B, 3D sample applications work fine, even though Raspberry is not designed for 3D graphics.

Small twitching of the picture due to video recording from the screen and its encoding. Without it, the animation is smooth.

To access the raspberry hardware, the community has written a number of libraries or interfaces to existing ones. The list can be found in the topic on the official forum https://www.purebasic.fr/english/viewtopic.php?t=78338


Let’s look at one example that reads the temperature of the “raspberry” processor and displays it in a window.

; Файл из которого нужно считывать температуру.
If ReadFile(0, "/sys/class/thermal/thermal_zone0/temp", #PB_UTF8) = 0
  MessageRequester("", "Нет доступа к файлу", #PB_MessageRequester_Error)

; Создание окна.
OpenWindow(0, 0, 0, 250, 90, "CPU Temp", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0, 0, 20, 250, 80, "", #PB_Text_Center)
SetGadgetFont(0, LoadFont(0, "FreeSans", 28, #PB_Font_Bold))
; Таймер с периодом 1 секунда.
AddWindowTimer(0, 0, 1000)
PostEvent(#PB_Event_Timer, 0, 0) ; Отправка события таймера чтобы температура появилась сразу, а не через секунду после запуска приложния.

  Event = WaitWindowEvent() 
  If Event = #PB_Event_Timer And EventTimer() = 0 ; Сработал таймер.
    FileSeek(0, 0)                                ; Переход в начало файла.
    temp.d = ValD(ReadString(0))/1000             ; Чтение из файла и перевод с тысячных долей градуса в целые.
    SetGadgetText(0, StrD(temp, 3)+" °C")         ; Отображение в температуры в окне.
Until Event = #PB_Event_CloseWindow


At the beginning of the program, the ReadFile() function opens a system file from which the temperature will be read later. If the file is unavailable, a corresponding message appears and the program ends.

Upon successful opening of the file, a window and a text field are created in it by calling the OpenWindow() and TextGadget() functions.

The AddWindowTimer() function adds a timer to the window with a period of 1000 milliseconds (a second), and an event will be generated regularly at these intervals.

In a loop, the WaitWindowEvent() function waits for the nearest event and returns its code. If this is a timer event, the temperature is read from the file and displayed in the window.

In the case of a window close event, the loop will be interrupted and the program will end there.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *