Recent

Author Topic: FPC on Rasp Pi, non Lazarus, use of GPIO.  (Read 17828 times)

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
FPC on Rasp Pi, non Lazarus, use of GPIO.
« on: February 18, 2021, 06:02:25 pm »
Hi,

I don't need Laz for my Pi project.  But I do need access to the GPIO.

How do I go about that?  Are there units I can DL for that?  Current v. is FPC 3.0.4 under 32b Rasp Pi OS.

Thanks,
Alan.
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

ojz0r

  • Jr. Member
  • **
  • Posts: 60
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #1 on: February 18, 2021, 06:36:08 pm »
Check out the wiki page: https://wiki.freepascal.org/Raspberry_Pi
Thats a very good guide for gpio access.
Just trying to learn.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #2 on: February 18, 2021, 06:52:29 pm »
In any event the GPIO bits are exposed via a standard API in the /sys tree, and I believe that there's also a newer (and higher performance) way of driving the bits by accessing /dev devices although I've not played with it yet.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #3 on: February 18, 2021, 07:03:47 pm »
Thanks both MarkMLI and ojzOr -

I hope to also be able to easily link assembly code.  But that is next week (waiting for the parts to come (GPS, Accel/gyro)).


So, you send me a link that says:   "https://wiki.freepascal.org/Raspberry_Pi"

And I end up on the page: "https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi"

Argghh ... Oh, well, it's a start!  I'll figure out (I hope) how to strip Laz out of that....  I really only want/need a CLI as the project will be headless in the end...
« Last Edit: February 18, 2021, 07:08:54 pm by AlanTheBeast »
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

ojz0r

  • Jr. Member
  • **
  • Posts: 60
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #4 on: February 18, 2021, 07:16:56 pm »
Its not hard to strip the Lazarus part out,  if you get stuck t can send you an example based on that guide that im currently running on a RPi Zero W.
Just trying to learn.

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #5 on: February 18, 2021, 07:26:48 pm »
ojzOr - well don't delay, act now!  Thanks. 

(Yes, I'm lazy!).

Thanks

I'll be doing a Pi zero eventually as a remote sensor with a LoRa ... maybe in a month... want to do some airborne experiments too ( carry on a drone ).
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #6 on: February 18, 2021, 07:28:51 pm »
The RPi is a standard Linux-based computer, albeit a bit smaller than most and with not-quite-standard startup and video arrangement.

Lazarus is an IDE that is entirely suitable for non-GUI development: scratch the surface and you'll find that many if not most of the FPC core developers use it to work on the compiler.

If you don't want to use Lazarus then use some other editor and makefiles etc., but assume that much of the Lazarus (as distinct from LCL) documentation actually pertains to the underlying compiler.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #7 on: February 18, 2021, 07:46:38 pm »
@Mark,

I'm not familiar with Lazarus.
OTOH, I'm quite happy to write Pascal in a basic text editor or lite IDE.  Indeed there's one I found with the Rasp OS distro called Geany that recognizes Pascal and invokes FPC.  I was surprised.

The "overhead" of Lazarus, etc., just gets in the way of my project timewise - I don't want to invest much into it when I won't be implementing or using it.  A CLI is all I need to run, test and complete the work.

I'm trying to avoid C because I despise C.  I'd rather write in assembler than C (but I don't know the ARM machine that well so another learning process to avoid...).  (I did an Arduino project in "C" (ish) which reminded me how bad it is...)

Plain old Pascal is all I need (of the Turbo vein with units)... I'll even jump to Python 3 (spit!) if need be...

That said, I'll install Lazarus on the Pi and try the demo at the linked page... you never know... I might succumb...

Thanks!
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4467
  • I like bugs.
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #8 on: February 18, 2021, 08:22:44 pm »
The "overhead" of Lazarus, etc., just gets in the way of my project timewise - I don't want to invest much into it when I won't be implementing or using it.  A CLI is all I need to run, test and complete the work.
What overhead do you mean? How does it get in the way?
In reality it is snappy. It does everything that Geany does + a lot more.
Lazarus trunk is speed optimized recently. Especially startup in Unix related systems is faster now. Raspberry Pi users please test. The memory and HW requirements however remain the same because compilation and especially linking hog resources.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #9 on: February 18, 2021, 08:34:01 pm »
The "overhead" of Lazarus, etc., just gets in the way of my project timewise

What overhead? It's a better-than-average text editor (not as good as Multi-Edit on DOS, but nothing is) with the major advantage of a properly-integrated debugger.

I'm not sure that "underhead" is a word, but criticising it due to automatically assuming that it introduces an unacceptable amount of cruft is at best underhand :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #10 on: February 18, 2021, 09:25:08 pm »

I mean overhead in the code, generally.  Also the overhead of learning Lazarus when all I need is access to the GPIO pins.

For example "https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Switching_a_device_via_the_GPIO_port" uses a TForm ...  don't need that ... at all.

In essence when someone wants access to the GPIO pins (or other h/w) then the abstraction should be about that w/o showing all the rest.

I don't need "objects" to access a pin on a header.

etc and so on
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #11 on: February 18, 2021, 09:52:23 pm »
Lazarus is an IDE. The LCL is GUI stuff. Objects have their uses even if you aren't using GUI-oriented components.

The first part of that example manipulates the GPIO bits via- AS I HAVE ALREADY SAID- the /sys tree. The GUI stuff is there entirely as eye-candy.

The second part goes via /dev/mem (which is a non-standard RPi-specific interface)... again, the GUI-based stuff is completely irrelevant except that it's easier to drop a couple of buttons onto a form than to implement an interactive text-based demo (I'll leave you to work out how I know).

The second part /does/ use a couple of classes to encapsulate functionality, I'm undecided as to whether that's justified without seeing a larger project that demonstrates the author's intent.

If you cited an interface which was distributed as a Lazarus package and couldn't easily be unbundled from its visual component then your reservations would be justified. As it is, you are criticising from an uninformed position: AS I HAVE ALREADY SAID the Lazarus IDE is an exceptionally good development environment for character (console) based programs (and I've used- and sold- quite a few in my time).

