element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Simple method of turning on a led with gpio needed
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 6 replies
  • Subscribers 678 subscribers
  • Views 551 views
  • Users 0 members are here
Related

Simple method of turning on a led with gpio needed

cityswift
cityswift over 13 years ago

Hi I have made up a simple interface for my Pi gpio and now want to turn a led on and off. I have tried the Cambridge University tutorial on this topic http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/ but fail at the first apt-get command as my Pi will not allow the command. Can anyone suggest an alternative or explain why this problem is occurring? What I find is that there is little or no explaination of what the commands are doing and why they are needed. image

  • Sign in to reply
  • Cancel
Parents
  • johnbeetem
    johnbeetem over 13 years ago

    The GPIO example at the RasPi Hardware Wiki worked for me: http://elinux.org/RPi_Low-level_peripherals#GPIO_Driving_Example_.28C.29

     

    You do need to run the executable using sudo until I try out some of the suggestions people have made in this thread: http://www.element14.com/community/thread/19995?tstart=0

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • johnbeetem
    johnbeetem over 13 years ago

    The GPIO example at the RasPi Hardware Wiki worked for me: http://elinux.org/RPi_Low-level_peripherals#GPIO_Driving_Example_.28C.29

     

    You do need to run the executable using sudo until I try out some of the suggestions people have made in this thread: http://www.element14.com/community/thread/19995?tstart=0

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • cityswift
    cityswift over 13 years ago in reply to johnbeetem

    Thanks for your replies but I wanted to write a very basic bit of code rather than copying a large comprehensive programme. This is the Cambridge tutorial which I have tried but nothing happens when I input it.

     

    Turn on the Pi

    Open a root terminal from the menu,or by running sudo su in a normal terminal

    Now type in these commands, where "18" is replaced by whichever pin the led is connected to.

     

    cd /sys/class/gpio/

    echo "18" > export

    cd gpio18

    echo "out" > direction

    echo "1" > value

    The led should now be turned on.

     

    To turn the led off

    echo "0"  > value

    cd ..

    echo "18" > unexport

     

    Everthing appears to go OK when I input this but the led does not light.

     

    Can anyone help? Have I missed something obvious? Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • anhtien
    anhtien over 13 years ago in reply to cityswift

    I also tried the RPi Low-level Peripherals approach like John and it worked for me, I used Python coding and it was very simple.

    Your problem could be that you used the wrong pin, you can check my experiment from my blog here

    Cheers

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • johnbeetem
    johnbeetem over 13 years ago in reply to cityswift

    cityswift wrote:

     

    Can anyone help? Have I missed something obvious? Thanks

    You might try copying the C example and compiling and running it, just so you can see if the hardware is working.  I just cut and pasted the code into "gpio.c", compiled it using "gcc -o gpio gpio.c", and ran it using "sudo ./gpio".  Worth spending three minutes.

     

    If "gpio" doesn't work, here are some obvious hardware errors that are easy to miss:  (1) Check that the LED lights using just RasPi +3.3V, a current-limiting resistor (330-470 Ohm is a good starting value), and RasPi ground.  Maybe your LED is dead.  (2) Check that the LED's anode is high and cathode is low.

     

    Caution: one of the easiest ways to destroy a RasPi is to short the +5V and +3.3V pins on the GPIO connector.  I recommend stripping some insulation off a wire and sliding it over the +5V pin before messing around with other GPIO connections.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
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