element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Forum Accessing hardware on the Edison?
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 20 replies
  • Subscribers 5 subscribers
  • Views 1971 views
  • Users 0 members are here
Related

Accessing hardware on the Edison?

Workshopshed
Workshopshed over 8 years ago

I'm wondering about accessing the GPIO of the Edison in high-level languages such as Python or Node.

 

So far I've found MRAA but wondered if there are other options?

 

https://github.com/intel-iot-devkit/mraa

  • Sign in to reply
  • Cancel

Top Replies

  • jasonwier92
    jasonwier92 over 8 years ago +3
    MRAA should be the way to go. Looks like they have Python interface. Check out this link: Getting Started With Intel Edison - Python Programming - All I cannot wait to play with Python and Node on the…
  • Former Member
    Former Member over 8 years ago +2
    If you can access the gpio through the standard linux filesystem method it should be possible to write out the bash commands in Python using os.popen e.g. import os p = os.popen("echo 1 > /sys/class/gpio…
  • mcb1
    mcb1 over 8 years ago in reply to konstantinoskonstas +2
    I'm learning as I go. I've always said I'm more a hardware guy that pokes and prods at software. I was hoping to get a head start on you guys/gals ...
Parents
  • Former Member
    Former Member over 8 years ago

    If you can access the gpio through the standard linux filesystem method it should be possible to write out the bash commands in Python using os.popen

     

    e.g.

     

    import os
    p = os.popen("echo 1 > /sys/class/gpio/export")
    p.close()

     

    would export pin 1 of the gpio for use in the file system.

     

    so once the pin is exported to the filesystem you would do

     

    p = os.popen("echo out > /sys/class/gpio/gpio1/direction")

     

    to set gpio pin 1 to be an output pin and then

     

    p = os.popen("echo 1 > /sys/class/gpio/gpio1/value")

     

    to set gpio pin 1 high

     

    and

     

    p = os.popen("echo 0 > /sys/class/gpio/gpio1/value")

     

    to set that pin low.

     

    This method should work for all devices that can access the gpio through the linux filesystem.

     

    --------------------------

     

    I should mention that you probably need to run the Python script with sudo or as root  for this to work. If this is a problem for your project you can get around it by adding the user account to the gpio group

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • Workshopshed
    Workshopshed over 8 years ago in reply to Former Member

    Cheers Lucie, yes using the filesystem is always my fallback approach when I can't get something working.

    According to the hardware guide you can even control PWM that way.

    http://www.intel.com/content/dam/support/us/en/documents/edison/sb/edison-arduino-hardware-guide.pdf

     

    I really hate the whole needing to run as root thing for GPIO access. It seems a common problem across different platforms, would be nice to see if it's solved on the Edison.

     

    For my BeagleBone project I've resolved the problem with a C Daemon that listens on NamedPipes. That can run as root but the client apps can run as the user.

    https://github.com/Workshopshed/musicController/blob/master/servoDaemon/servoDaemon.c

     

    MRAA does seem like the natural choice given that it was provided by one of the competition sponsors. Libsoc could also be a possibility https://github.com/jackmitch/libsoc

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 8 years ago in reply to Workshopshed

    try using

     

    useradd -G {group-name} username

     

    in a terminal to add the user account to the gpio group, doing this will allow the user account to work with gpio without needing sudo etc.. it took me a while to work it out but its obvious when the group is there ready and waiting to add users to it. There's usually groups for i2c spi etc..

     

    just type "groups" into a terminal to see which groups are available

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Workshopshed
    Workshopshed over 8 years ago in reply to Former Member

    mcb1 can you test this on your Edison?

     

    You'd need to be root for the following:

     

    echo 1 > /sys/class/gpio/export

    echo out > /sys/class/gpio/gpio1/direction

     

    But can you run the following as a regular user?

     

    echo 1 > /sys/class/gpio/gpio1/value

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 8 years ago in reply to Workshopshed

    if you add the user account to the gpio group you can do export, direction, value and anything else available as a regular user. I add the www-data user to the group to allow webserver software to interact with gpio for control over network.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Former Member
    Former Member over 8 years ago in reply to Workshopshed

    if you add the user account to the gpio group you can do export, direction, value and anything else available as a regular user. I add the www-data user to the group to allow webserver software to interact with gpio for control over network.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube