Lazarus

Programming => General => Topic started by: woodengineer on June 29, 2012, 02:58:47 am

Title: Lazarus / RaspberyPi Hardware Library
Post by: woodengineer on June 29, 2012, 02:58:47 am
Hello,
please find attached a wrapper unit for Gordon Henderson's
wiringPi C library (https://projects.drogon.net/raspberry-pi/wiringpi) and a little Lazarus test program.
This library allows access to the RaspberryPi's GPIO pins as well as the PWM pin.
The RaspberryPi is an inexpensive $25 SBC that runs linux. Check it out at http://www.raspberrypi.org.
BTW Lazarus runs quite well on the Pi.
Have fun, I know I will! :D
Alex
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: marcov on June 29, 2012, 10:58:25 am
Which distro did you run Lazarus with?
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: woodengineer on June 29, 2012, 03:45:19 pm
Hello,
I am running ArchLinux, XFCE4, fpc 2.6 and Lazarus 0.9.30.4.
Got the fpc arm binaries from the freepascal website and then compiled Lazarus from source.
Works quite nice, haven't found any problems, just don't expect 2sec compile times.
But compared to e.g. Mono it fly's.
A "Build all" of this posts Hardware library sample app takes about 5sec (console).
A Gui app with a form and a button on it about  1:30sec and about 50sec on subsequent builds .
Also played around with Geany and FpGui which is faster, but not as comfortable as Lazarus.
Hope this helps.

Alex
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: DirkS on June 29, 2012, 05:35:30 pm
Marco,

FYI: I have FPC / Laz running on the debian wheezy distro for armel (http://www.raspberrypi.org/archives/1435 / http://www.raspberrypi.org/phpBB3/viewtopic.php?f=50&t=8071).
I just used apt-get to install both. Versions: FPC 2.6.0-3 (2012.05/07); Laz 09.30.4-1 Rev 35971

I tried to use BigChimp's fpcup (using fpcup-linux-armel from https://bitbucket.org/reiniero/fpcup), but that did not work (or not completely).

Gr.
Dirk.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: ludob on June 29, 2012, 06:02:35 pm
Quote
I tried to use BigChimp's fpcup (using fpcup-linux-armel from https://bitbucket.org/reiniero/fpcup), but that did not work (or not completely).
Do you stilll have any details or log files of what went wrong?
I've only tested it with --only=fpc,lazarus since the default install tries to install too much for my small arm system.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: jwdietrich on June 30, 2012, 02:17:25 pm
I am happy to read that Lazarus has arrived at the Pi.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: DirkS on July 01, 2012, 06:45:49 am
Quote
I tried to use BigChimp's fpcup (using fpcup-linux-armel from https://bitbucket.org/reiniero/fpcup), but that did not work (or not completely).
Do you stilll have any details or log files of what went wrong?
I've only tested it with --only=fpc,lazarus since the default install tries to install too much for my small arm system.
It's actually an fpc error (ran fpcup with --only=fpc,lazarus):
Quote
make[3]: Entering directory `/home/pi/fpc/utils/fpcmkcfg'
/bin/mkdir -p units/arm-linux
__missing_command_DATA2INC -b -s fppkg.cfg fppkg.inc fppkg
make[3]: __missing_command_DATA2INC: Command not found
make[3]: *** [fppkg.inc] Error 127
make[3]: Leaving directory `/home/pi/fpc/utils/fpcmkcfg'
make[2]: *** [fpcmkcfg_all] Error 2
make[2]: Leaving directory `/home/pi/fpc/utils'
make[1]: *** [utils_all] Error 2
make[1]: Leaving directory `/home/pi/fpc'
make: *** [build-stamp.arm-linux] Error 2
make: Leaving directory `/home/pi/fpc'

Info: Running make install for FPC:
Note that fpcup *does* continue with 'make install', which it probably should not do (?).
I killed the procedure at this point and the fpcup log file does not give any useful info.

Gr
Dirk
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: rmudryk on August 12, 2012, 04:17:25 am
Did a fresh download of weezy 7-15 from the raspberry pi website http://downloads.raspberrypi.org/images/raspbian/2012-07-15-wheezy-raspbian/2012-07-15-wheezy-raspbian.zip (http://downloads.raspberrypi.org/images/raspbian/2012-07-15-wheezy-raspbian/2012-07-15-wheezy-raspbian.zip) 

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install fpc
sudo apt-get install lazarus
sudo apt-get install libfbclient2

this is a estimation

http://www.inprox.net/pi/Raspberry-PI-Lazarus.png (http://www.inprox.net/pi/Raspberry-PI-Lazarus.png)

Rob
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: marcov on August 13, 2012, 11:51:09 am
__missing_command_DATA2INC -b -s fppkg.cfg fppkg.inc fppkg

That means

(1) you are attempting to compile a FPC without a full install of FPC.
(2) the codebase (svn checkout, unzipped source snapshot) has messed up datetime stamps


Point (1) means that you didn't fulfill the requirements to build FPC, and (2) is that you (or fpcup) didn't
even try to implement the workarounds.

(2) typically happens if you decompress a source archive made on a different OS, or do a SVN checkout on a
non standard filesystem that has different datestamp systems (like network drives), and/or use checkouts
between multiple OSes (that might have different time synchronization characteristics)
 
A workaround on *nix when bootstrapping on a new system is to "touch" the .inc files generated by data2inc and/or
other generator programs.  On Windows this is useless since touch doesn't come with windows or FPC.  Apparently FPCUP doesn't
implement it (it would require creating a list  what exactly is generated by data2inc)
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: ludob on August 13, 2012, 01:26:09 pm
The real problem is that fpcup starts with only a bootstrap compiler and binutils. At some stage in the make all process, data2inc is build in the fpc/utils directory and a little later fpmake calls data2inc but can't find it. Later in the make install process data2inc is copied to the fpc/bin/arm-linux directory but that is too late. Fpcup has solved this by adding the fpc/utils dir to the path before launching make. Perhaps the OP is using an older version of fpcup.

So yes it is (1) but IMHO also a shortcoming in the fpc make file.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: marcov on August 13, 2012, 03:39:32 pm
The real problem is that fpcup starts with only a bootstrap compiler and binutils. At some stage in the make all process, data2inc is build in the fpc/utils directory and a little later fpmake calls data2inc but can't find it. Later in the make install process data2inc is copied to the fpc/bin/arm-linux directory but that is too late. Fpcup has solved this by adding the fpc/utils dir to the path before launching make. Perhaps the OP is using an older version of fpcup.

So yes it is (1) but IMHO also a shortcoming in the fpc make file.

Yes and no. Of course the current state is imperfect and not terribly well documented, but the requirements are/were always clear. We hope that we can concentrate many of these requirements in fppkg/fpmake system but that is long term only.

A _full_ install is needed for automated bootstrap, but tweaking with just a cmdline compiler is possible on *nix targets with some care. (this is mainly meant to facilitate bootstrapping to a new target, and never was meant to be automable). The problem is mainly (2), while in general SVN is in a consistent state, ocassionally people make mistakes (and not check in the generated version) and some operations on checkouts can corrupt timestamps by fractions enough to select a different codepath by make. The automatic regenneration guards against that, but adds a dependency.

Some other problems are the creation of initial fpc.cfgs, symlinks (and I assume fpcup has already run into those, (2) is one of the rare ones)

FPCUP tries to do it fully automated without a full install, then it will run into exception (2). I think the workaround with fpc/utils is not correct (*) and then this will fail. If you really want to work around this, you need to touch all data2inc generated .incs.

(*) IIRC data2inc might be called in compiler/utils before data2inc is generated, and during crosscompiling a native target compiler will never reach te fpc/utils directory, only a cross compiler will.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: fredycc on August 13, 2012, 04:02:15 pm
Try with CodeTyphon.

http://www.pilotlogic.com/sitejoom/index.php/forum/other-cross-build-targets/2238-my-first-raspbian-app#2430 (http://www.pilotlogic.com/sitejoom/index.php/forum/other-cross-build-targets/2238-my-first-raspbian-app#2430)

regards
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: BigChimp on August 13, 2012, 04:48:21 pm
We hope that we can concentrate many of these requirements in fppkg/fpmake system but that is long term only.
I'd certainly be willing to help work on this, if only on the testing part, but I'm not sure what exactly needs to be done/what the requirements are.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: ludob on August 13, 2012, 07:46:58 pm
Quote
A _full_ install is needed for automated bootstrap
Quote
IIRC data2inc might be called in compiler/utils before data2inc is generated
So the "shortcoming in the fpc make file" was really an understatement.  data2inc is an internal dependency for make, created by make, but not always in time.
Quote
while in general SVN is in a consistent state, ocassionally people make mistakes (and not check in the generated version) and some operations on checkouts can corrupt timestamps by fractions enough to select a different codepath by make. The automatic regenneration guards against that, but adds a dependency.
But isn't that the wrong way around? Instead of putting internally build files under svn control and put a safeguard in place, logic says that one should only put sources under version control and build always. No more problems with different codepaths. Lazarus has a similar problem with some lrs resource files under version control.  It also happens that developers forget to regenerate them before committing the new sources with sometimes build failures as a result.
Quote
If you really want to work around this, you need to touch all data2inc generated .incs.
A touch will just fool the guard. The inc doesn't not correspond with the source if the developer forgot to regenerate them. So, touch will avoid the data2inc missing error but the outcome is a fpc that does not correspond with the sources.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: marcov on August 13, 2012, 10:10:00 pm
Quote
A _full_ install is needed for automated bootstrap
Quote
IIRC data2inc might be called in compiler/utils before data2inc is generated
So the "shortcoming in the fpc make file" was really an understatement.  data2inc is an internal dependency for make, created by make, but not always in time.

The dependency on the bootstrap is a full FPC install. A full FPC install contains data2inc. There is no shortcoming.

There is a  "cmdline compiler only" shortcut ONLY on open source *nix (since other platforms require "make" "binutils" etc) for people that know what they are doing. But that is a workaround for quick and dirty work, not an official supported solution.

The cmdline compiler-only route was never official. It just works mostly, and was somewhat documented in the buildfaq to help people keep machines up to date with minimal dependencies.

That doesn't mean that you can't think about building on the standalone compiler, but big changes in the current codebase wrt fpcmake are unlikely,
since it is both a production and declared legacy. As usual with longterm infrastructural work on the successor has stalled.

Quote
Quote
while in general SVN is in a consistent state, ocassionally people make mistakes (and not check in the generated version) and some operations on checkouts can corrupt timestamps by fractions enough to select a different codepath by make. The automatic regenneration guards against that, but adds a dependency.
But isn't that the wrong way around? Instead of putting internally build files under svn control and put a safeguard in place, logic says that one should only put sources under version control and build always.

That's something for any new system to attempt. The old system already depends on way too many externals that are immutable (starting with make)

Quote
No more problems with different codepaths. Lazarus has a similar problem with some lrs resource files under version control.  It also happens that developers forget to regenerate them before committing the new sources with sometimes build failures as a result.

Actually the filesystem thing (having sources shared between multiple OSes or on network drives, extracting archives made on different OSes that cause date rounding errors during file creation) is more common.

Quote
Quote
If you really want to work around this, you need to touch all data2inc generated .incs.
A touch will just fool the guard. The inc doesn't not correspond with the source if the developer forgot to regenerate them. So, touch will avoid the data2inc missing error but the outcome is a fpc that does not correspond with the sources.

Then your only choice is to follow the official way, and always require a proper installation.

I don't think touching is so bad. It might mask a very short transient problem in rare cases, but it will save you a lot of trouble where people have moved files across filesystem bounderies. Most of such forgotten makefile regenerations are for platforms that are still under development anyway. (which is why they go unnoticed)
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: BigChimp on August 14, 2012, 11:40:11 am
Quote
I tried to use BigChimp's fpcup (using fpcup-linux-armel from https://bitbucket.org/reiniero/fpcup), but that did not work (or not completely).
Do you stilll have any details or log files of what went wrong?
I've only tested it with --only=fpc,lazarus since the default install tries to install too much for my small arm system.
It's actually an fpc error (ran fpcup with --only=fpc,lazarus):
Quote
make[3]: Entering directory `/home/pi/fpc/utils/fpcmkcfg'
/bin/mkdir -p units/arm-linux
__missing_command_DATA2INC -b -s fppkg.cfg fppkg.inc fppkg
make[3]: __missing_command_DATA2INC: Command not found
make[3]: *** [fppkg.inc] Error 127
make[3]: Leaving directory `/home/pi/fpc/utils/fpcmkcfg'
make[2]: *** [fpcmkcfg_all] Error 2
make[2]: Leaving directory `/home/pi/fpc/utils'
make[1]: *** [utils_all] Error 2
make[1]: Leaving directory `/home/pi/fpc'
make: *** [build-stamp.arm-linux] Error 2
make: Leaving directory `/home/pi/fpc'

Info: Running make install for FPC:
Note that fpcup *does* continue with 'make install', which it probably should not do (?).
I killed the procedure at this point and the fpcup log file does not give any useful info.

Thanks Dirk, we opened a bug report on it:
https://bitbucket.org/reiniero/fpcup/issue/45/make-sure-data2inc-exists-before-make-all (https://bitbucket.org/reiniero/fpcup/issue/45/make-sure-data2inc-exists-before-make-all)
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: muratech on August 19, 2012, 08:23:59 pm
Hi all

I am a noob when it comes to linux or anything similar. Have been working with Delphi on Windows for years. Here's my question -
1) Installed Lazarus
2) Downloaded the wrapper for GPIO.
3) Tried running demo program.

