Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-10

Accessing GPIO on RaspberryPi2 from Lazarus/FPC

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I have found a description of a unit implementing an interface to the gpio driver in the Free Pascal documentation. It is here: http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#5._PiGpio_Low-level_native_pascal_unit_.28GPIO_control_instead_of_wiringPi_c_library.29

However, it specifically lists the BCM2835 chip and not the BCM2836 which is used on the Pi2.

So I wonder if anyone here knows about an updated gpio.pas file which works on the Pi2?

Bo Berglund Developer in Sweden

Reply by email

Mark Morgan Lloyd
to Bo Berglund
Bo Berglund wrote 9 lines
I have found a description of a unit implementing an interface to the gpio driver in the Free Pascal documentation. It is here: http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#5._PiGpio_Low-level_native_pascal_unit_.28GPIO_control_instead_of_wiringPi_c_library.29 However, it specifically lists the BCM2835 chip and not the BCM2836 which is used on the Pi2. So I wonder if anyone here knows about an updated gpio.pas file which works on the Pi2?

I have already said elsewhere: exercise the interface using echo to /sys/class/gpio etc. first, since I would expect this to be the same irrespective of model.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Bo Berglund
to Alfred
Alfred wrote 12 lines

Very good suggestion, Thanks!

I noticed in the file PXL.Boards.RPi.pas the following note:

// The following option controls whether the code is optimized for Raspberry PI 2.
{.$DEFINE RPi2}

And further down I found that this define controls the address used for GPIO:

  FChipOffsetBase := {$IFDEF RPi2} $3F000 {$ELSE} $20000 {$ENDIF}; //

in pages (x 4096 bytes)

So it looks like it is going to solve my I/O control on the Pi2! Now I just have to figure which files to copy over to the Pi for this to work, the complete download is very big and most of it I really do not need...

Bo Berglund Developer in Sweden

Reply by email

Michael Ring
to Bo Berglund

I agree, this is a really, really nice find.

Not only because of the rpi code, their xml parser implementation is the most easiest to debug I have ever seen, not the usual pointer chaos seen in all the other implementations.

Hopefully there are even more gems hidden in this library.

Michael

Bo Berglund wrote 33 lines
On Fri, 09 Oct 2015 07:31:52 +0000, Alfred wrote: > Please have a look at: > http://www.afterwarp.net/products/pxl > https://github.com/yunkot/pxl > > Forum post: > http://forum.lazarus.freepascal.org/index.php/topic,29852.0.html?PHPSESSID=bf43911005bf788ab072b3d73d1bfb4f > > Pxl is a very well written library, capable of doing a lot, with the > inclusion of hardware access on RPi(2) ! > > See sample: > https://github.com/yunkot/pxl/tree/master/Samples/FreePascal/SingleBoard/RaspberryPI Very good suggestion, Thanks! I noticed in the file PXL.Boards.RPi.pas the following note: // The following option controls whether the code is optimized for Raspberry PI 2. {.$DEFINE RPi2} And further down I found that this define controls the address used for GPIO: FChipOffsetBase := {$IFDEF RPi2} $3F000 {$ELSE} $20000 {$ENDIF}; // in pages (x 4096 bytes) So it looks like it is going to solve my I/O control on the Pi2! Now I just have to figure which files to copy over to the Pi for this to work, the complete download is very big and most of it I really do not need...

Reply by email

Michael Van Canneyt
to Michael Ring
Michael Ring wrote 5 lines
I agree, this is a really, really nice find. Not only because of the rpi code, their xml parser implementation is the most easiest to debug I have ever seen, not the usual pointer chaos seen in all the other implementations.

The difference will be in speed, most likely.

Hopefully there are even more gems hidden in this library.

At first glance, it is a very nice piece of work, quite complete.

Michael.

Reply by email

Bo Berglund
to Bo Berglund: I have found a description of a unit implementing an interface to the gpio driver in the…
Bo Berglund wrote 9 lines
I have found a description of a unit implementing an interface to the gpio driver in the Free Pascal documentation. It is here: http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#5._PiGpio_Low-level_native_pascal_unit_.28GPIO_control_instead_of_wiringPi_c_library.29 However, it specifically lists the BCM2835 chip and not the BCM2836 which is used on the Pi2. So I wonder if anyone here knows about an updated gpio.pas file which works on the Pi2?

I have solved the problem now. This is how I modified pigpio.pas:
1) I added a define for RPI2 and used it in a conditional to set the REG_GPIO constant to $3F000 or $20000

2) I changed the device from /dev/mem to /dev/gpiomem This allowed the generated program to run as user pi.

3) I also added the Pi connector mapping defines into pigpio.pas so that any user program does not have to enter this in its own code. Just use RPI_P12 or similar in the user code.

Apart from this pigpio.pas stays the same as before.

Thanks to all that helped me come to this result!

Bo Berglund Developer in Sweden

Reply by email