Raspberry Pi and GPIO

Michael Doub mikedoub at gmail.com
Thu Oct 9 17:20:32 EDT 2014


Thanks Andrew.

I did the following:

1)   edit /etc/rc.local   (sudo nano /etc/rc.local)
2)   added the following 2 line near the end, but in front of the last line (exit 0)
            chgrp -R dialout /sys/class/gpio
            chmod -R g+rw /sys/class/gpio
3)   saved file
4)   rebooted

This allowed me to do the shell commands with out needing to add the “sudo” and to do livecode I/O.

Playing with livecode I/O I have learned the following:

setting the defaultfolder to “/sys/class/gpio/gpio12”
put the files…. gets me what I expect.   I see the direction and value files as well as some others that I have yet to explore.

putting the defaultfolder returns  “/sys/device/virtual/gpio/gpio12”

Hummm, can livecode do I/O to virtual devices?   Kind of…..

These do NOT work:

put URL “/sys/class/gpio/gpio12/value” or
put 0 into URL “/sys/class/gpio/gpio12/value”

open file “/sys/class/gpio/gpio12/value” for write
write 0 to file “/sys/class/gpio/gpio12/value”
wait 1 second
write 1 to file “/sys/class/gpio/gpio12/value”
close file “/sys/class/gpio/gpio12/value”        
— I suspect that the virtual driver keys off of the close to actually output the signal.


This works quite well:

open file “/sys/class/gpio/gpio12/value” for write
write 0 to file “/sys/class/gpio/gpio12/value”
close file “/sys/class/gpio/gpio12/value”        

In fact it can be pretty fast, I could not see any blinking at all with _delay set to 0, 1 was flicker, 2 was the start of a true blink, 3,4,5 were solid blinks.

on mouseup
repeat with _delay = 0 to 5
 repeat 10 times
   _output 0
   wait _delay ticks
   _output 1
   wait _delay ticks
 end repeat
end repeat
end mouse up

on _output val
  open file “/sys/class/gpio/gpio12/value” for write
  write val to file “/sys/class/gpio/gpio12/value”
   close file “/sys/class/gpio/gpio12/value” 
end _output

Using the shell cmds were way too slow.   Not even close to the performance of open, write, close.

Hope this helps someone else playing with Raspberry Pi

Regards,
   Mike


On Oct 9, 2014, at 2:50 PM, Andrew Kluthe <andrew at ctech.me> wrote:

> No specific information I can help with but this seems like it might hold
> some answers for you if you dig enough.
> 
> http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=73924
> 
> On Thu, Oct 9, 2014 at 1:43 PM, Michael Doub <mikedoub at gmail.com> wrote:
> 
>> I think that I have now confirmed that it is a permission issue.   I added
>> a “sudo” in front of the “echo” command.  Now everything seems to be
>> working.
>> 
>> I still have the question about how to give livecode the correct
>> permissions to access this files as it would seem more logical to use to do
>> direct IO to the files rather that to be forced to use a shell command.
>> 
>> I am running as the default pi user.   Should this user have different
>> permissions?  If so how do you grant them?
>> 
>> Regards,
>>  Mike
>> 
>> 
>> On Oct 9, 2014, at 2:21 PM, Michael Doub <mikedoub at gmail.com> wrote:
>> 
>>> I am looking for some help from some of you with unix/raspberry pi
>> experience.
>>> 
>>> I have think that I have installed 7.0 rc 1 on my raspberry pi B+
>> properly.   I am trying to figure out how to play with the GPIO’s.
>>> 
>>> I am am able to execute the following to set up the IO
>>> 
>>>       put shell("echo 12 > /sys/class/gpio/export") into dummy
>>> 
>>> dummy is empty,   However the next statement:
>>> 
>>>       put shell("echo out > /sys/class/gpio/gpio12/direction") into
>> dummy
>>> 
>>> 
>>> dummy contains the error message:
>>> 
>>>      bin/sh: cannot create /sys/class/gpio/gpio12/direction:  Directory
>> nonexistent
>>> 
>>> When I use the terminal, I can see that the directory does exist and I
>> am able to modify the contents to both set the IO direction and sucessfully
>> turn the LED on and off.
>>> 
>>> Could it be that I do not have the permission to create directories and
>> modify files from livecode?   How can I check this from livecode and fix
>> it?  …. assuming this is in fact a permission issue.
>>> 
>>> Thanks,
>>>  Mike
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> 
> 
> 
> -- 
> Regards,
> 
> Andrew Kluthe
> andrew at ctech.me
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list