Sign in Join

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

Mailing lists / lazarus / 2015-09

Where is hwiringPi?

11 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Donald Ziesig

Hi All!

It looks like this is Raspberry PI day :-) .

I have Lazarus working on a RPi 2 B with no problems til now.

(Started with monitor, keyboard and mouse till I got ssh and vnc setup, then switched to Remmina on my laptop via tcp/ip).

I need to access the GPIO pins from my Lazarus program. I have found the C library "wiringPi" and many references to the FPC "hwiringPi" package that wraps it, but I'll be darned if I can find "hwiringPi" itself.

Everything points to Alex's Lazarus forum post which starts:

"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."

I can't find the attachment, and I can't find any other references to the code.

Help, please :'( .

Thanks,

Don Ziesig

Reply by email

Maxim Ganetsky
to Donald Ziesig

19.09.2015 1:10, Donald Ziesig ?????:

Show quoted text 12 lines
Hi All! It looks like this is Raspberry PI day :-) . I have Lazarus working on a RPi 2 B with no problems til now. (Started with monitor, keyboard and mouse till I got ssh and vnc setup, then switched to Remmina on my laptop via tcp/ip). I need to access the GPIO pins from my Lazarus program. I have found the C library "wiringPi" and many references to the FPC "hwiringPi" package that wraps it, but I'll be darned if I can find "hwiringPi" itself.

Strange, that you couldn't find it. This site:

https://github.com/AkselMeola/Pascal-projects-on-Raspberry/tree/master/Morse-code-translator

is the first for the "hwiringPi" Google query.

Best regards, Maxim Ganetsky mailto:

Reply by email

Donald Ziesig
to Maxim Ganetsky
Maxim Ganetsky wrote 22 lines
19.09.2015 1:10, Donald Ziesig ?????: > Hi All! > > It looks like this is Raspberry PI day :-) . > > I have Lazarus working on a RPi 2 B with no problems til now. > > (Started with monitor, keyboard and mouse till I got ssh and vnc setup, > then switched to Remmina on my laptop via tcp/ip). > > I need to access the GPIO pins from my Lazarus program. I have found > the C library "wiringPi" and many references to the FPC "hwiringPi" > package that wraps it, but I'll be darned if I can find "hwiringPi" > itself. Strange, that you couldn't find it. This site: https://github.com/AkselMeola/Pascal-projects-on-Raspberry/tree/master/Morse-code-translator is the first for the "hwiringPi" Google query.

Got it. I have cataract surgery upcoming :-( , that would have helped me see in when I looked at it :-[ . Thanks.

Don Z

Reply by email

Maxim Ganetsky
to Donald Ziesig

19.09.2015 1:39, Donald Ziesig ?????:

Show quoted text 24 lines
On 09/18/2015 06:21 PM, Maxim Ganetsky wrote: > 19.09.2015 1:10, Donald Ziesig ?????: >> Hi All! >> >> It looks like this is Raspberry PI day :-) . >> >> I have Lazarus working on a RPi 2 B with no problems til now. >> >> (Started with monitor, keyboard and mouse till I got ssh and vnc setup, >> then switched to Remmina on my laptop via tcp/ip). >> >> I need to access the GPIO pins from my Lazarus program. I have found >> the C library "wiringPi" and many references to the FPC "hwiringPi" >> package that wraps it, but I'll be darned if I can find "hwiringPi" >> itself. > > Strange, that you couldn't find it. This site: > > https://github.com/AkselMeola/Pascal-projects-on-Raspberry/tree/master/Morse-code-translator > > > is the first for the "hwiringPi" Google query. > Got it. I have cataract surgery upcoming :-(

Good luck with it.

, that would have helped me see in when I looked at it :-[ . Thanks.
Best regards, Maxim Ganetsky mailto:

Reply by email

Bo Berglund
to Maxim Ganetsky: 19.09.2015 1:10, Donald Ziesig ?????: Strange, that you couldn't find it. This site:…
Maxim Ganetsky wrote 19 lines
19.09.2015 1:10, Donald Ziesig ?????: > Hi All! > > It looks like this is Raspberry PI day :-) . > > I have Lazarus working on a RPi 2 B with no problems til now. > > (Started with monitor, keyboard and mouse till I got ssh and vnc setup, > then switched to Remmina on my laptop via tcp/ip). > > I need to access the GPIO pins from my Lazarus program. I have found > the C library "wiringPi" and many references to the FPC "hwiringPi" > package that wraps it, but I'll be darned if I can find "hwiringPi" itself. Strange, that you couldn't find it. This site: https://github.com/AkselMeola/Pascal-projects-on-Raspberry/tree/master/Morse-code-translator is the first for the "hwiringPi" Google query.

Strangely I also need this for my RPi2 project!
The software needs to pull two relays as part ofthe automation. So GPIO access is needed.
Now that it popped up may I inject a question here:

The hiwiringpi.pas file is an interface to something else written in C if I understood the text correctly.
How does that work? It seems like I have to compile something in C on the Pi as well and it produces an *.o file. Does that act like a dll in Windows or like a lib file that gets linked into the final executable?

I am not really (yet) familiar wth programming in Linux....

Bo Berglund Developer in Sweden

Reply by email

Graeme Geldenhuys
to Bo Berglund
Bo Berglund wrote
The hiwiringpi.pas file is an interface to something else written in C if I understood the text correctly.

As far as I know there is another pure Object Pascal GPIO package which has no other dependencies. Maybe that would be a better option than the C wrapper version.... I'll see if I bookmarked it or something.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Donald Ziesig
to Bo Berglund: On Sat, 19 Sep 2015 01:21:25 +0300, Maxim Ganetsky Strangely I also need this for my RPi2…
Bo Berglund wrote 36 lines
On Sat, 19 Sep 2015 01:21:25 +0300, Maxim Ganetsky wrote: > 19.09.2015 1:10, Donald Ziesig ?????: >> Hi All! >> >> It looks like this is Raspberry PI day :-) . >> >> I have Lazarus working on a RPi 2 B with no problems til now. >> >> (Started with monitor, keyboard and mouse till I got ssh and vnc setup, >> then switched to Remmina on my laptop via tcp/ip). >> >> I need to access the GPIO pins from my Lazarus program. I have found >> the C library "wiringPi" and many references to the FPC "hwiringPi" >> package that wraps it, but I'll be darned if I can find "hwiringPi" itself. > Strange, that you couldn't find it. This site: > > https://github.com/AkselMeola/Pascal-projects-on-Raspberry/tree/master/Morse-code-translator > \ > is the first for the "hwiringPi" Google query. Strangely I also need this for my RPi2 project! The software needs to pull two relays as part ofthe automation. So GPIO access is needed. Now that it popped up may I inject a question here: The hiwiringpi.pas file is an interface to something else written in C if I understood the text correctly. How does that work? It seems like I have to compile something in C on the Pi as well and it produces an *.o file. Does that act like a dll in Windows or like a lib file that gets linked into the final executable? I am not really (yet) familiar wth programming in Linux....

