Many people from my age still remember from university studies what is Pascal.
A wide description of this very old programming language can be found in Wikipedia Pascal description page.
Pascal is an imperative and procedural programming language, created as a small, efficient language intended to encourage good programming practices. It is named in honour of the French mathematician, philosopher and physicist Blaise Pascal.
It was very successful in the 1970s, notably on the burgeoning minicomputer market. Widely used as a teaching language in university-level programming courses in the 1980s, it was also used in production settings for writing commercial software during the same period.
Beside others, some wide companies included Pascal in their systems (like, for example, IBM and Apple).
Because of its great success, there where a number of implementations, most famous being Borland Pascal (also known as Turbo Pascal).
In this guide I’ll show you how to install and configure Free Pascal in your Raspberry PI. I’ll also show you how to setup a simple and useful terminal IDE to control and analyze your Pascal code.
I’ll use Raspberry PI Zero W, but this guide works also with newer Raspberry PI boards.
Free Pascal is really lightweith, having very affordable memory and disk requirements (Ref: https://freepascal.org/docs-html/current/user/usersu1.html#x9-80002.1.1):
As usual, I suggest adding from now to your favourite e-commerce shopping cart all the needed hardware, so that at the end you will be able to evaluate overall costs and decide if to continue with the project or remove them from the shopping cart. So, hardware will be only:
Check hardware prices with following links:
As usual, start from OS installation and update. After installing Raspberry PI OS Lite, please make your OS up-to-date:
sudo apt update sudo apt upgrade
Having Aptitude, installing Free Pascal is really simple as executing following command from Raspberry PI terminal:
sudo apt install fpc
This will download alla dependencies, installing and configuring Free Pascal command line (fpc) in your system. Let’s check what version is installed:
pi@raspberrypi:~ $ fpc -iV 3.0.4
Version will be helpful in a while…
From here. your fpc terminal command is ready to work, using system config file available in “/etc/fpc.cfg” path. You can compile Pascal programs files (usually “.pas” files) and execute them.
But fpc installation includes also a useful terminal IDE, that you can enable with the simple terminal command:
fp
Resulting in following IDE from terminal:
Navigating in FP IDE is quite simple but not intuitive. Basically, main keys / chortcuts you will use:
More shortcuts can be found in Free Pascal Keyboard shortcuts page.
When you launch Free Pascal IDE, it will create in your current directory 3 files (if not already available): fp.cfg, fp.dsk and fp.ini. These files owns local configurations for your IDE, which are unlinked from fpc system configuration.
pi@raspberrypi:~ $ ls fp.cfg fp.dsk fp.ini
From here, we’ll create our classic hello world first program.
From IDE home, create a New File (ALT+f -> New):
Copy following text inside your editor:
program HelloWorld; begin writeln('Hello World, peppe8o.com!'); end.
Save your file as “hello_world.pas” (ALT+f -> “Save as” -> write hello_world.pas -> press ENTER):
Before running your program, you need to compile it to check if code is correct (ALT+C -> “Compile”). You will note following compiling error:
reporting following info:
Main file: hello_workd.pas Failed to compile… Target: Linux for ARMHF Line number: 0 Total lines: 2 Used memory: 124K Allocated memory: 896K Total errors: 2 Compile time: 0.2s Compile failed
Pressing ALT+F3, you will close Compiling result window and activate Compiler Messages Window reporting:
(3,1) Fatal: Can't find unit system used by HelloWorld (0) Fatal: Compilation aborted
This is a common and simple error. FP IDE, as said, started with local configuration unlinked to system configuration. FOr this reason we need to add paths to units required. Be aware that changing directory where you launch fp IDE will result in new local config files and will require same operation.
Let’s add required paths. Go under Options menu (ALT+o) -> “Directories”. Press Tab utill editing screen becames editable and add following paths, caring to change version (mine is 3.0.4) to your one:
/usr/lib/arm-linux-gnueabihf/fpc/3.0.4/units/arm-linux /usr/lib/arm-linux-gnueabihf/fpc/3.0.4/units/arm-linux/* /usr/lib/arm-linux-gnueabihf/fpc/3.0.4/units/arm-linux/rtl
Press tab to activate “OK” button and then ENTER.
Close Compiler Messages Windows (ALT+f3) if still open, to go back in you code.
With new configuration on place, try again to compile (ALT+c -> “Compile”). This will result in a more pleasant “Compile Successful” message:
Press any key to go back on code. Run your code by selecting Run menù (Alt+r) -> Run. This will move back you terminal window in ssh shell and show your hello world program running by writing “Hello World, peppe8o.com!”:
Final operation, close FP IDE (ALT+x) and go back to terminal. Checking again your folder content, you will find a few more files:
pi@raspberrypi:~ $ ls fp.cfg fp.dsk fp.ini hello_world hello_world.o hello_world.pas
pi@raspberrypi:~ $ ./hello_world Hello World, peppe8o.com!
Enjoy!
In this tutorial, I will share a DIY project to create a fully customizable solar…
In this tutorial, we will use two Arduino Uno to demonstrate the Serial Peripheral Interface…
In this tutorial, we will be making an automatic irrigation system (AIS) with Arduino and…
This tutorial will show you how to use Python Virtual Environment with Raspberry PI computer…
This tutorial will show you how to get betting odds with Raspberry PI by using…
This tutorial will show you how to perform the backup of Raspberry PI (computer board)…