掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
Raspberrypiにて、LazarusでGPIOを使用したいのですが上手くいきません。 (ID:149581)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
Raspberrypi3 model b+にて Lazarus(1.6.2) FPC(3.0.0) を使用して、 GPIOの制御をしたいのですが、 https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi/es 左記ページの pigpio.pasをダウンロードし、 実行ファイルの入ったフォルダにpigpio.pasを入れ、 下記のソースでコンパイルしているのですが、 エラーが出ます。 unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, lNetComponents, lNet, lhttp, IniFiles ,Unix, BaseUnix, pigpio; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Memo1: TMemo; Timer1: TTimer; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { private declarations } public { public declarations } end; const PIN18 = 18; var Form1: TForm1; GPIO_Driver : TIoDriver; Gpf : TIoPort; {stores the result of the IO operation} implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin Memo1.Clear; if not GPIO_Driver.MapIo then begin Memo1.Lines.Add('Error Mappig GPIO Registry'); end; if GPIO_Driver.MapIo then begin Gpf := GpIo_Driver.CreatePort(GPIO_BASE,CLOCK_BASE,GPIO_PWM); Gpf.SetPinMode(18,INPUT); end; Timer1.Enabled := True; end; procedure TForm1.Timer1Timer(Sender: TObject); begin Timer1.Enabled := false; try if Gpf.GetBit(18) = true then begin Memo1.Lines.Add('1'); end; if Gpf.GetBit(18) = false then begin Memo1.Lines.Add('0'); end; finally //Gpf.SetPinMode(18,INPUT); //Gpf.ClearBit(18); //GpIo_Driver.UnmapIoRegisrty(Gpf); end; Timer1.Enabled := True; end; procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Clear; end; end. どうも、FormCreateの「if not GPIO_Driver.MapIo then」を通ってしまっている様で、 その後のTimer1イベントで、 プロジェクト project1 は、例外クラス'External SIGSEGV'を発生させました。 該当ファイル 'unit1.pas' 該当行72 if Gpf.GetBit(18) = true then 上記のエラーが出てしまいます。 gpio.pasの使い方が間違っているのでしょうか? それとも、Raspberrypi側で先にやっておかなくてはならない事があるのでしょうか? どなたかご教授の程、宜しくお願い致します。
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.