라즈베리파이 > Lazarus on Raspberry Pi

TODAY893 TOTAL2,440,696
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 라즈베리파이 | 라즈베리파이 | Lazarus on Raspberry Pi

페이지 정보

작성자 키트 작성일2017-09-13 16:14 조회2,805회 댓글0건

본문

Lazarus on Raspberry Pi

 Deutsch (de) │ English (en) │ suomi (fi) │ 

Lazarus on Raspbian Wheezy
3660040649_R4XEns6l_magnify-clip.png
Lazarus on Raspbian Wheezy
Raspberry Pi Logo

This article applies to Raspberry Pi only.

See also: Multiplatform Programming Guide

The Raspberry Pi is a credit-card-sized single-board computer. It has been developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools. Raspberry Pis are also used for multiple other purposes that are as different as media servers, robotics and control engineering.

The Raspberry Pi Foundation recommends Raspbian Wheezy as standard operating system. Alternative systems running on RPI include RISC OS and various Linux distributions, as well as Android.

Lazarus runs natively under the Raspbian operating system.

Installing and compiling Lazarus

Simple installation under Raspbian

Raspberry Pi 1

In the Raspbian OS it is easy to install Lazarus and Free Pascal. In order to do this simply open a terminal window and type:

sudo apt-get updatesudo apt-get upgradesudo apt-get install fpcsudo apt-get install lazarus

This installs a precompiled, stable version of FPC and Lazarus on the Raspberry Pi. Of course, a network connection is required. Installation may take about 30 minutes, but major portions of this process take place automatically. After installation you may instantly start Lazarus from the "Programming" section of the LXDE start menu.

If you need a newer version, or if Lazarus complains about a broken leakview, here.

Raspberry Pi 2

Since June 2015 the regular "out of the box" installation method also works for Raspberry Pi 2 Model B. The version that gets installed is, however, quite old. For those looking to build the latest FPC and Lazarus IDE see this article.

Cross compiling for the Raspberry Pi from Windows

1. Using fpcup

One way is to use fpcup to set up a cross compiler; follow these instructions: fpcup#Linux_ARM_cross_compiler

2. Using scripts

Alternatively, for a more manual approach using batch files, you can follow these steps.

2.1 Prerequisites

FPC 2.7.1 or higher installed with sourcecodeInstall the Windows version from the Linaro binutils for linux gnueabihf into %FPCPATH%/bin/win32-armhf-linux [1]

2.2 Example Build Script (adapt paths as needed)

set PATH=C:\pp\bin\i386-win32;%PATH%;set FPCMAKEPATH=C:/ppset FPCPATH=C:/ppset OUTPATH=C:/pp271%FPCMAKEPATH%/bin/i386-win32/make distclean OS_TARGET=linux CPU_TARGET=arm  CROSSBINDIR=%FPCPATH%/bin/win32-armhf-linux CROSSOPT="-CpARMV6 -CfVFPV2 -OoFASTMATH" FPC=%FPCPATH%/bin/i386-win32/ppc386.exe %FPCMAKEPATH%/bin/i386-win32/make all OS_TARGET=linux CPU_TARGET=arm CROSSBINDIR=%FPCPATH%/bin/win32-armhf-linux CROSSOPT="-CpARMV6 -CfVFPV2 -OoFASTMATH" FPC=%FPCPATH%/bin/i386-win32/ppc386.exeif errorlevel 1 goto quit%FPCMAKEPATH%/bin/i386-win32/make crossinstall CROSSBINDIR=%FPCPATH%/bin/win32-armhf-linux CROSSOPT="-CpARMV6 -CfVFPV2 -OoFASTMATH" OS_TARGET=linux CPU_TARGET=arm FPC=%FPCPATH%/bin/i386-win32/ppc386.exe INSTALL_BASEDIR=%OUTPATH% :quitpause

With the resulting ppcrossarm.exe and ARM RTL you will be able to build a cross Lazarus version as usual and compile FPC projects for the Raspberry Pi and other armhf devices. Remember that not all - especially Windows - libraries are available for Linux arm.

Compiling from sources

You may want to compile Lazarus from subversion sources. See Michell Computing: Lazarus on the Raspberry Pi for details.

Compiling from sources on Raspberry with Gentoo (and other distro)