Getting the following errors -

Quote
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: error: raspberry uses VFP register arguments, ./wiringPi/wiringPi.o does not
/usr/bin/ld: failed to merge target specific data of file ./wiringPi/wiringPi.o
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
raspberry.lpr(46,47) Error: Error while linking
raspberry.lpr(46,47) Fatal: There were 1 errors compiling module, stopping
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: woodengineer on August 21, 2012, 05:15:30 pm
Hi all

I am a noob when it comes to linux or anything similar. Have been working with Delphi on Windows for years. Here's my question -
1) Installed Lazarus
2) Downloaded the wrapper for GPIO.
3) Tried running demo program.

Getting the following errors -

Quote
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: error: raspberry uses VFP register arguments, ./wiringPi/wiringPi.o does not
/usr/bin/ld: failed to merge target specific data of file ./wiringPi/wiringPi.o
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.22 assertion fail ../../bfd/elf32-arm.c:12049
raspberry.lpr(46,47) Error: Error while linking
raspberry.lpr(46,47) Fatal: There were 1 errors compiling module, stopping

Hello muratech,
I am running Archlinux not Debian,
Try to recompile the the wiringPi.c file to get a new wiringPi.o file as described in the readme.txt file of the lazwiringpi folder.

" The source file for Gordon's library is inside the wiringPi subdirectory. You can recompile
the library by executing a simple gcc -c wiringPi.c.
The resulting wiringPi.o file is whats used by pascal."

