Raspberry Pi GPIO

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Raspberry Pi GPIO

Richard Gaskin
What's needed to work with the GPIO on RPi?

I'd like to work with a motion sensor, and would prefer to work with LC
instead Python if I can.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Monte Goulding-2
It looks like you could do this very easily in script. A good community project to write a library and see what you can do with it!

http://luketopia.net/2013/07/28/raspberry-pi-gpio-via-the-shell/

Cheers

Monte

> On 10 Jun 2016, at 8:38 AM, Richard Gaskin <[hidden email]> wrote:
>
> What's needed to work with the GPIO on RPi?
>
> I'd like to work with a motion sensor, and would prefer to work with LC instead Python if I can.
>
> --
> Richard Gaskin
> Fourth World Systems
> Software Design and Development for the Desktop, Mobile, and the Web
> ____________________________________________________________________
> [hidden email]                http://www.FourthWorld.com
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

[-hh]
Using the GPIO is nothing else than writing zeros or ones to a file.
Nobody needs a library for that?
[Also there was a talk about that at the last LC US-conference.]

The problem is to use the *correct* files or pins numbering
respectively. This is hardware dependent, not a problem of using
LC or Python. And hardware has changes, also on Raspi GPIO ...

So be very careful to follow old "second hand" links which are
for Raspberry A (2012/13). Better use the infos/forum, starting for
example from here (or ask LC-Fraser):

http://www.raspberrypi-spy.co.uk/
http://www.raspberryconnect.com/
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Michael Doub
In reply to this post by Richard Gaskin
Richard,  Take a look at the code in the MasterLibrary.   Look at the
comments in the library it self for how to solve the Accessing the GPIO
(of a raspberry pi) without "sudo" problem.

https://www.dropbox.com/s/3wpwn3hfbmpl7sk/MasterLibrary.livecode?dl=0

Regards,

     Mike



On 6/9/16 6:38 PM, Richard Gaskin wrote:
> What's needed to work with the GPIO on RPi?
>
> I'd like to work with a motion sensor, and would prefer to work with
> LC instead Python if I can.
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Richard Gaskin
In reply to this post by [-hh]
-hh wrote:

 > Using the GPIO is nothing else than writing zeros or ones to a file.
 > Nobody needs a library for that?
 > [Also there was a talk about that at the last LC US-conference.]

I'll see if I can find that one on the DVDs.

What is the LC syntax for something like:

   open file GPIO pin 6 for read

?

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Richard Gaskin
In reply to this post by Michael Doub
Michael Doub wrote:

 > Richard,  Take a look at the code in the MasterLibrary.   Look at the
 > comments in the library it self for how to solve the Accessing the
 > GPIO (of a raspberry pi) without "sudo" problem.
 >
 > https://www.dropbox.com/s/3wpwn3hfbmpl7sk/MasterLibrary.livecode?dl=0

Thanks, Michael.  Downloading now.

I hadn't realized GPIO access was considered a solved problem.  I see so
many requests for this I had though there must be something else needed
beyond what LC currently provides.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Michael Doub
Richard,

You initial gut reaction is STILL correct.   Currently the only solution
available to livecoders is the file method.  The performance of this
solution is terrible and limits the types of real world problems that
can be solved with livecode and raspberry pi.

It would be wonderful if someone could write a library that allowed
direct access to the actual GPIO driver.  I am hoping someone with
LiveCode builder skills will solve this problem.  If python can do it,
so can livecode.

-= Mike


On 6/10/16 11:19 AM, Richard Gaskin wrote:

> Michael Doub wrote:
>
> > Richard,  Take a look at the code in the MasterLibrary. Look at the
> > comments in the library it self for how to solve the Accessing the
> > GPIO (of a raspberry pi) without "sudo" problem.
> >
> > https://www.dropbox.com/s/3wpwn3hfbmpl7sk/MasterLibrary.livecode?dl=0
>
> Thanks, Michael.  Downloading now.
>
> I hadn't realized GPIO access was considered a solved problem.  I see
> so many requests for this I had though there must be something else
> needed beyond what LC currently provides.
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Richard Gaskin
Michael Doub wrote:
 > Richard,
 >
 > You initial gut reaction is STILL correct.   Currently the only
 > solution available to livecoders is the file method.

What is "the file method"?  How do I treat GPIO connections as file
paths?  Somewhere in /proc?

Earlier you wrote:

    Look at the comments in the library it self for how to solve
    the Accessing the GPIO (of a raspberry pi) without "sudo" problem.

The stack script isn't very big, and perhaps I'm just pre-coffee but I
couldn't find anything there about sudo.

Where should I be looking?


 > It would be wonderful if someone could write a library that allowed
 > direct access to the actual GPIO driver.  I am hoping someone with
 > LiveCode builder skills will solve this problem.  If python can do
 > it, so can livecode.