If you want to install the latest stable release of fpc and, additional and isolated, the trunk fpc compiler: you can read the following guide. It was written using gentoo but this guide will be useful with any distro: Install fpc on Raspberry with Gentoo

Accessing external hardware

Raspberry Pi pinout
3660040649_R4XEns6l_magnify-clip.png
Raspberry Pi pinout of external connectors

One of the goals in the development of Raspberry Pi was to facilitate effortless access to external devices like sensors and actuators. There are five ways to access the I/O facilities from Lazarus and Free Pascal:

  1. Direct access using the BaseUnix unit
  2. Access through encapsulated shell calls
  3. Access through the wiringPi library.
  4. Access through Unit rpi_hal.
  5. Access through Unit PiGpio.
  6. Access through the PascalIO library.

1. Native hardware access

3660040649_GgbUz5l1_testprogram_for_GPIO_on_RPI_annotated.png
3660040649_R4XEns6l_magnify-clip.png
Simple test program for acessing the GPIO port on Raspberry Pi
3660040649_lZi2aewP_rpi_testcircuit_1d.png
3660040649_R4XEns6l_magnify-clip.png
Test circuit for GPIO access with the described program
3660040649_8K9auUnt_rpi_testcircuit_1p_annotaded.png
3660040649_R4XEns6l_magnify-clip.png
Simple demo implementation of the circuit from above on a breadboard

This method provides access to external hardware that doesn't require additional libraries. The only requirement is the BaseUnix library that is part of Free Pascal's RTL.

Switching a device via the GPIO port

The following example lists a simple program that controls the GPIO pin 17 as output to switch an LED, transistor or relais. This program contains a ToggleBox with nameGPIO17ToggleBox and for logging return codes a TMemo called LogMemo.

For the example, the anode of a LED has been connected with Pin 11 on the Pi's connector (corresponding to GPIO pin 17 of the BCM2835 SOC) and the LED's cathode was wired via a 68 Ohm resistor to pin 6 of the connector (GND) as previously described by Upton and Halfacree. Subsequently, the LED may be switched on and off with the application's toggle box.

The code requires to be run as root, i.e. either from a root account (not recommended) or via su.

Controlling unit:

unit Unit1; {Demo application for GPIO on Raspberry Pi}{Inspired by the Python input/output demo application by Gareth Halfacree}{written for the Raspberry Pi User Guide, ISBN 978-1-118-46446-5} {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,  Unix, BaseUnix; type   { TForm1 }   TForm1 = class(TForm)    LogMemo: TMemo;    GPIO17ToggleBox: TToggleBox;    procedure FormActivate(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure GPIO17ToggleBoxChange(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; const  PIN_17: PChar = '17';  PIN_ON: PChar = '1';  PIN_OFF: PChar = '0';  OUT_DIRECTION: PChar = 'out'; var  Form1: TForm1;  gReturnCode: longint; {stores the result of the IO operation} implementation {$R *.lfm} { TForm1 } procedure TForm1.FormActivate(Sender: TObject);var  fileDesc: integer;begin  { Prepare SoC pin 17 (pin 11 on GPIO port) for access: }  try    fileDesc := fpopen('/sys/class/gpio/export', O_WrOnly);    gReturnCode := fpwrite(fileDesc, PIN_17[0], 2);    LogMemo.Lines.Add(IntToStr(gReturnCode));  finally    gReturnCode := fpclose(fileDesc);    LogMemo.Lines.Add(IntToStr(gReturnCode));  end;  { Set SoC pin 17 as output: }  try    fileDesc := fpopen('/sys/class/gpio/gpio17/direction', O_WrOnly);    gReturnCode := fpwrite(fileDesc, OUT_DIRECTION[0], 3);    LogMemo.Lines.Add(IntToStr(gReturnCode));  finally    gReturnCode := fpclose(fileDesc);    LogMemo.Lines.Add(IntToStr(gReturnCode));  end;end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);var  fileDesc: integer;begin  { Free SoC pin 17: }  try    fileDesc := fpopen('/sys/class/gpio/unexport', O_WrOnly);    gReturnCode := fpwrite(fileDesc, PIN_17[0], 2);    LogMemo.Lines.Add(IntToStr(gReturnCode)

댓글 0

조회수 2,805

등록된 댓글이 없습니다.

라즈베리파이HOME > 라즈베리파이 > 전체 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기