Also, your resulting program must be run as root.
Hope this helps!

Alex
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: muratech on August 21, 2012, 07:51:12 pm
 :) Thanks ALex
Busy installing ARCH now and will try this out.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: muratech on August 27, 2012, 07:42:44 pm
Thanks Woodengineer.
I did a recompile of Wiringpi.

I need to run a program with a GUi in StartX. Is there a way I can do this as root.
Program is running but can't read anything from Pins, tested in Python and my wirring is correct.

Thanks
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: avra on November 19, 2012, 03:12:13 pm
I need to run a program with a GUi in StartX. Is there a way I can do this as root.
Have you tried to start terminal from the desktop, navigate to your GUI executable, and start executable with sudo from command line? Does that work? Can you check if your binary is flagged as executable?
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: marun on December 01, 2012, 09:39:47 am
Hello,
please find attached a wrapper unit for Gordon Henderson's
wiringPi C library (https://projects.drogon.net/raspberry-pi/wiringpi) and a little Lazarus test program.
This library allows access to the RaspberryPi's GPIO pins as well as the PWM pin.
The RaspberryPi is an inexpensive $25 SBC that runs linux. Check it out at http://www.raspberrypi.org.
BTW Lazarus runs quite well on the Pi.
Have fun, I know I will! :D
Alex
i tried to use your unit but it doesnt work it crashes on pinMode "esternal error SIGSEGV"
where i have to copy files from your unit?
here is my project http://leteckaposta.cz/556983847 (http://leteckaposta.cz/556983847) (it is fan control)
edit: i added "if wiring pisetup..." and it ends with error (wiringpisetup=-1) do you know where is problem?
edit2: finally it works but only as a root
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: Max12 on December 04, 2012, 09:37:00 pm
why it works only when starting by root????

I've exact the same problem!
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: DirkS on December 05, 2012, 12:41:32 am
why it works only when starting by root????
IIRC accessing GPIO functions on the PI requires root priviliges.
You can use 'sudo <yourprogramname>' to start the compiled program

Gr.
Dirk
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: marun on December 08, 2012, 07:11:50 pm
i made this test program because i want to verify pinout but if i want change log. level of any pin it write access violation (started as a root) does anybody know where is problem? poject is here http://leteckaposta.cz/356175095 (http://leteckaposta.cz/356175095)
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: lynnr on January 13, 2013, 11:02:56 pm
Hello All,

I'm trying to get my Raspberry Pi working using the wiringPi library, but haven't had any success.  I'm new to this, I've only had my Pi for about 1 month. 

Using Raspbian wheezy image, I was able to install Lazarus and compile and run a hello world program.  Next, installed wiringpi using directions on: //projects.drogon.net/raspberry-pi/wiringpi/download-and-install/  . All went smooth, so next I compiled the example(lazwiringpi.pas) from the beginning of this topic using the IDE. The compile completed normally.
But when I execute I get the following error:


pi@raspberrypi ~/lazarus/lazwiringpi $ sudo ./raspberryStarting RaspberryPi
An unhandled exception occurred at $000449F4 :
EAccessViolation : Access violation
  $000449F4


Help would be much appreciated.
Lynn
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: jwdietrich on January 27, 2013, 08:10:12 pm
An alternative, and perhaps simpler, way to access the Pi's GPIO ports is via encapsulated Unix shell calls. See http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Hardware_access_via_encapsulated_shell_calls for an example.

This method is directly supported by Lazarus / Free Pascal and doesn't require installation of any additional libraries or packages. Of course, your application has to be run with root privileges.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: vcp_ai on March 04, 2013, 07:05:33 pm
An alternative, and perhaps simpler, way to access the Pi's GPIO ports is via encapsulated Unix shell calls. See http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Hardware_access_via_encapsulated_shell_calls for an example.

This method is directly supported by Lazarus / Free Pascal and doesn't require installation of any additional libraries or packages. Of course, your application has to be run with root privileges.
Hi,  can you give an example of how to READ a GPIO port into fpc, using fpsystem ???

Regards
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: jwdietrich on April 28, 2013, 08:39:33 pm
Hi,  can you give an example of how to READ a GPIO port into fpc, using fpsystem ???

I can give an example to read the status of a port with native FPC methods (fpopen, fpread, fpclose etc.). This is a more elegant solution than the detour over fpsystem.

See http://wiki.lazarus.freepascal.org/Lazarus_on_Raspberry_Pi#Reading_the_status_of_a_port for a working example.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: picstart on April 28, 2013, 11:10:52 pm
Just keep in mind that GPIO ( working with pins) on the rasp pi is a restricted operation and often needs to be run with root privileges that usually means the lazarus IDE or the o file needs to run from root. Other things like I2C are less restricted
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: jwdietrich on April 28, 2013, 11:22:37 pm
Just keep in mind that GPIO ( working with pins) on the rasp pi is a restricted operation and often needs to be run with root privileges that usually means the lazarus IDE or the o file needs to run from root.

That is correct. For automated operation it may be advisable to write a shell script that calls the executable via sudo.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: rmudryk on May 18, 2013, 06:15:59 pm
This works but you do not have to expose the entire OS to Root access, as well as run Lazarus as root.  But because these are dynamic devices you have to run a script in rc.local or something as root to give yourself permissions to write on every reboot or runlevel change.

Example command line:
sudo echo 4 > /sys/class/gpio/export
sudo echo out > /sys/class/gpio4/direction
sudo chmod 666 > /sys/class/gpio4/value

now because the permissions are rw rw rw  world can read/write to gpio4

you can add this kinda stuff to the rc.local in the /etc  without the sudo, as that runs as root on boot up, so your System is GPIO ready on boot for normal users to use.


i2c is a bit different, I found these instructions in a word document for settting up i2c on the raspberry pi, but I use this all the time instead of running lazarus as "Root".  I am sorry but I can't remember the link to these instructions, but thanks!  it was the key to cleaning up this debacle of having to be root for me.  I also hear there is a more formal program to do all this in unix as well. 

Once the reboot has finished you need to make the ports active by running this command:

   $sudo modprobe i2c-dev

 Now you should be able to see the i2c ports listed in your /dev/ directory

   $ls /dev/i2c*

You should see /dev/i2c-0 and /dev/i2c-1 listed. To be able to use these ports you need to give yourself permission to access them.

   $sudo chmod o+rw /dev/i2c*

Now your i2c ports will be ready for you to use. You will have to run the modprobe and chmod commands every time you login to activate the ports and apply the permissions. If you wish to automate this process so the commands are run every time you log in then you can edit /etc/rc.local and add the commands in.



Just keep in mind that GPIO ( working with pins) on the rasp pi is a restricted operation and often needs to be run with root privileges that usually means the lazarus IDE or the o file needs to run from root. Other things like I2C are less restricted
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: bartdereu on August 10, 2013, 07:05:57 pm
When i try the WiringPi example in Lazarus i get :

Code: [Select]
..
/usr/bin/ld:error : raspberry uses VFP register arguments, .wiringPi/wiringPi.o does not
/usr/bin/ld: failed to merge target specific data of file ./wiringPi/wiringPi.o
..

Is there someone who can help me trough getting the PiFace board working with Lazarus ?
I'm getting pretty fast grey hair the last few days!  :P


I think i tried every single piece of pascal code to make the PiFace respond to me, but nothing
has been working so far. The Piface-Emulator does work fine.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: rmudryk on August 10, 2013, 09:05:10 pm
Are you running as root or a user?   Always try as root first, and make sure the devices are already created.  I have not played with lazarus lately, but I have felt your pain before.

When i try the WiringPi example in Lazarus i get :

Code: [Select]
..
/usr/bin/ld:error : raspberry uses VFP register arguments, .wiringPi/wiringPi.o does not
/usr/bin/ld: failed to merge target specific data of file ./wiringPi/wiringPi.o
..

Is there someone who can help me trough getting the PiFace board working with Lazarus ?
I'm getting pretty fast grey hair the last few days!  :P


I think i tried every single piece of pascal code to make the PiFace respond to me, but nothing
has been working so far. The Piface-Emulator does work fine.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: bartdereu on August 10, 2013, 10:27:10 pm
Yes i am running it as a root. Man, i thought the raspberry pi was a neat thing but the piface
is going to make me crazy !
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: avra on August 11, 2013, 12:53:34 am
And have you tried to google for "uses VFP register arguments"? The first link explains it all:
http://stackoverflow.com/questions/9753749/arm-compilation-error-vpf-registered-used-by-executable-not-object-file
Your compiled code and that lib do not match. You are trying to link code compiled with soft-float ABI with another hard-float ABI code. Search the net if you don't know what is that and why is that important with ARM. That can be fixed, but it would be easier for you to try another way to access hardware as others have already suggested. The link is still the same: http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Accessing_external_hardware. It seams that rpi_hal directly supports piface as mentioned here: http://forum.lazarus.freepascal.org/index.php/topic,20991.msg126708.html#msg126708.

I would really suggest you to learn more about ARM Linux, architecture and compiling for ARM, and also about RPi from it's site and wiki and about similar RPi projects, and search this forum and wikis for anything about RPi. You can also find valuable info on PilotLogic forum. Otherwise you will run into many walls like this one.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: picstart on August 11, 2013, 03:36:06 am
Let's hope most won't want to use the Raspbery pi as a slave on I2C.... just as well because the pi folks didn't bring a trace out to the GPIO to support the slave clock. A pi must always be the I2C master which can be limiting if the I2C bus already has a working master.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: rmudryk on August 11, 2013, 04:20:24 pm
They make I2C slave to SPI master chips that would solve that problem with hardware.  Or a write a software I2C slave.

Let's hope most won't want to use the Raspbery pi as a slave on I2C.... just as well because the pi folks didn't bring a trace out to the GPIO to support the slave clock. A pi must always be the I2C master which can be limiting if the I2C bus already has a working master.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: avra on August 11, 2013, 05:12:56 pm
Let's hope most won't want to use the Raspbery pi as a slave on I2C.... just as well because the pi folks didn't bring a trace out to the GPIO to support the slave clock. A pi must always be the I2C master which can be limiting if the I2C bus already has a working master.
A need to use RPi as a I2C slave will be very rare. People will mostly want to interface I2C slaves as a master and that's where RPi fits very well. Even if you have such a specific need when you design your own project you are aware of this problem and there are many ways to design around it.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: rmudryk on August 11, 2013, 06:51:00 pm
Being such a complete IDE, I would really hope Lazarus would be added into the main Distribution of Raspberry PI at some point.  It is probably one of the most, if not the most complete and intuitive IDEs available, and far superior than what comes with the default Debian Squeeze distro now.  There are newer and better ways to allow users access to a virtual device in /dev that does not require having to do permissions every boot, I just forgot where. 
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: avra on August 12, 2013, 08:19:09 am
Being such a complete IDE, I would really hope Lazarus would be added into the main Distribution of Raspberry PI at some point.
It will hardly happen, because foundation owners and Pi creators like Python. Even Pi's name came as an association to Python. For something simpler they chose Scratch, and for something low level they chose C.

What I would really like to see is that Debian finally moves from that old 0.9.30 to something newer. That would help a lot.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: bartdereu on August 12, 2013, 03:49:34 pm
Ofcourse i've tried different approaches to get the PiFace running, and i almost found a very good one.

You must have (ofcourse) GPIO installed correctly, then you can just execute gpio commands with the fpsystem(' ')
function. Don't forget to add 'Unix' in the uses clause of the unit.
 
Code: [Select]
Procedure TForm1.Checkbox1Change(Sender:TObject)
begin
 if Checkbox1.Checked then
  gReturncode:=fpsystem('gpio -p write 200 1')
else
  gReturncode:=fpsystem('gpio -p write 200 0');
end;

A little explanation : With the gpio installed the piface input output ports are situated on ports 200-207.
the fact that things like this are NOT explained in the PiFace manual , makes it very difficult to work with
boards like this.
This works ok, but i'm now struggling to read the state of a button (button 1 = 200)

Code: [Select]
Procedure TForm1.Timer1Timer(Sender:TObject)
begin
  gReturncode:=fpsystem('gpio -p read 200')
  if gReturncode=0 then checkbox2.checked:=true;
  else if gReturncode=1 then checkbox2.checked:=false;
end;

The command 'gpio -p read 200' in the terminal gives me a '1' when the button is not
pressed and a '0' when it does (probably bc it goes low)
So far i have been unable to get the result with this Lazarus code. The gReturncode
remains 0 all the time. Maybe pfsystem doesn't give me back a result ? is there another
way to execute the gpio line and get the result back ?
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: bartdereu on August 12, 2013, 05:32:23 pm
And the final solution :  ;D

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Unix,BaseUnix;

type

  { TForm1 }

  TForm1 = class(TForm)
    ApplicationProperties1: TApplicationProperties;
    Button1: TButton;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Edit1: TEdit;
    Memo1: TMemo;
    Timer1: TTimer;
    procedure ApplicationProperties1Idle(Sender: TObject; var Done: Boolean);
    procedure CheckBox1Change(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  gReturncode,a : longint;
  return: integer;

implementation

{$R *.lfm}

{ TForm1 }

// Set the output high for output 1:

procedure TForm1.CheckBox1Change(Sender: TObject);
begin
  if Checkbox1.Checked then
        gReturncode:=fpsystem('gpio -p write 200 1')
  else
    gReturncode:=fpsystem('gpio -p write 200 0');

  end;

// Read the state of button 1 on the PiFace :

procedure TForm1.ApplicationProperties1Idle(Sender: TObject; var Done: Boolean);
var FileDesc:Integer;
  buttonStatus:String[1] ='1';
begin
 try
 return:=fpsystem('gpio -p read 200 > inputs.dat');
 fileDesc:=fpopen('inputs.dat',O_RdOnly);
 if FileDesc > 0 Then
       begin
         gReturncode:=fpread(fileDesc,buttonStatus[1],1);
         if buttonStatus ='0' then
               checkbox2.Checked:=true
               else
                 checkbox2.Checked:=false;
       end;
  finally
  gReturncode :=fpclose(fileDesc);
end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
 fpsystem('gpio -p mode 200 up');
end;

end.

Hope this helps someone some day :-)
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: bartdereu on August 14, 2013, 10:34:07 pm
Apparently this approach has a nasty side -effect . It read/writes to the SD card several times a second,
and an SD card is not well suited for this kind of things. After on million writes the best is just gone. That
would be within a few days.

Now i've been trying to use a TProcess to get the output of the 'gpio -p read 200' directly into my progam,
but i'm running in more troubles then i'd like. Acces violations at the NumBytesAvailable :

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var bufstr:string;
  buflen:integer;
begin
AProcess:= TProcess.Create(nil);
AStringlist := Tstringlist.create;
AProcess.commandline := 'echo 17';
Aprocess.Execute;

try
Aprocess.Execute;
BufStr := '';
repeat
if aProcess.Output.NumBytesAvailable > 0 then
begin
BufLen := Length(BufStr);
SetLength(BufStr, BufLen + aProcess.Output.NumBytesAvailable);
aProcess.Output.Read(BufStr[BufLen+1],aProcess.Output.NumBytesAvailable);
end;
until not aProcess.Running;
finally
aProcess.Free;
edit1.text:=BufStr;

end;
end;

Did anyone succeed to get a TProcess get an output in Lazarus ?

Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: lazaursrotton on March 14, 2015, 02:13:28 am

it will not  require a recompile
 linklib to installed shared lib

translated more of the lib from

 2.23 wiringpi
 
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: Pelican on May 26, 2015, 01:40:31 am
I've downloaded the unit a year ago and it worked on the older Pis but now I have a Pi 2 which needs the new version of the wiringPi but when I try to build any program using that new object files the linker gives me the following error messages:

Code: [Select]
/usr/bin/ld.bfd: wiringPi.o undefined reference to symbol '__aeabi_idiv@@GCC3.5'
//lib/arm-linux-gnueabihf/libgcc_s.so.1: error adding symbols: DSO missing from command line

If I link the lazwiringpi's object file then no error but the gpio function doesn't work.
Could you help me how can I solve this linker issue?
I tried to make the object files by myself - no change.

wiringPi 2.25
Lazarus 0.9.30.4-6

I added to the wrapper more functions in wiringPi (and the spi, i2c and serial functions too) send me an email if you want the sources.

Edit:
I think this is a similar problem, but I have no idea how could I fix this.
http://glandium.org/blog/?p=2510
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: Pelican on June 14, 2015, 09:34:21 am
I've updated my Lazarus to v1.5 and fpc to the latest but the problem is still there, cannot compile any code which use the wiringPi.o.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: DonAlfredo on June 14, 2015, 09:50:07 am
Try to add this to the compiler options when compiling for RPi2:
Code: [Select]
-dFPC_ARMHF -CpARMV7A -CaEABIHF -CfVFPv3 -OoFASTMATH
if you use hardfloat for RPi2.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: Pelican on June 15, 2015, 06:11:05 pm
Hi,

Thank you for your reply.
I tried to put those to the Project options/Compilation and Linking/Linking/pass to linker...
I've got unrecognized option warning for these options: -CpARMV7A -CaEABIHF -CfVFPv3
I removed them and got a new error message: Error while linking

Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: DonAlfredo on June 15, 2015, 07:01:00 pm
Could it be that you have a compiler that does not support hardfloat ?
I presume you need hardfloat due to the info in your post:
Code: [Select]
//lib/arm-linux-gnueabihf/libgcc_s.so.1: error adding symbols: DSO missing from command line
If your compiler does hardfloat, it would support the instructions I gave you.
So, check your compiler would be my advice !
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: Pelican on June 15, 2015, 10:54:36 pm
This is the compiler: Free Pascal Compiler version 3.1.1 [2015/05/28] for arm
Based on it's help it supports all of the options you gave but I put all those to the linker's option...  :o
How can I give these option to the compiler?
I tried to put Project options/Compiler options/Additions and overrides/Custom and got this error message>

Code: [Select]
Compile Project, Target: homeserver: Exit code 256, Errors: 1, Warnings: 2, Hints: 1
main.pas(8,79) Hint: Unit "wiringPi" not used in Main
homeserver.lpr(21,0) Warning: "crtbegin.o" not found, this will probably cause a linking failure
homeserver.lpr(21,0) Warning: "crtend.o" not found, this will probably cause a linking failure
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: /home/pi/projects/homeserver/wiringPi.o: undefined reference to symbol '__aeabi_idiv@@GCC_3.5'
//lib/arm-linux-gnueabihf/libgcc_s.so.1: error adding symbols: DSO missing from command line
[8.977] Executing "/usr/bin/ld" with command line "  --dynamic-linker=/lib/ld-linux-armhf.so.3    -L. -o homeserver link.res"
homeserver.lpr(21,0) Error: Error while linking

Edit:

Anyway, I tried the h2wiringpi from the previous page and it seems it's working...

The
{$linklib libwiringPi}
just did the trick.
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: lazaursrotton on June 16, 2015, 12:25:09 am
https://github.com/laz2wiringpi/lazI2cdev
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: lazaursrotton on June 16, 2015, 12:26:21 am
https://github.com/laz2wiringpi/laz2wiringpi
Title: Re: Lazarus / RaspberyPi Hardware Library
Post by: Pelican on June 18, 2015, 11:07:02 pm
I've put SPI, I2C, serial and other functions to it.
http://pel.hu/down/libwiringpi.pas
Title: Re: Lazarus / RaspberyPi 2 model B Hardware Library
Post by: kaptindan on February 15, 2016, 03:53:43 pm
Hello, newbe here! I've been working with the Raspberry Pi 2 Model B and trying to access the GPIO....no luck so far using h2wiringPi...any ideas?????
TinyPortal © 2005-2018