There is a package written in C called wiringPi which is available on github. You will need to clone it and follow the instructions to build it. The hwiringPi package links to the wiringPi.o file in the wiringPi directory. As of right now, I am getting a linking error which seems to be rather common (there are many references to it online) because I am using the latest RPi version 2 B.

Unfortunately my ISP has dropped my connection due to a thunderstorm so I am working on my cell phone (very slow). I think I'll wait until tomorrow to look any further.

Don Z

Reply by email

Dennis
to Donald Ziesig

I have written a small program using FPC to run on Rasp Pi to connect, via i2c, to a temperature/humidity sensor and save the readings into a MySQL database.
Initially, I tried to use wiringPi, but I later found out it was very simple to directly connect to i2c via fpRead() . It was as simple as:

const
   I2C_SLAVE = 1795;
   CMD_SOFT_RESET : byte = $FE;
   CMD_READ_TEMP_NOHOLD : byte = $F3;
   CMD_READ_HUM_NOHOLD : Byte =  $F5;
var TheDeviceNo : integer = $40;
     ThePath : String = '/dev/i2c-1';
     DeviceHandle : integer;

.....

    DeviceHandle := fpopen(ThePath,O_RDWR); //Open the I2C bus in

Read/Write mode

    iio:= FpIOCtl(DeviceHandle, I2C_SLAVE, pointer(TheDeviceNo)); //Set

options

    If (iio  0) or (DeviceHandle < 0) Then begin
       fpclose(DeviceHandle);
       DeviceHandle := 0;
       raise Exception.Create('Failed to open '+ThePath+' device#
0x'+IntToStr(TheDeviceNo));
    end;
//to read a floating variable:
function ReadFloat(const TheRegNo: byte; TheOffset,  TheSlope: double):
double;
var aBytes : array[0..3] of byte;
   i : integer;
begin
  fpwrite(DeviceHandle, TheRegNo, 1);
  Sleep(100); //for safety only. not sure if needed
  Fillchar(aBytes, sizeof(aBytes), 0);
  fpread(DeviceHandle, aBytes, 3);
//the following is only specific to the themometer which requires some
conversion in the data read.
  if IsCRC8Ok(aBytes) then begin
    result := ((aBytes[0] shl 8) or aBytes[1] ) and ($FFFC);
    result  :=result/65536;
    result := result * TheSlope + TheOffset;
  end else
    raise ECRCError.Create('');
end;
//to reset the themometer
   fpwrite(DeviceHandle, CMD_SOFT_RESET, 1);

Reply by email

Marc Santhoff
to Bo Berglund: On Sat, 19 Sep 2015 01:21:25 +0300, Maxim Ganetsky Strangely I also need this for my RPi2…
Bo Berglund wrote 6 lines
The hiwiringpi.pas file is an interface to something else written in C if I understood the text correctly. How does that work? It seems like I have to compile something in C on the Pi as well and it produces an *.o file. Does that act like a dll in Windows or like a lib file that gets linked into the final executable?

Yes, it does. A statically linked library (.a in contrast to a dynamically linked library .so) is nothing more than an archive holding a bunch of .o files. As long as the compiler creates the same type of object file (ELF mostly) thosse are the same created when compiling pascal files. This .o files can be linked into a pascal program.

If using dynamical linking things are different, but in general it works the same as using dll files on Windows.

I did use object files compiled from C to use some USB functions withstanding my translation trials vigorously. ;)