I would imagine so, but in Python it's easy because someone wrote a
component for GPIO.  I haven't looked into this deeply so forgive my
ignorance, but how does GPIO present itself to an application?  A sort
of named pipe, or serial I/O, or....?

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Richard Gaskin
Earlier I wrote:

 > What is "the file method"?  How do I treat GPIO connections as file
 > paths?  Somewhere in /proc?
 >
 > Earlier you wrote:
 >
 >     Look at the comments in the library it self for how to solve
 >     the Accessing the GPIO (of a raspberry pi) without "sudo" problem.
 >
 > The stack script isn't very big, and perhaps I'm just pre-coffee but I
 > couldn't find anything there about sudo.
 >
 > Where should I be looking?

Coffee helped.  I was looking in "the stack itself", and then for a
"Hardware" section, overlooking the "Raspberry Pi" section right there
in front of me once I thought to scroll down to look for it. :)

It seems the "files" method is using a mounted virtual file system,
similar to /proc or /run/shm, which are actually elements in RAM
accessible through file-like paths in keeping with the Unix tradition of
"everything is a file".  This appears to be the common method for
obtaining GPIO data:
<https://sites.google.com/site/semilleroadt/raspberry-pi-tutorials/gpio>

Thanks for maintaining the Master Lib - with what's there I should be
able to poke around and get what I need.

One last question for now:  is there any mechanism accessible to use in
LiveCode that allows our app to subscribe to events in /sys/class/gpio,
or do we need to poll for changes?

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Michael Doub
I think you have to poll.   This would be another feature that might go
on the list to be done with LCB.

-= Mike


On 6/10/16 1:26 PM, Richard Gaskin wrote:

> Earlier I wrote:
>
> > What is "the file method"?  How do I treat GPIO connections as file
> > paths?  Somewhere in /proc?
> >
> > Earlier you wrote:
> >
> >     Look at the comments in the library it self for how to solve
> >     the Accessing the GPIO (of a raspberry pi) without "sudo" problem.
> >
> > The stack script isn't very big, and perhaps I'm just pre-coffee but I
> > couldn't find anything there about sudo.
> >
> > Where should I be looking?
>
> Coffee helped.  I was looking in "the stack itself", and then for a
> "Hardware" section, overlooking the "Raspberry Pi" section right there
> in front of me once I thought to scroll down to look for it. :)
>
> It seems the "files" method is using a mounted virtual file system,
> similar to /proc or /run/shm, which are actually elements in RAM
> accessible through file-like paths in keeping with the Unix tradition
> of "everything is a file".  This appears to be the common method for
> obtaining GPIO data:
> <https://sites.google.com/site/semilleroadt/raspberry-pi-tutorials/gpio>
>
> Thanks for maintaining the Master Lib - with what's there I should be
> able to poke around and get what I need.
>
> One last question for now:  is there any mechanism accessible to use
> in LiveCode that allows our app to subscribe to events in
> /sys/class/gpio, or do we need to poll for changes?
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Michael Doub
In reply to this post by Richard Gaskin
Sorry,  this is beyond me as well

-= Mike



On Jun 10, 2016, 1:15 PM, at 1:15 PM, Richard Gaskin <[hidden email]> wrote:

>Michael Doub wrote:
> > Richard,
> >
> > You initial gut reaction is STILL correct.   Currently the only
> > solution available to livecoders is the file method.
>
>What is "the file method"?  How do I treat GPIO connections as file
>paths?  Somewhere in /proc?
>
>Earlier you wrote:
>
>    Look at the comments in the library it self for how to solve
>    the Accessing the GPIO (of a raspberry pi) without "sudo" problem.
>
>The stack script isn't very big, and perhaps I'm just pre-coffee but I
>couldn't find anything there about sudo.
>
>Where should I be looking?
>
>
> > It would be wonderful if someone could write a library that allowed
> > direct access to the actual GPIO driver.  I am hoping someone with
> > LiveCode builder skills will solve this problem.  If python can do
> > it, so can livecode.
>
>I would imagine so, but in Python it's easy because someone wrote a
>component for GPIO.  I haven't looked into this deeply so forgive my
>ignorance, but how does GPIO present itself to an application?  A sort
>of named pipe, or serial I/O, or....?
>
>--
>  Richard Gaskin
>  Fourth World Systems
>  Software Design and Development for the Desktop, Mobile, and the Web
>  ____________________________________________________________________
>  [hidden email]                http://www.FourthWorld.com
>
>
>_______________________________________________
>use-livecode mailing list
>[hidden email]
>Please visit this url to subscribe, unsubscribe and manage your
>subscription preferences:
>http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

[-hh]
Perhaps the best "library" to Raspi-GPIO, that may also
answer most of your technical questions (in the C-part).

http://elinux.org/RPi_GPIO_Code_Samples

Note the line in the C example that explains how to
make this "Raspi 1"-code working on a Raspi 2.

Especially for you the WebIOPi may be also interesting:
http://webiopi.trouch.com/

Relating to PIR sensors there are well-tested-tutorials
in English in the folks (I dont link to the one I used,
because it's in German only).

===
This is my 'unsharp' opinion
(may hopefully need an update with LC's FFI):

If you use python via shell from LC this doesn't really
matter: LC 7 is *much* slower than LC 6, and LC 6 is
slower than Python, and Python is *much* slower than C
anyway. Sums up to a factor of close to 100 in time
needed. LCB will not bring that down below 10, I presume.

Nevertheless, using LC on Raspi for hardware is *really*
good for rapid TESTING (use LC 6), NOT for rapid WORKING.
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

[-hh]
Forgot to mention, in case you are interested in WebIOPi,
there is a patch:

WebIOPi-0.7.1 Patch for Raspberry B+, Pi2, and Pi3
https://github.com/doublebind/raspi/

I had it running on Raspi2, but not yet on Raspi3.
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Richard Gaskin
-hh wrote:
 > Forgot to mention, in case you are interested in WebIOPi,
 > there is a patch:
 >
 > WebIOPi-0.7.1 Patch for Raspberry B+, Pi2, and Pi3
 > https://github.com/doublebind/raspi/
 >
 > I had it running on Raspi2, but not yet on Raspi3.

Thanks.  Bookmarked for when I get back to that.

Right now I have a very small Pi project that doesn't need GPIO, and I
don't know when I'll get back to the GPIO project given the state of LC
in Pi.

Yesterday my Pi3 arrived and I tried once again to see if any of the
three most recent LC builds would run on it.  And once again, as with my
Pi2, the older of the three crashes on launch, the other two crash as
soon as I click anywhere in the menu bar.

Too bad, since the Pi is very popular in EDU and LC is a perfect fit for
that.

I'm hoping to get some time to work out the compile details so I can at
least compile v8 for Pi, but I don't know when that will be.  And even
when I do, I doubt I have the C chops to track down and fix the menu bar
crasher.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

Richard Gaskin
Earlier I wrote:

> Yesterday my Pi3 arrived and I tried once again to see if any of the
> three most recent LC builds would run on it.  And once again, as with my
> Pi2, the older of the three crashes on launch, the other two crash as
> soon as I click anywhere in the menu bar.
>
> Too bad, since the Pi is very popular in EDU and LC is a perfect fit for
> that.
>
> I'm hoping to get some time to work out the compile details so I can at
> least compile v8 for Pi, but I don't know when that will be.  And even
> when I do, I doubt I have the C chops to track down and fix the menu bar
> crasher.

I should add that the crashers appear limited to GUI routines.

My current Pi3 SD card has Raspbian Jessie Lite with no GUI, a better
fit for the lower-powered Pi and all you need for server and IoT projects.

In that setup the most recent LC Server build for Pi works very well.

So if you were excited about LC on Pi for GUIs, it seems a mixed bag in
which some folks are having a good time and others getting crashers.

But if you're using your Pi for server or IoT projects, run LC Server
without a GUI and it seems to run reliably well.

And FWIW, I once ran my Pi2 under Ubuntu Snappy Core, the new super-slim
Ubuntu edition with their new Snap packaging optimized for microservers
and IoT.  LC Server ran well there.  There isn't yet a build of Ubuntu
Core for Pi3, but it should be just another couple weeks and once it's
out I'll be using that and can report back here on how it goes with LC
Server if anyone's interested.

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

[-hh]
Currently I ran
= Lubuntu 15.10 on Raspi2, runs LC 6.5.1 and 7.0.4 without any problem
= Xubuntu 16.04 on Raspi3, runs LC 6.5.1 and 7.0.4 without any problem

installed from here:
https://ubuntu-pi-flavour-maker.org/download/

There is also Ubuntu Server Minimal 16.04 for Raspi3 ...
Reply | Threaded
Open this post in threaded view
|

Re: Raspberry Pi GPIO

mwieder
In reply to this post by Richard Gaskin
On 06/09/2016 03:38 PM, Richard Gaskin wrote:
> What's needed to work with the GPIO on RPi?
>
> I'd like to work with a motion sensor, and would prefer to work with LC
> instead Python if I can.
>

Not LC, but I came across a very nice Forth for the pi: supports C-code
primitives and has a GPIO example.

http://elinux.org/Forth

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
--
 Mark Wieder
 ahsoftware@gmail.com