MarkMLl


MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #12 on: February 18, 2021, 10:47:51 pm »
I appreciate the help (and yes I realize that Laz is an IDE).

However it seems like all examples around here must pass through the GUI stuff (Forms, etc).
Why do I need objpascal?  Do I need objpascal?  (Certainly don't want it).

I just want to know the very basic things I need to do to get at that h/w and would be much happier without all the cruft of forms, etc.

I don't use object Pascal - so the purpose of (Sender: TOBject) is pretty opaque to me in the example.  Yes, I can figure it out or muddle my way through   I'd rather write (or use) a simple, clear, clean, fast, unit -no objects.

So (IMO) when people make examples, they should make the simplest example possible w/o all the wrappers, bells and whistles that are not related to the specifics - to make things clearer.

Sorry to vent when people are helping!

Thanks!
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #13 on: February 18, 2021, 11:04:27 pm »
Object Pascal is a somewhat extended variant of Turbo Pascal, which is a somewhat extended variant of J&W Pascal. You don't want me to start going on about the precursors or the politics that resulted in Pascal. Honest.

If you don't want or need the OP extensions, then don't use them. Simple as that.

If you feel like writing something that is text-menu based or has an internal command line then do so, but don't knock the efforts of people who've gone to the trouble of providing examples (e.g. of how to get at GPIO bits) and have chosen to save themself effort by using form-based GUI stuff as a wrapper.

FFS, man, *READ* those examples and you'll see that by and large they show you how to do things like accessing the GPIO bits independent of the GUI wrapper. You asked for an example, somebody gave you one: study it.

Now before you tax the community's patience any further, I strongly suggest that you install Lazarus and experiment with using it to develop and debug a couple of simple console-based ** application programs. If you don't like it that's fine, but don't go on to complain that the FP editor or some out-of-tree IDE has poor debugger support (unless, of course, you're prepared to contribute by improving it).

** Text-only. Non-GUI. No forms involved. Runs from the shell. etc. Start off with the canonical "Hello, World!".

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: FPC on Rasp Pi, non Lazarus, use of GPIO.
« Reply #14 on: February 18, 2021, 11:58:19 pm »
Hi Mark,

Don't assume I'm not reading.

I'll be working on the project tomorrow.

Cheers,
Alan

Where do I pay the back taxes?

As to the history of Pascal, I do know that had attention been paid to rapidly adding to the initial Wirth version early and not kept ring fenced it would likely be a major language today.  Indeed, Ada could have been built around it as a core instead of merely inspired by it had such attention been paid earlier...

« Last Edit: February 19, 2021, 12:12:07 am by AlanTheBeast »
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

 

TinyPortal © 2005-2018