Marc Santhoff

Reply by email

Marc Santhoff
to Marc Santhoff
Marc Santhoff wrote 19 lines
On Fr, 2015-09-18 at 18:50 -0500, Bo Berglund wrote: > The hiwiringpi.pas file is an interface to something else written in C > if I understood the text correctly. > How does that work? It seems like I have to compile something in C on > the Pi as well and it produces an *.o file. Does that act like a dll > in Windows or like a lib file that gets linked into the final > executable? Yes, it does. A statically linked library (.a in contrast to a dynamically linked library .so) is nothing more than an archive holding a bunch of .o files. As long as the compiler creates the same type of object file (ELF mostly) thosse are the same created when compiling pascal files. This .o files can be linked into a pascal program. If using dynamical linking things are different, but in general it works the same as using dll files on Windows. I did use object files compiled from C to use some USB functions withstanding my translation trials vigorously. ;)

I forgot:

These C-Functions are activated in pascal files like this:

<snip>
{ ---------- low level C functions ---------- }

function domotorrequest(device : integer ; motor: integer; speed: integer):integer; cdecl; external;
{$L domotorrequest.o}
function doserialrequest(device: longint; buffer: pAnsiChar):integer; cdecl; external;
{$L doserialrequest.o}
</snip>

After that they can be used like any other function. One of the C files:

<C-code>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <dev/usb/usb.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "usb-serial.h"
int doserialrequest(int dev, char* buffer)
{
        usb_device_descriptor_t devdescr;
        struct usb_string_desc stringdescr;
        int res;
        /*int dev;*/
        int i;
        bzero(&devdescr, sizeof(devdescr));
        res = ioctl(dev, USB_GET_DEVICE_DESC, &devdescr);
        if (res < 0) {
                printf("USB get_device_descriptor failed: %s\n",
                    strerror(errno));
                exit(-1);
        }
        bzero(&stringdescr, sizeof(stringdescr));
        stringdescr.usd_string_index = devdescr.iSerialNumber;
        res = ioctl(dev, USB_GET_STRING_DESC, &stringdescr);
        if (res < 0) {
                printf("USB get_string_descriptor failed: %s\n",
                    strerror(errno));
                exit(-1);
        }

for (i = 0 ; i < stringdescr.usd_desc.bLength; i++ ) {

                //printf("%c", (char)UGETW(stringdescr.usd_desc.bString[i]));
                buffer[i] = (char)UGETW(stringdescr.usd_desc.bString[i]);
        }
        return i;

}
</C-code>

Marc Santhoff

Reply by email

Donald Ziesig
to Donald Ziesig: There is a package written in C called wiringPi which is available on github. You will…
Donald Ziesig wrote 61 lines
On 09/18/2015 07:50 PM, Bo Berglund wrote: > On Sat, 19 Sep 2015 01:21:25 +0300, Maxim Ganetsky > wrote: > >> 19.09.2015 1:10, Donald Ziesig ?????: >>> Hi All! >>> >>> It looks like this is Raspberry PI day :-) . >>> >>> I have Lazarus working on a RPi 2 B with no problems til now. >>> >>> (Started with monitor, keyboard and mouse till I got ssh and vnc >>> setup, >>> then switched to Remmina on my laptop via tcp/ip). >>> >>> I need to access the GPIO pins from my Lazarus program. I have found >>> the C library "wiringPi" and many references to the FPC "hwiringPi" >>> package that wraps it, but I'll be darned if I can find "hwiringPi" >>> itself. >> Strange, that you couldn't find it. This site: >> >> https://github.com/AkselMeola/Pascal-projects-on-Raspberry/tree/master/Morse-code-translator >> >> \ >> is the first for the "hwiringPi" Google query. > Strangely I also need this for my RPi2 project! > The software needs to pull two relays as part ofthe automation. So > GPIO access is needed. > Now that it popped up may I inject a question here: > > The hiwiringpi.pas file is an interface to something else written in C > if I understood the text correctly. > How does that work? It seems like I have to compile something in C on > the Pi as well and it produces an *.o file. Does that act like a dll > in Windows or like a lib file that gets linked into the final > executable? > > I am not really (yet) familiar wth programming in Linux.... > > There is a package written in C called wiringPi which is available on github. You will need to clone it and follow the instructions to build it. The hwiringPi package links to the wiringPi.o file in the wiringPi directory. As of right now, I am getting a linking error which seems to be rather common (there are many references to it online) because I am using the latest RPi version 2 B. Unfortunately my ISP has dropped my connection due to a thunderstorm so I am working on my cell phone (very slow). I think I'll wait until tomorrow to look any further. Don Z -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

I got it working8-) . It seems that the appropriate wrapper is *h2wiringPi* (as opposed to *hwiringPi*). cloned that from github, set the paths correctly, edited my uses clause and the program compiled, linked and ran successfully.

Thanks all for pointing me in the right direction.

Don Z.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150919/7d1457b1/attachment.html>

Reply by email