Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-25 Thread Koenraad Lelong

Op 25-01-16 om 09:40 schreef Koenraad Lelong:

First : I'm using pascalio, on a Pi2 model B.

Just modified bcm2708.pas :
   GPIO_BASE = (BCM2708_PERI_BASE + $003F); // GPIO controller
and
   mem_fd := FpOpen('/dev/gpiomem', O_RDWR OR O_SYNC);

Now I can run my app as user 'pi'.

Thanks.


Forget this. I don't know what I did, but this seems not to work 
anymore. Looking at the sources of pascalio, it should not have worked 
anyway.


Koenraad.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-25 Thread Marc Santhoff
On Mo, 2016-01-25 at 08:33 +0100, Bo Berglund wrote:
> On Mon, 25 Jan 2016 00:18:50 +0100, Marc Santhoff 
> wrote:
> 
> >> For me it is like this:
> >> pi@rpi2-jessie2:~/dev $ cat /etc/group | grep gpio
> >> gpio:x:997:pi
> >
> >Thje last one wrong, should have been
> >
> >$ ls -lL /sys/class/gpio/gpiochip0
> 
> New test:
> 
> pi@rpi2-jessie2:~/dev $ ls -lL /sys/class/gpio/gpiochip0
> total 0
> -rwxrwx--- 1 root gpio 4096 Jan 17 16:47 base
> drwxr-xr-x 3 root root0 Jan 17 16:47 device
> -rwxrwx--- 1 root gpio 4096 Jan 17 16:47 label
> -rwxrwx--- 1 root gpio 4096 Jan 17 16:47 ngpio
> drwxrwx--- 2 root gpio0 Jan 17 16:47 subsystem
> -rwxrwx--- 1 root gpio 4096 Jan 17 16:47 uevent
> 
> >and
> >
> >$ ls -lL ../../devices/platform/soc/3f20.gpio/gpio/
> 
> This is a relative path and you did not specify where one should be
> located in order to execute it. Cannot perform this command.
> Please supply an absolute path instead.

I know. The user can see from where links are not resolved by reading
the failing command. My point was to help diagnosing why a program
running as user pi did not work. I explained with the changed command,
for checking permissions on the targets of the links, not the links
themselves.

But since you found the cause by your patch differentiating between RPi1
and RPi2 it's obsolete now.

-- 
Marc Santhoff 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-25 Thread Koenraad Lelong

Op 25-01-16 om 00:18 schreef Marc Santhoff:

On Mo, 2016-01-25 at 00:11 +0100, Bo Berglund wrote:

On Sun, 24 Jan 2016 21:42:06 +0100, Marc Santhoff 
wrote:


My results :

root@raspberrypi:/home/pi# grep gpio /etc/group
gpio:x:997:pi
root@raspberrypi:/home/pi# ls -lL /sys/class/gpio/gpiochip0
totaal 0
-rwxrwx--- 1 root gpio 4096 jan 24 22:10 base
drwxr-xr-x 3 root root0 jan 24 22:10 device
-rwxrwx--- 1 root gpio 4096 jan 24 22:10 label
-rwxrwx--- 1 root gpio 4096 jan 24 22:10 ngpio
drwxrwx--- 2 root gpio0 jan 24 22:10 subsystem
-rwxrwx--- 1 root gpio 4096 jan 24 22:10 uevent
root@raspberrypi:/home/pi# cd /sys/class/gpio/

Application running as user pi :
root@raspberrypi:/sys/class/gpio# ls -lL 
../../devices/platform/soc/3f20.gpio/gpio/

totaal 0
drwxrwx--- 2 root gpio 0 jan 25 08:54 gpio17
drwxrwx--- 2 root gpio 0 jan 25 08:54 gpio18
drwxrwx--- 2 root gpio 0 jan 24 22:10 gpiochip0

Application running as user root :
root@raspberrypi:/sys/class/gpio# ls -lL 
../../devices/platform/soc/3f20.gpio/gpio/

totaal 0
drwxrwx--- 2 root gpio 0 jan 25 08:56 gpio17
drwxrwx--- 2 root gpio 0 jan 25 08:56 gpio18
drwxrwx--- 2 root gpio 0 jan 24 22:10 gpiochip0

I'm going to try that patch of Bo.

I'll report back.

Koenraad.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-25 Thread Koenraad Lelong

