Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
There's a definition issue on read_file but that is unused so I have commented it out to test it.

Yes, it's missing my $fn=shift; as the first line of read_file(). As I wrote: untested.

As I expected, but cannot explain, your code works as expected provided the GPIO is already exported. Your export code doesn't work and fails with Could not open /sys/class/gpio/gpio20/direction: Permission denied at afoken.pl line 12.

I have burried my spare Raspi unter tons of stuff, so I can't reproduce that at the moment. But I have two ideas why that happens:

  • You are using a non-privileged account (i.e. not root), but /sys/class/gpio/*/* is writable only by root. Either run as root (bad) or change the permissions on sysfs. It seems the way to do so is udev (see https://unix.stackexchange.com/questions/68897/ and https://unix.stackexchange.com/questions/20125/). For tests, you also could work as root. But sooner or later, you will need to address the permission issue. On the other hand, if the Raspi just gets its time via NTP and does nothing else on the network, running as root is not that big issue.
  • There may be a delay between export and actually creating the files in the sysfs filesystem, so your code may be too fast. Sleep for a few milliseconds after exporting and before accessing the new export.

I just had a look at the source code of the daemon mentioned in Re^12: Controlling USB on Raspberry Pi. It runs as root, so permission checks are effectively off. The source code does write a lot of debug output, so there is definitively a delay between exporting and setting direction.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^14: Controlling USB on Raspberry Pi by afoken
in thread Controlling USB on Raspberry Pi by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-04-18 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found