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 Raspberry Pi and /dev/mem access
  • 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
  • State Not Answered
  • Replies 30 replies
  • Subscribers 680 subscribers
  • Views 4851 views
  • Users 0 members are here
  • raspberry
  • pi
  • raspberry_pi
Related

Raspberry Pi and /dev/mem access

Former Member
Former Member over 11 years ago

Question(s) regarding Raspberry Pi and GPIO.

 

Been working with RPi.GPIO for several weeks trying to get the following script to run: (from Third Eye Visions, using the GPIO Python library that they suggest to use)

 

import RPi.GPIO as GPIO

GPIO.setmode (GPIO,BOARD)

GPIO.setup (7, GPIO.OUT)

GPIO.output (7, True)

 

When running from the Lynux command line, an error is posted “no access to /dev/mem.  Try running as root”

 

I go to command line and run sudo/home/pi/file name and another error is returned “command not found”.

 

Doing a brief search on line, I don’t seem to be the only person having this problem.  I simply don’t understand the solutions that are presented and it is not clear that the solutions solve the problem.

 

When using RPi.GPIO 0.5.4 revision of the Python Package Index, isn’t this problem resolved?

 

I am using the Debian Wheezy Rasbiabn 2012.12.img 192, Debian GNU/Linux 7 raspberry pi tty1

 

I have Python 2.7, 3.2 and 3 on the SD and Python IDE.

 

I want to program the raspberry pi using GPIO functions with Python not C or any other script.

 

Why won’t the current upgrade of Raspberry Pi from Third Eye Visions work with the above script?  This is not the only GPIO program (from other sources) that I have tried and receive the same result.  I can control the pins in the command line of Linux from the keyboard using set mode, etc and read the status of the pins using readall.

 

I have used Pygame with this distribution of Debian and it works perfectly.

 

Can anyone supply a simple fix for this problem?  Can it be solved with a new SD loaded with a raspberry pi compatible program set-up with Python?  If so. where can I find one.? Or can I simply add one or two lines to the script that will allow access into

/dev/mem and then reinstate root privileges to /dev/mem at the point of exit from the program?

 

Help!

morgsterdad

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 11 years ago

    Try running "sudo su", then you will be in a shell that has all root privileges.  When you run your Python script and it will definitely have all rights to access /dev/mem.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Hello All,

     

    Thank you for your input.  The program works!  My problems were related to permissions, paths and misunderstands on my part.  I still have many questions that probably will be answered with experience.  I am using "Raspberry Pi for Dummies" and "Programming the Raspberry Pi" as references, but they are very limited when trying to answer questions pertaining to Raspberry Pi, GPIO, Linux, Python and how they all work together.  Is there another reference that I could be using or is "trial and error" and Google the best references?

     

    Again thank you.  Next step is PWM.

     

     

    Regards,

     

    Bill

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • johnbeetem
    0 johnbeetem over 11 years ago in reply to Former Member

    My favorite reference for RasPi GPIO is the RasPi Hardware Wiki: http://elinux.org/RPi_Low-level_peripherals

    It includes both hardware description and software examples.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mconners
    0 mconners over 11 years ago in reply to johnbeetem

    That is a great Hardware reference John.

     

    For Unix command line stuff, I always liked

     

    Unix in a Nutshell, Fourth Edition: Arnold Robbins: 9780596100292: Amazon.com: Books

     

    I have the old version with Referees on the front. But it is a good reference for unix command like and basic sys admin.

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • mconners
    0 mconners over 11 years ago in reply to johnbeetem

    That is a great Hardware reference John.

     

    For Unix command line stuff, I always liked

     

    Unix in a Nutshell, Fourth Edition: Arnold Robbins: 9780596100292: Amazon.com: Books

     

    I have the old version with Referees on the front. But it is a good reference for unix command like and basic sys admin.

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • shabaz
    0 shabaz over 11 years ago in reply to mconners

    They do like their animals : )

    I think I posted this a while back, it was some notes I typed up for a few colleagues.

    It's very short, but might be useful until a textbook is purchased. Some older versions of UNIX allowed you to print out a whole list of commands along with a single-line description. I can't recall what the command was (maybe it was a switch in the 'man' command), or if it is present in Linux.

     

    Quick Linux Guide

    Once logged into the Linux machine via Telnet, you will see a command prompt. In Linux, the software that is running that displays the prompt and allows you to type content is called the ‘shell’. You can leave the shell at any time by typing ‘exit’.

    Command Prompt

    Commands typically (but not always) have the syntax

    command -option -option argument

     

    An example would be

    ls –l *.txt

    The command ‘ls’ performs a directory (i.e. folder) listing. The argument ‘-l’ displays in a ‘lengthy’ format. The ‘*.txt’ argument defines what files to list.

    Redirection

    You can force the output into a file, using ‘>’.

    For example,

    ls > listing.txt

    would place the directory listing output into a file called listing.txt.

    History

    You can see earlier commands that you have typed by using the history command. It is very useful.

    Commands

    Useful commands are shown here.

    Command

    Example

    Description

    man

    man pwd

    Bring up a screen of help information or a manual page for a command. Press space to step through it, and press 'q' to quit. Very useful to quickly obtain information about any command. The example here pulls up information on what the 'pwd' command does.

    cd

    cd /home

    Change directory (folder)

    mkdir

    mkdir bob

    mkdir /home/bob

    Make a directory (folder)

    pwd

    pwd

    Display the current directory

    ls

    ls -altr

    Directory listing of files. The ‘-altr’ is a combination of 4 options. ‘-a’ lists hidden files too. ‘-l’ displays in a lengthy detailed format. ‘-t’ displays in date stamped order. ‘-r’ reverses the order, so that the most recent file is printed last.

    cp

    cp bob.txt mytest1.txt

    Copies a file

    mv

    mv bob.txt tests/.

    Moves a file into a folder or to a new file name. The example shown here would move the file into the tests folder.

    rm

    rm bob.txt

    Delete a file

    cat

    cat readme.txt

    Displays the contents of a file.

    more

    more readme.txt

    ls –altr | more

    cat readme.txt | more

    Displays content, but pauses per page. It can be combined with other commands that print lots of output, using the ‘pipe’ character ‘|’. The second example would be useful for viewing the contents of a folder with hundreds of files. The third example does the same as the first example.

    su

    su

    su - bob

    Change user. This allows you to jump from one user to another. It effectively creates a new shell. The first example allows you to become the root user who has administrator privileges. The second example changes to the user called ‘bob’. You can revert back to the original user (i.e. the original shell) by typing ‘exit’.

    ps

    ps -ef

    View the running processes. The example lists all processes (‘-e’) and in a long format (‘-f’). This command is useful to see what is running, and also useful if you want to force a process to close using the next command in this table

    kill

    kill -9 3244

    Force a process (program) to be closed. The ‘-9’ is a special signal that usually tells the program to close. The argument 3244 is the process number, found by using the ‘ps –ef’ command mentioned above.

    df

    df -k

    Check disk space. The ‘-k’ displays the values in kbytes.

    history

    history

    See all the previous commands that were typed

     

     

     

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to mconners

    Hello,

     

    Are you saying that Unix and Linux are so closely related that a Unix reference could be used as a reference for Linux?  Is Python related to Unix as well?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mconners
    0 mconners over 11 years ago in reply to Former Member

    For all  intents and purposes Linux is Unix. Last I checked it  was more of the SYSV variant. So many of the references for that will be portable to linux.

     

    As John will like to tell you it is technically GNU/Linux, as linux itself is just the OS kernel, while all the command line programs and user oriented things are part of the GNU toolset.

     

    I wont overwhelm you with details at this point, but there is a lot to learn and a lot of resources.

     

    Python is a programming language that is available on most major operating systems.

     

    There are libraries available for python that can allow you to write programs that take advantage of operating systems and features, but they kind of stop being portable to the other operating systems at that point.

     

     

    Mike

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • iagorubio
    0 iagorubio over 11 years ago in reply to Former Member

    Bill, both Unix and Linux try conform to a family of IEEE standards called POSIX. That is Portable Operating System Interface and is meant to provide compatibility between different operating systems.

     

    So they are so close than if you know some Linux you can fiddle a bit on Unix. OsX is based on a BSD variant of Unix and is also POSIX compliant, the first time I saw and OsX box, I was able to open the terminal window and feel at home. Even Windows have a POSIX C library, so It's possible - and I have done it countless times - to port Linux programs to Windows without much work.

     

    Said that there are some differences between command's parameters.

     

    Here you have a Linux bash commands' list if you are interested on it. http://ss64.com/bash/

     

    Most of those commands work on Linux, Unix and OsX but the parameters of this list are for the Linux variants.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • johnbeetem
    0 johnbeetem over 11 years ago in reply to mconners

    Michael Conners wrote:

     

    For all  intents and purposes Linux is Unix. Last I checked it  was more of the SYSV variant. So many of the references for that will be portable to linux.

     

    As John will like to tell you it is technically GNU/Linux, as linux itself is just the OS kernel, while all the command line programs and user oriented things are part of the GNU toolset.

    I first learned Unix on a PDP-11/45 back around 1977.  The basic commands -- ls, grep, od, more -- still have the same names but many have new options.  So when I need a GNU/Linux command, I can usually use the old Unix command and use "man" (print manual) to find out what options are available today.  Occasionally there's a new command like "hd" (hex dump) -- in the PDP-11 days octal dumps ("od") were more useful :-)

     

    I was quite entertained to discover that I can use the good old "lpr" (line printer) command to print PDFs to my laser printer.  When I first used Unix, "lpr" did in fact print on a line printer.

     

    shabaz I think you should add "man" to your list of Unix/GNU commands.  IMO it's the most useful Unix command since you can use it to read about every other command.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 11 years ago in reply to johnbeetem

    John Beetem wrote:

     

    shabaz I think you should add "man" to your list of Unix/GNU commands.  IMO it's the most useful Unix command since you can use it to read about every other command.

    Hi John!

    Ahh you're right, it was a big oversight : (  I've added it now.

    I've been meaning to extend the list over time, but not got round to it so far : (

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mconners
    0 mconners over 11 years ago in reply to johnbeetem

    I could have sworn that at one time

     

    man -l

     

    gave you a list of all available man pages

     

    now it prompts for a man  page

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • iagorubio
    0 iagorubio over 11 years ago in reply to mconners

    A list of man pages ... lets try some bash magic.

     

    $ find /usr/share/man/ | sed -e "s#/usr/share/man##" | grep \^/man | awk -F/ '{ print $3 }' | sed -e "s/\.[0-9].gz//"

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mconners
    0 mconners over 11 years ago in reply to iagorubio

    That's definitely one way around it image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 11 years ago in reply to mconners

    Yes, same here. Guess these args have changed over time.

    I just tried reading man man, and think I've found something ok-ish:

    man -k [a-z] | more

     

    That lists over 3000 entries, single-line.

    Could be good for a general overview.

     

    Or, of course, to search for anything hex related as an example:

    man -k hex | more

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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