Op 25-01-16 om 09:00 schreef Koenraad Lelong:

Op 25-01-16 om 00:18 schreef Marc Santhoff:
I'm going to try that patch of Bo.

I'll report back.


First : I'm using pascalio, on a Pi2 model B.

Just modified bcm2708.pas :
  GPIO_BASE = (BCM2708_PERI_BASE + $003F); // GPIO controller
and
  mem_fd := FpOpen('/dev/gpiomem', O_RDWR OR O_SYNC);

Now I can run my app as user 'pi'.

Thanks.

According to Bo's post 
(http://lists.lazarus.freepascal.org/pipermail/lazarus/2015-October/094438.html) 
GPIO_BASE depends on where the app runs.
I'm going to look for a way to detect which device the application runs 
on so I can automatically switch the GPIO_BASE.

Suggestions ?

Koenraad.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-25 Thread Koenraad Lelong

Op 25-01-16 om 09:40 schreef Koenraad Lelong:


According to Bo's post
(http://lists.lazarus.freepascal.org/pipermail/lazarus/2015-October/094438.html)
GPIO_BASE depends on where the app runs.
I'm going to look for a way to detect which device the application runs
on so I can automatically switch the GPIO_BASE.


FWIW, rpi_hal is already testing for which pi it runs on, and sets it's 
GPIO_BASE based on that.


I'm going to try to mimic that in pascalio.

Koenraad.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Bo Berglund
On Fri, 22 Jan 2016 20:55:59 -0500, Donald Ziesig 
wrote:

>The application itself must run as root to do digital I/O.  If you don't 
>want to debug using the IDE, you don't have to make the IDE run as root, 
>though, just the app.

I do not think this is necessary!

I am NOT running my RPi2B as any other user than pi and it works just
fine to access the GPIO pins. Both FPC and Lazarus run just fine as pi
user.

The trick is to make sure that pi belongs to the proper groups dealing
with the hardware. You can check this using the command:
cat /etc/group | grep pi

It will list the groups pi belongs to and you will find out if there
are missing groups here. This is what my Pi says:

pi@rpi2-jessie2:~/dev $ cat /etc/group | grep pi
adm:x:4:pi
dialout:x:20:pi
cdrom:x:24:pi
sudo:x:27:pi
audio:x:29:pi
video:x:44:pi
plugdev:x:46:pi
games:x:60:pi
users:x:100:pi
input:x:101:pi
netdev:x:108:pi
spi:x:999:pi
i2c:x:998:pi
gpio:x:997:pi  <== This for GPIO

I never use the NOOBS disk, I always create the start image from the
offiocial Raspbian Jessie image, currently I am on the Nov 2015
release. And the groups above were set from the start on that distro.

-- 
Bo Berglund
Developer in Sweden


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Donald Ziesig

On 01/24/2016 05:47 AM, Bo Berglund wrote:

On Fri, 22 Jan 2016 20:55:59 -0500, Donald Ziesig 
wrote:


The application itself must run as root to do digital I/O.  If you don't
want to debug using the IDE, you don't have to make the IDE run as root,
though, just the app.

I do not think this is necessary!

I am NOT running my RPi2B as any other user than pi and it works just
fine to access the GPIO pins. Both FPC and Lazarus run just fine as pi
user.

The trick is to make sure that pi belongs to the proper groups dealing
with the hardware. You can check this using the command:
cat /etc/group | grep pi

It will list the groups pi belongs to and you will find out if there
are missing groups here. This is what my Pi says:

pi@rpi2-jessie2:~/dev $ cat /etc/group | grep pi
adm:x:4:pi
dialout:x:20:pi
cdrom:x:24:pi
sudo:x:27:pi
audio:x:29:pi
video:x:44:pi
plugdev:x:46:pi
games:x:60:pi
users:x:100:pi
input:x:101:pi
netdev:x:108:pi
spi:x:999:pi
i2c:x:998:pi
gpio:x:997:pi  <== This for GPIO

Hi Bo,

I get exactly this on my pi except there is a line:

pi:x:1000:

immediately following the netdev line..


I never use the NOOBS disk, I always create the start image from the
offiocial Raspbian Jessie image, currently I am on the Nov 2015
release. And the groups above were set from the start on that distro.


I updated the copy of NOOBS to use jessie as soon as jessie was available.
I updated FPC and Lazarus from Anthony's download (as he corrected it 
for the problem with installing custom components) as soon as it was 
available.


When I run my program unprivileged from the command line I get:

wiringPiSetup:  Must be root.  (did you forget sudo?).

Using the same executable but prefacing the command with sudo, it runs 
and does digital I/O.


When I try to run my program using unprivileged Lazarus it compiles but 
the Debugger crashes.


When I run my program using root-mode Lazarus it compiles, runs and does 
digital I/O.


The comments in h2WiringPi state that the programs that use it must run 
as root, which is how I got to this position in the first place.


Don




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Bo Berglund
On Sun, 24 Jan 2016 22:02:49 -0500, Donald Ziesig 
wrote:

>
>I get exactly this on my pi except there is a line:
>
>pi:x:1000:
>
>immediately following the netdev line..

I edited out that because the grep found pi in the wrong place...

>wiringPiSetup:  Must be root.  (did you forget sudo?).
>
>Using the same executable but prefacing the command with sudo, it runs 
>and does digital I/O.
>
>When I try to run my program using unprivileged Lazarus it compiles but 
>the Debugger crashes.
>
>When I run my program using root-mode Lazarus it compiles, runs and does 
>digital I/O.
>
>The comments in h2WiringPi state that the programs that use it must run 
>as root, which is how I got to this position in the first place.

I solved my root/pi problem back in Oct 2015.
You can read about it here:
http://lists.lazarus.freepascal.org/pipermail/lazarus/2015-October/094438.html

Specifically see how the change from using /dev/mem to /dev/gpiomem
made it possible to run as user pi.

I personally totally detest having to be root in a development system
and having my programs require root to run.
I don't have to anymore.


-- 
Bo Berglund
Developer in Sweden


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Bo Berglund
On Mon, 25 Jan 2016 00:18:50 +0100, Marc Santhoff 
wrote:

>> For me it is like this:
>> pi@rpi2-jessie2:~/dev $ cat /etc/group | grep gpio
>> gpio:x:997:pi
>
>Thje last one wrong, should have been
>
>$ ls -lL /sys/class/gpio/gpiochip0

New test:

pi@rpi2-jessie2:~/dev $ ls -lL /sys/class/gpio/gpiochip0
total 0
-rwxrwx--- 1 root gpio 4096 Jan 17 16:47 base
drwxr-xr-x 3 root root0 Jan 17 16:47 device
-rwxrwx--- 1 root gpio 4096 Jan 17 16:47 label
-rwxrwx--- 1 root gpio 4096 Jan 17 16:47 ngpio
drwxrwx--- 2 root gpio0 Jan 17 16:47 subsystem
-rwxrwx--- 1 root gpio 4096 Jan 17 16:47 uevent

>and
>
>$ ls -lL ../../devices/platform/soc/3f20.gpio/gpio/

This is a relative path and you did not specify where one should be
located in order to execute it. Cannot perform this command.
Please supply an absolute path instead.


-- 
Bo Berglund
Developer in Sweden


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Koenraad Lelong

Op 24-01-16 om 11:47 schreef Bo Berglund:

On Fri, 22 Jan 2016 20:55:59 -0500, Donald Ziesig 
wrote:


The application itself must run as root to do digital I/O.  If you don't
want to debug using the IDE, you don't have to make the IDE run as root,
though, just the app.


I do not think this is necessary!


Strange,

I tried this with my test-application and it does not work as user 'pi'.
I investigated a little bit further.
No application running :
root@raspberrypi:/home/pi/Documents/lazarus/pascalio/koen-test# ls -l 
/sys/class/gpio

totaal 0
-rwxrwx--- 1 root gpio 4096 jan 22 22:03 export
lrwxrwxrwx 1 root gpio0 jan 22 22:03 gpiochip0 -> 
../../devices/platform/soc/3f20.gpio/gpio/gpiochip0

-rwxrwx--- 1 root gpio 4096 jan 22 22:03 unexport

When I run the application as 'pi', I get this :

root@raspberrypi:/home/pi/Documents/lazarus/pascalio/koen-test# ls -l 
/sys/class/gpio

totaal 0
-rwxrwx--- 1 root gpio 4096 jan 22 22:03 export
lrwxrwxrwx 1 root gpio0 jan 24 19:43 gpio17 -> 
../../devices/platform/soc/3f20.gpio/gpio/gpio17
lrwxrwxrwx 1 root gpio0 jan 24 19:43 gpio18 -> 
../../devices/platform/soc/3f20.gpio/gpio/gpio18
lrwxrwxrwx 1 root gpio0 jan 22 22:03 gpiochip0 -> 
../../devices/platform/soc/3f20.gpio/gpio/gpiochip0

-rwxrwx--- 1 root gpio 4096 jan 22 22:03 unexport
root@raspberrypi:/home/pi/Documents/lazarus/pascalio/koen-test#

But the IO does not work. When I do
echo 1 > /sys/class/gpio/gpio17/value
from the command-line, the IO does not work, even when I do this as root.

When I run the application as root, everything works as expected.

B.T.W. what 'library' are you using for the GPIO's ?

Koenraad


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O - PiGpio.zip (1/1)

2016-01-24 Thread Bo Berglund

begin 644 PiGpio.zip
M4$L#!!0``@`(`..:*DBT1R3E"@L``%\E```*4'<+G!A<\U:;4_;
MRA+^W$K]#U,)Z22G*;&=0(&<'IU`$AH52)2$(MT/C9QX#;YU;,MVH+3BO]]G
M=NVU"8'"%>7>B`9[9W;>=W9FZ#+P4AIZAY$7MMZ\_OGF->T?'%L[C2TZ'/8'
M-!+G7I+]2)O4L1U\CVDY#F=D#+1%`:TL(.O@>;2D,+T0,<7Y+CL6
M=O+F-:A.+KR$YJ$C"+]3D:3"H3#PKVD_#FUG'BYH-E](OB!3(\=S71&+(`6)
M!2\EX'1-@<`V#0/9<\A-CI2-O$7DBP76[=0+`\G5,LP&'=JS,*;QC]#WP\1[
M\_H&>FXL6)1P]F\WFM_\W/CT[H;QO2`5L6O/!;_4ZQ!:D,O;KKS@G,*(Z4*)
M((U#/Z"R?6C'$6W@](Z8+GR$ZBF8AAB&&?K$U)L^TX@$*PK?>F@1^:
MP08A[8OXW%\&3HG?E9B1[5QZW9=:H$A\4NQ'<0,ID08B]A-U\C

Re: [Lazarus] Raspberry Pi Debug Digital I/O - PiGpio.zip (0/1)

2016-01-24 Thread Bo Berglund
On Sun, 24 Jan 2016 20:59:40 +0100, Koenraad Lelong
 wrote:

>Op 24-01-16 om 11:47 schreef Bo Berglund:
>> On Fri, 22 Jan 2016 20:55:59 -0500, Donald Ziesig 
>> wrote:
>>
>>> The application itself must run as root to do digital I/O.  If you don't
>>> want to debug using the IDE, you don't have to make the IDE run as root,
>>> though, just the app.
>>
>> I do not think this is necessary!
>>
>Strange,
>
>I tried this with my test-application and it does not work as user 'pi'.

On your Pi, what groups are user pi member of?
...

>B.T.W. what 'library' are you using for the GPIO's ?

I have used PiGpio.pas, I will try to attach it - don't really know
how one does thios in a newsreader...


-- 
Bo Berglund
Developer in Sweden


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Marc Santhoff
On So, 2016-01-24 at 20:59 +0100, Koenraad Lelong wrote:

> When I run the application as 'pi', I get this :
> 
> root@raspberrypi:/home/pi/Documents/lazarus/pascalio/koen-test# ls -l 
> /sys/class/gpio
> totaal 0
> -rwxrwx--- 1 root gpio 4096 jan 22 22:03 export
> lrwxrwxrwx 1 root gpio0 jan 24 19:43 gpio17 -> 
> ../../devices/platform/soc/3f20.gpio/gpio/gpio17
> lrwxrwxrwx 1 root gpio0 jan 24 19:43 gpio18 -> 
> ../../devices/platform/soc/3f20.gpio/gpio/gpio18
> lrwxrwxrwx 1 root gpio0 jan 22 22:03 gpiochip0 -> 
> ../../devices/platform/soc/3f20.gpio/gpio/gpiochip0
> -rwxrwx--- 1 root gpio 4096 jan 22 22:03 unexport
> root@raspberrypi:/home/pi/Documents/lazarus/pascalio/koen-test#
> 
> But the IO does not work. When I do
> echo 1 > /sys/class/gpio/gpio17/value
> from the command-line, the IO does not work, even when I do this as root.
> 
> When I run the application as root, everything works as expected.

What do

$ cat /etc/group | grep gpio

and

$ ls -lL /sys/class/gpio

show?

-- 
Marc Santhoff 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Bo Berglund
On Sun, 24 Jan 2016 21:42:06 +0100, Marc Santhoff 
wrote:

>What do
>
>$ cat /etc/group | grep gpio
>
>and
>
>$ ls -lL /sys/class/gpio
>
>show?

For me it is like this:
pi@rpi2-jessie2:~/dev $ cat /etc/group | grep gpio
gpio:x:997:pi
pi@rpi2-jessie2:~/dev $ ls -lL /sys/class/gpio
total 0
-rwxrwx--- 1 root gpio 4096 Jan 17 16:47 export
drwxrwx--- 2 root gpio0 Jan 17 16:47 gpiochip0
-rwxrwx--- 1 root gpio 4096 Jan 17 16:47 unexport


-- 
Bo Berglund
Developer in Sweden


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Raspberry Pi Debug Digital I/O

2016-01-24 Thread Marc Santhoff
On Mo, 2016-01-25 at 00:11 +0100, Bo Berglund wrote:
> On Sun, 24 Jan 2016 21:42:06 +0100, Marc Santhoff 
> wrote:
> 
> >What do
> >
> >$ cat /etc/group | grep gpio
> >
> >and
> >
> >$ ls -lL /sys/class/gpio
> >
> >show?
> 
> For me it is like this:
> pi@rpi2-jessie2:~/dev $ cat /etc/group | grep gpio
> gpio:x:997:pi

Thje last one wrong, should have been

$ ls -lL /sys/class/gpio/gpiochip0

and

$ ls -lL ../../devices/platform/soc/3f20.gpio/gpio/

to see the the targets of the links (correct permissions there, too?)
and content of the directory, sorry.

> pi@rpi2-jessie2:~/dev $ ls -lL /sys/class/gpio
> total 0
> -rwxrwx--- 1 root gpio 4096 Jan 17 16:47 export
> drwxrwx--- 2 root gpio0 Jan 17 16:47 gpiochip0
> -rwxrwx--- 1 root gpio 4096 Jan 17 16:47 unexport
> 
> 

-- 
Marc Santhoff 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Raspberry Pi Debug Digital I/O

2016-01-22 Thread Donald Ziesig

Hi All!

This applies to the Raspberry Pi 2 B.

After a bit of cut and try, I got Anthony Walter's version of Lazarus to 
run as root (from the Raspbian menu) so I could debug programs which do 
DigitalRead, DigitalWrite, etc. using h2wiringPi.


Note that this could be dangerous if you are permanently connected to 
the web while using Lazarus, but in my case, the only time that my Pi 
will be connected to the web is when I am getting Lazarus set up (and it 
is not yet running as root).  Thereafter I will be connected directly 
from Pi to Laptop on a private subnet with no router.  Once the app is 
developed the Pi will not be networked at all.


Incidentally, I got the Pi setup so that if it fails DHCP (is not 
connected to a router) it reverts to the private subnet.  If anyone 
wants to do this, let me know and I'll publish the "magic incantations". 
;-) It is much more convenient than editing /etc/network/interfaces 
every time you need to change from accessing the web to a local private 
subnet.


The application itself must run as root to do digital I/O.  If you don't 
want to debug using the IDE, you don't have to make the IDE run as root, 
though, just the app.


Using Anthony's default paths, I created a file in 
/home//Development/FreePascal/lazarus called lazroot.sh  This 
file contains two lines:


xhost +localhost
sudo /home//Development/FreePascal/lazarus/lazarus.sh

Then chmod +x lazroot.sh

I used the Menu > Preferences > Main Menu Editor to change the command 
which starts Lazarus to:


/home//Development/FreePascal/lazarus/lazroot.sh

Obviously  is the directory where lazarus is located.

At first I tried to change the Menu command to the two lines in the 
lazroot.sh file, but the internals of the menu system did not support 
multi-command arguments.


For some reason, Lazarus re-built itself (as if I were installing 
components) the very first time I ran it as root.  After that it starts 
normally.


Hope this helps someone in return for all the help I have been given here.

Don Ziesig



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus