Raspberry Pi GPIO
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Raspberry Pi GPIO
I wand to be able to send inputs and out puts via the Raspberry Pi's GPIO interface pins.
Does anyone know the LiveCode script/code that I need to write?
Does anyone know the LiveCode script/code that I need to write?
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Raspberry Pi GPIO
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:12 am, edited 1 time in total.
shiftLock happens
-
- Posts: 16
- Joined: Mon Nov 25, 2013 8:35 pm
Re: Raspberry Pi GPIO
I am interested in this as well. I have been doing quite a bit of work lately with my RPi.
Skip Kimpel - Magicgate Software
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Raspberry Pi GPIO
..........
Last edited by [-hh] on Wed Aug 13, 2014 11:12 am, edited 1 time in total.
shiftLock happens
Re: Raspberry Pi GPIO
check this!
ttp://hedgehao.blogspot.tw/2014/07/livecode-raspberry-pi-light-up-led.html
(add a 'h' at the front, the forums does not allow me to post a url
I've wrote a prorotype using C external in livecode to control GPIO and successfully light up the LED
ttp://hedgehao.blogspot.tw/2014/07/livecode-raspberry-pi-light-up-led.html
(add a 'h' at the front, the forums does not allow me to post a url
I've wrote a prorotype using C external in livecode to control GPIO and successfully light up the LED
Re: Raspberry Pi GPIO
Very nice! Do you have more info on making a C external and its source code? I am not at all familiar with C externals.hedgehao wrote:I've wrote a prorotype using C external in livecode to control GPIO and successfully light up the LED
Re: Raspberry Pi GPIO, stack with no externals, uses file i/
Here is the stack that I demoed at RunRevLive2014 in San Diego. Uses "file" based GPIO (every bit is a file) and needs no externals. For convenience and speed, I put all the GPIO "file" (dev) calls in shell scripts, but this is not necessary. See documentation in stack. BTW, the hardware is also bare bones, just use 10K pull up resistors and also lights up LED output in parallel. I can also directly drive a 3.3V low current relay, the problem was to source these on the web--I found some Panasonics that work well. Will document all of this when I have some more time.
stack link of course add the h ---> ttps://drive.google.com/file/d/0B6_fSXet59hJMEJ0WjZiMkFTbHc/edit?usp=sharing
pdf of scripts of course add the h ---> ttps://drive.google.com/file/d/0B6_fSXet59hJR0x3ejlVRnJlSjA/edit?usp=sharing
stack link of course add the h ---> ttps://drive.google.com/file/d/0B6_fSXet59hJMEJ0WjZiMkFTbHc/edit?usp=sharing
pdf of scripts of course add the h ---> ttps://drive.google.com/file/d/0B6_fSXet59hJR0x3ejlVRnJlSjA/edit?usp=sharing
Re: Raspberry Pi GPIO tutorial and clarifications
Make sure you copy the full link address in my previous post and add the h before the ttps to form the complete url, downloads from Google drive.
Clarification: The stack uses shell commands that do Unix-based file i/o. For convenience and for my particular application, I put multiple Unix file i/o commands into a single shell script, but you could control each bit by using the appropriate shell command as an individual statement line in LiveCode.
Here are the steps;
Step 1: Creata a GPIO "device" corresponding to a pin, example pin 25
put shell("echo 25 > /sys/class/gpio/export") into dummy
Step 2: Set direction (input or output) ,in this example pin 25 is set to be output
put shell("echo out > /sys/class/gpio/gpio25/direction") into dummy (if the pin were to be set as input, use echo in ...)
Step 3: Read or write as appropriate. For output pin 25, write is appropriate!!
Write a 1
put shell("echo 1 /sys/class/gpio25/value") into dummy
or to read an input, (if pin 25 was previously set as input)
put shell("cat /sys/class/gpio25/value") into pVal
If you are curious about my stack, it was scripted for a practical application of Pi in an electrochemistry laboratory where we set up the Pi and LC to act as a coulometer, i.e., a device that passes electrical current for a known time interval through a solution.
We set up a stack with four timers, each one controlled by a push button connected to a Pi input pin.
When push button is closed, timer is started and a (corresponding) output pin connected to a 3.3 V low current relay is activated. The relay in turn switches on a constant current source (LMxxx current regulator chip!)
Thus, we used four input pins for timers and four output pins connected to relays.
The script is somewhat intricate because we had to run all the timer processes in the background so we can constantly check push buttons for (continued) closure in round-robin fashion. Also, we needed high precision timers and had to figure out ways to keep processing time to the minimum. All in all, we could get 0.1 to 0.2 second precision --read docs for details!
Clarification: The stack uses shell commands that do Unix-based file i/o. For convenience and for my particular application, I put multiple Unix file i/o commands into a single shell script, but you could control each bit by using the appropriate shell command as an individual statement line in LiveCode.
Here are the steps;
Step 1: Creata a GPIO "device" corresponding to a pin, example pin 25
put shell("echo 25 > /sys/class/gpio/export") into dummy
Step 2: Set direction (input or output) ,in this example pin 25 is set to be output
put shell("echo out > /sys/class/gpio/gpio25/direction") into dummy (if the pin were to be set as input, use echo in ...)
Step 3: Read or write as appropriate. For output pin 25, write is appropriate!!
Write a 1
put shell("echo 1 /sys/class/gpio25/value") into dummy
or to read an input, (if pin 25 was previously set as input)
put shell("cat /sys/class/gpio25/value") into pVal
If you are curious about my stack, it was scripted for a practical application of Pi in an electrochemistry laboratory where we set up the Pi and LC to act as a coulometer, i.e., a device that passes electrical current for a known time interval through a solution.
We set up a stack with four timers, each one controlled by a push button connected to a Pi input pin.
When push button is closed, timer is started and a (corresponding) output pin connected to a 3.3 V low current relay is activated. The relay in turn switches on a constant current source (LMxxx current regulator chip!)
Thus, we used four input pins for timers and four output pins connected to relays.
The script is somewhat intricate because we had to run all the timer processes in the background so we can constantly check push buttons for (continued) closure in round-robin fashion. Also, we needed high precision timers and had to figure out ways to keep processing time to the minimum. All in all, we could get 0.1 to 0.2 second precision --read docs for details!
Re: Raspberry Pi GPIO
Is there anything you need to do regarding permissions?
I seem to be able to do step ! successfully, but I get a folder not found error when I attempt step 2. The interesting part is that when I do this from the terminal it all seems to work fine. I am just having difficult doing it thru livecode.
PS I don't have a lot of unix experience.
I seem to be able to do step ! successfully, but I get a folder not found error when I attempt step 2. The interesting part is that when I do this from the terminal it all seems to work fine. I am just having difficult doing it thru livecode.
PS I don't have a lot of unix experience.
Re: Raspberry Pi GPIO
This is indeed strange. Are you logged in as a standard user with standard permissions, not guest or some restricted entity? IF so, those "commands" should work.. I'll check when I next fire up my Pi -- on the road right now... best..
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Raspberry Pi GPIO
You could look into here: GPIO-library
This works perfectly. Easy to read for a LiveCoder. Could also be used via "shell".
This works perfectly. Easy to read for a LiveCoder. Could also be used via "shell".
shiftLock happens
Re: Raspberry Pi GPIO
I have added some routines that will do Raspberry Pi GPIO to my MasterLibrary. There are instructions for getting around the permissions issue in the comments.
Enjoy...
https://www.dropbox.com/s/3wpwn3hfbmpl7 ... ecode?dl=0
Enjoy...
https://www.dropbox.com/s/3wpwn3hfbmpl7 ... ecode?dl=0
Re: Raspberry Pi GPIO
Hi,
how easy is it nowadays to use the GPIO pins in Livecode?
I'm evaluating if it is useful to use the Raspberry 3 with Livecode, so to have a user interface and be able to use the GPIO outputs to drive a few steppermotors via their drivers.
On a previous job we used Labview for it with another interface. Could also use Flowstone but that's a dead development tool unfortunately now.
For Arduino there seems many more support to do this kind of thing and there lots of python examples to do it.
But i like Livecode, so if it is reasonable to do with LC7.0.4 (that's the only version to be able to create executable for the Rpi? right?)
The pins need to send out pulses in different speeds and lengths.
Any suggestions?
how easy is it nowadays to use the GPIO pins in Livecode?
I'm evaluating if it is useful to use the Raspberry 3 with Livecode, so to have a user interface and be able to use the GPIO outputs to drive a few steppermotors via their drivers.
On a previous job we used Labview for it with another interface. Could also use Flowstone but that's a dead development tool unfortunately now.
For Arduino there seems many more support to do this kind of thing and there lots of python examples to do it.
But i like Livecode, so if it is reasonable to do with LC7.0.4 (that's the only version to be able to create executable for the Rpi? right?)
The pins need to send out pulses in different speeds and lengths.
Any suggestions?
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Raspberry Pi GPIO
The above description still works. Michael Doub's Master Library includes convenient functions for it to make it even easier.
https://www.dropbox.com/s/3wpwn3hfbmpl7 ... ecode?dl=0
https://www.dropbox.com/s/3wpwn3hfbmpl7 ... ecode?dl=0
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Raspberry Pi GPIO
Great!,
I will check it out.
I will check it out.