Welcome, Guest
Username: Password: Remember me
CodeTyphon Cross-Build Development, discussions and problems
  • Page:
  • 1

TOPIC:

GPIO (Orange PI + wiringOP) 1 month 21 hours ago #18217

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 75
  • Thank you received: 0
I have Orange Pi Zero 2 width OS Debian Bullseye 11.
Which toolchain should I use? Can I use toolchains "lin64-aarch64-linux--RapberryPi3" or "lin64-aarch64-linux"?

I installed the library wiringOP .
Is there a library for FPC to interact with wiringOP (or maybe somehow directly with GPIO)?

Please Log in or Create an account to join the conversation.

GPIO (Orange PI + wiringOP) 1 month 19 hours ago #18218

  • Matis A.
  • Matis A.'s Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 1020
  • Thank you received: 140

I have Orange Pi Zero 2 width OS Debian Bullseye 11.
Which toolchain should I use? Can I use toolchains "lin64-aarch64-linux--RapberryPi3" or "lin64-aarch64-linux"?

I installed the library wiringOP .
Is there a library for FPC to interact with wiringOP (or maybe somehow directly with GPIO)?


My suggestion is to try both toolchains

CT don't have anything about wiringOP library.
 
PilotLogic Core Programmer

Please Log in or Create an account to join the conversation.

GPIO (Orange PI + wiringOP) 2 weeks 3 days ago #18243

  • Vlad Wilhelm
  • Vlad Wilhelm's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 33
  • Thank you received: 2
Dear Vital, maybe this option for working with GPIO will suit you?


unit rpiGPIO;

{$mode objfpc}{$H+}

interface

uses
 Classes, SysUtils, Unix, BaseUnix;

procedure gpioSettings(path, v: ansiString);
procedure gpioSetDirection(n: byte; o: boolean);
function gpioRead(n: byte): boolean;
procedure gpioWrite(n: byte; o: boolean);

implementation

procedure gpioSettings(path, v: ansiString);
var
 r: integer;
begin
 try
  r:= FpOpen(pChar('/sys/class/gpio/' + path), O_WrOnly);
  if r > 0 then FpWrite(r, v[1], length(v))
  else raise Exception.Create('Can not open control resource.');
    finally
  FpClose(r);
    end;
end;

procedure gpioSetDirection(n: byte; o: boolean);
const
 v: array [boolean] of pChar = ('in', 'out');
begin
 gpioSettings(pChar('gpio' + IntToStr(n) + '/direction'), v[o]);
end;

function gpioRead(n: byte): boolean;
var
 r: integer;
 ch: char;
begin
 try
  r:= FpOpen('/sys/class/gpio/gpio' + IntToStr(n) + '/value', O_RdOnly);
  if r > 0 then begin
    fpRead(r, ch, 1);
    Result:= ch = '1';
  end else raise Exception.Create('Can not open control resource.');
    finally
  FpClose(r);
    end;
end;

procedure gpioWrite(n: byte; o: boolean);
const
 v: array [boolean] of pChar = ('0', '1');
begin
 gpioSettings(pChar('gpio' + IntToStr(n) + '/value'), v[o]);
end;

end.

 
The following user(s) said Thank You: Vital

Please Log in or Create an account to join the conversation.

GPIO (Orange PI + wiringOP) 2 weeks 2 days ago #18248

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 75
  • Thank you received: 0
Dear Vlad Wilhelm, thanks for the offer! Could you please tell me how to attach a status listener to a specific pin?

Please Log in or Create an account to join the conversation.

GPIO (Orange PI + wiringOP) 2 weeks 2 days ago #18249

  • Vlad Wilhelm
  • Vlad Wilhelm's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 33
  • Thank you received: 2
I'm just polling the files on the auxiliary thread, keeping the previous state in a buffer. If there is a change, I call the trigger via thread synchronization.

Please Log in or Create an account to join the conversation.

GPIO (Orange PI + wiringOP) 2 weeks 15 hours ago #18268

  • Vital
  • Vital's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 75
  • Thank you received: 0
In my project, the connected equipment can change the state of a pin several times in one millisecond. If I run a thread without sleep(1), then the processor is 100% busy and it overheats and freezes. If I put it to sleep(1), then I may not notice the change in the state of the pin.

Please Log in or Create an account to join the conversation.

GPIO (Orange PI + wiringOP) 1 week 6 days ago #18269

  • Vlad Wilhelm
  • Vlad Wilhelm's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 33
  • Thank you received: 2
In this case my solution is not suitable. I use signal lines for slow processes. However, I'm not sure that state changes with a frequency of tens of hertz are suitable for the built-in GPIO. It might make sense to consider some external hardware implementation with data pumping through a serial port or via TWI.

For example like this:
 

Please Log in or Create an account to join the conversation.

Last edit: by Vlad Wilhelm.
  • Page:
  • 1