sameis / pascalio Goto Github PK
View Code? Open in Web Editor NEWInput/Output library for Raspberry Pi or any other Linux based microcontroller
License: Other
Input/Output library for Raspberry Pi or any other Linux based microcontroller
License: Other
Hi,
you wrote to comment your package on http://www.lazarusforum.de, but there still exists the issue regarding registration (http://www.lazarusforum.de/viewtopic.php?f=14&t=11832).
So I have to make my comment hear:
Your code breaks the class properties convention (https://www.freepascal.org/docs-html/3.0.0/ref/refse39.html). In FPC 3.0.4 your code is wrongly accepted, but in all version 3.1+ it isn't allowed anymore (see http://forum.lazarus-ide.org/index.php/topic,42265.msg306140.html#msg306140).
Best regards,
antispam88
In the following program the testing condition on GPIO's direction is never executed.
program Project1;
{$mode objfpc}{$H+}
uses
pascalio, fpgpio
{ you can add units after this };
var
RAIO_RST: TGpioPin;
begin
RAIO_RST := TGpioLinuxPin.Create(22);
RAIO_RST.direction := gdin;
if RAIO_RST.direction = gdIn then begin
writeln('PIN 22 direction: in');
Writeln('This is never executed');
end;
writeln('ENDE');
RAIO_RST.Destroy;
end.
Hi,
i am working on a little Robot and so i need to control his servos. Using this Raspberry Pi addon card it is really easy.
fpspi.pas , line 185:
procedure TSPILinuxDevice.SetMode(AValue: TSPIMode);
begin
if FpIOCtl(fHandle, SPI_IOC_RD_MODE, @avalue) = -1 then
DoIoCtlError(SPI_IOC_RD_MODE);
end;
This should be:
procedure TSPILinuxDevice.SetMode(AValue: TSPIMode);
begin
if FpIOCtl(fHandle, SPI_IOC_WR_MODE, @avalue) = -1 then
DoIoCtlError(SPI_IOC_WR_MODE);
end;
On a 64-bit system, this function generates a range error if processing an _IOC_READ. Because SizeInt and TIOCtlRequest are defined at the system level, the best fix appears to be disabling the range check for the duration of the computation.
function _IOC(dir, _type, nr: Longword; size: SizeInt): TIOCtlRequest; begin {$push }{$R- } // If dir is 2 (_IOC_READ) this will set the MSB hence a range error _IOC := (dir shl _IOC_DIRSHIFT) or (_type shl _IOC_TYPESHIFT) or (nr shl _IOC_NRSHIFT) or (size shl _IOC_SIZESHIFT); {$pop } end;
If compiler switch InheritFromTStream is not defined, the unit fpspi is not compilable.
Compiling package pascalio 0.0: Exit code 1, Errors:5
fpspi.pas(204,6) Error: Identifier not found "EOSError"
fpspi.pas(204,14) Error: Error in type definition
fpspi.pas(206,8) Error: Identifier not found "EOSError"
fpspi.pas(207,5) Error: Illegal qualifier
fpspi.pas(208,10) Error: class type expected, but got "<erroneous type>"
Hello, I send some new units:
Class has a timing issue when creating a pin.
if you try to change direction direct after creating the pin, nothing happens.
Reason:
The Costructor is exporting GPIOPin. The Kernel now need some time, this is the reason why direction file not exists. the result is a timing issue. Setdirection is trying to write into a file which is not existing, yet.
One solution could be a sleep which seems not useful.
Maybe a checkroutine in Cunstructor to check exported folder would be a solution.
KR
Uwe
I added two units.
lcddriver.pas
LCD Display 2 x 16 - I2c
GpioButons.pas
GPIO input keyboard,
Measure how long a button is pressed
Press and LongPress
Test to Orange pi zero
https://github.com/zeljkoc/pascalio/tree/zeljus/src
I tried pascalio recently on Orange Pi 5.
For ultrasonic example with HC-SR04, existing sample did not work well.
So I have fixed it to make it work.
This is my working sample made with other time routines. (You may use it to publish.)
========== New Working Ultrasonic Sample on Orange Pi 5 =========
program opi5_hc_sr04;
uses sysutils, pascalio, fpgpio, baseunix, unix, math;
const
GPIO_TRIGGER = 52;
GPIO_ECHO = 35;
var
trigger : TGpioPin;
echo : TGpioPin;
distance : Double;
procedure millisecondSleep(const ms : real); // uses BaseUnix
var
// .1 millisecond level sleep (warning 70 microsecond overhead)
Reqested, Remaining : TimeSpec;
ResultVal : Longint;
NanoSecondVal : LongInt;
ErrorOverhead : LongInt = 70000; // 70 microsecond overhead
begin
// 1 milisecond = 1,000,000 nano second
NanoSecondVal := round(ms * 1000000 - ErrorOverhead);
// Here, enter time to sleep (seconds + nanoseconds)
with Reqested do begin
tv_sec := 0;
tv_nsec := NanoSecondVal; // 100 microseconds = .1 milliseconds
end;
// Sleep
ResultVal:=(fpNanoSleep(@Reqested,@Remaining));
if ResultVal <> 0 then begin
writeln('Remaining nanoseconds : ',Remaining.tv_nsec);
writeln('Remaining seconds : ',Remaining.tv_sec);
end;
end;
procedure DoSigInt(sig: cint); cdecl;
begin
Writeln('Signal ', sig, ' received.');
raise Exception.Create('Signal received.');
end;
function MeasureDistance: Double;
var
StartTime: TDateTime;
StopTime: TDateTime;
TimeElapsed: Extended;
tvprev, tvcur : timeval; // for fpgettimeofday
microgap : Longint;
begin
trigger.Value := True;
//WriteLn(ErrOutput, 'TRIGGER set to: ', trigger.Value);
millisecondSleep(10);
trigger.Value := False;
//WriteLn(ErrOutput, 'TRIGGER set to: ', trigger.Value);
StartTime := Now;
while not echo.Value do
fpgettimeofday(@tvprev, nil);
while echo.Value do
fpgettimeofday(@tvcur, nil); // get timestamp AFTER sleep
// Get the gap only for microseconds which is my interest point.
microgap := tvcur.tv_usec - tvprev.tv_usec;
Result := microgap / 58; // 58 for cm. For inch, 148
end;
begin
// Signal handler for SIG_INT (CTRL+C)
FpSignal(SIGINT, @DoSigInt);
// setup GPIO pins
trigger := TGpioLinuxPin.Create(GPIO_TRIGGER);
trigger.Direction := gdOut;
echo := TGpioLinuxPin.Create(GPIO_ECHO );
echo.Direction := gdIn;
try
while True do begin
distance := MeasureDistance;
Writeln(Format('Measured Distance = %4.2f cm', [distance]));
Sleep(200);
end;
except
on Exception do
WriteLn(ErrOutput, 'Terminated');
end;
trigger.Free;
echo.Free;
end.
Hello. Can you pls ask the author of Online Package Manager (in Lazarus IDE) to add this package?
you can do it in this forum topic
https://forum.lazarus.freepascal.org/index.php?topic=34297.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.