roller344
Posts: 5
Joined: Fri Apr 12, 2013 9:13 am

Installing RPi.Gpio for python

Fri Apr 12, 2013 9:18 am

I just wanna get started programming my pi with led's and stuff but why the F*** isn't RPi.gpio installed in the first place when it has gpio. I can't use ssh because i don't have a Ethernet stick for my pi. And no one explains how to install the package trugh usb or anything like that. Sorry but i'm fustrated. What to do?

Sry for bad english

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: Installing RPi.Gpio for python

Fri Apr 12, 2013 12:27 pm

Which image?

Which Model?

Are You using a Powered hub?

What do you mean by an ethernet stick?
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

roller344
Posts: 5
Joined: Fri Apr 12, 2013 9:13 am

Re: Installing RPi.Gpio for python

Fri Apr 12, 2013 2:43 pm

Image is wheezy i think

its the model B rev B

Power hub? what do you mean. Im just powering via mini sub and only using the 2 usb's

The stick to internet connection so i can conect via my computer.

My question is just. Can u install Rpi.GPIO 0.5.2 to the rpi via usb? and how.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4115
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Installing RPi.Gpio for python

Fri Apr 12, 2013 4:51 pm

According to the wiki (http://elinux.org/Rpi_Low-level_periphe ... er_support) "The RPi.GPIO module is installed by default in Raspbian. Any Python script that controls GPIO must be run as root."

As for connecting the Pi to the internet to download software, upgrades etc. you either use the fitted wired ethernet (LAN) port to connect to your router, or, if your router is WiFi only, a WiFi dongle (which may be your "ethernet stick".
Trev.
Usually running Raspbian Jessie on up to 12 of 13 Pi's (an A, B1, 2xB2, 2xB+, A+, P2B, 3xP0, P0W) and Stretch on my P3B. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Installing RPi.Gpio for python

Fri Apr 12, 2013 4:57 pm

As Trevor has said while I was typing this, RPi.Gpio is probably already installed as part of your version of raspbian.

What happens if you fire up python and try

Code: Select all

import RPi.GPIO as GPIO
If it imports correctly you can get the version of the module with GPIO.VERSION

If you need to upgrade, the most recent release is here -
http://raspberry-gpio-python.googlecode ... .2a.tar.gz

That's just a compressed tar archive, so it can be downloaded however you can arrange it and put on a usb stick or similar for installation on your Pi.

I've only used the version that came with raspbian, but installing a later version looks as though it would need this -

Code: Select all

$ tar zxf RPi.GPIO-0.5.2a.tar.gz
$ cd RPi.GPIO-0.5.2a
$ sudo python setup.py install
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

roller344
Posts: 5
Joined: Fri Apr 12, 2013 9:13 am

Re: Installing RPi.Gpio for python

Fri Apr 12, 2013 5:50 pm

As Trevor has said while I was typing this, RPi.Gpio is probably already installed as part of your version of raspbian.

What happens if you fire up python and try
CODE: SELECT ALL
import RPi.GPIO as GPIO


i dont understand? If it imports then why do i have to download stuff to install? if u say its already in the version.

I'm new to python and Rpi sry

gordon77
Posts: 3003
Joined: Sun Aug 05, 2012 3:12 pm

Re: Installing RPi.Gpio for python

Fri Apr 12, 2013 5:58 pm

If it works as you wish then don't upgrade. There maybe improvements in an upgrade.

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Installing RPi.Gpio for python

Fri Apr 12, 2013 6:11 pm

roller344 wrote: i dont understand? If it imports then why do i have to download stuff to install? if u say its already in the version.
When the Pi was first released there was no support for gpio. Some smart guys developed it and made it available as a separate package. Documents got written saying how to download and install it.

It became so useful that the maintainers of the operating system started including it in their versions of raspbian. At that point there was no longer a need to download it separately. But the people who had previously written documents didn't go back and change their webpages... So when you come along and try to learn how to use gpio on the Pi you are likely to find outdated and misleading information.

Not a problem restricted to the Pi. It's the nature of an open and unmediated publishing medium like the internet.

At least, that's the way I see it.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

roller344
Posts: 5
Joined: Fri Apr 12, 2013 9:13 am

Re: Installing RPi.Gpio for python

Sat Apr 13, 2013 9:28 am

CODE: SELECT ALL
import RPi.GPIO as GPIO

It says:
treaceback (most recent call last):
File "<pyshell2>", line 1, in module <module>
import Rpi.Gpio as GPIO
importerror: No module named Rpi.GPIO


And its all in read. The software is fully updated

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2808
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Installing RPi.Gpio for python

Sun Apr 14, 2013 7:20 pm

It has to be

Code: Select all

import RPi.GPIO as GPIO
you've got the case wrong, you typed Rpi.GPIO when it should be RPi.GPIO

you probably need to start python with

Code: Select all

sudo python
as well

I try to keep my RPi.GPIO tutorials up to date, but I haven't written any for the basics yet. The challenge is a real one as the pace of development is frantically fast. It takes a very long time to write bullet-proof tutorials. At least web based ones are updatable - dead-tree books aren't easily updated.

And let's not forget, RPi.GPIO is still in alpha - that means it's subject to change. It's very much a work in progress, but it's a very good work in progress. Thanks to Ben for doing it. :D
Alex Eames RasPi.TV, RasP.iO

User avatar
croston
Posts: 670
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Installing RPi.Gpio for python

Sun Apr 14, 2013 7:40 pm

You can find up-to-date instructions and examples here:
http://code.google.com/p/raspberry-gpio ... i/Examples

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2808
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Installing RPi.Gpio for python

Sun Apr 14, 2013 8:30 pm

croston wrote:You can find up-to-date instructions and examples here:
http://code.google.com/p/raspberry-gpio ... i/Examples
Shoot - I meant to add that link in and got distracted. :lol:
Alex Eames RasPi.TV, RasP.iO

raspytongue
Posts: 7
Joined: Sat Apr 13, 2013 8:42 pm

Re: Installing RPi.Gpio for python

Wed Apr 17, 2013 3:54 pm

Well, I have the latest pre-installed SD image of Wheezy, which I think has Python by default.
When I typed
sudo python, it returned this

pi@raspberrypi ~ $ sudo python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Not sure what to do next. I also tried to import RPi GPIO, but nothing happened. Didn't get the prompt coming up after the word information above.

I'm trying to run the small stepper motor plus PCB from the GPIO pins. Correct wiring, but as you can see can't progress. Any help? Thanks.

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Installing RPi.Gpio for python

Wed Apr 17, 2013 5:20 pm

@raspytongue. Odd! This is what it looks like for me in similar circumstances -

Code: Select all

pi@raspberrypi ~ $ sudo python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>>
Do you really not get the
>>>
prompt?

Do you just get a
pi@raspberrypi ~ $
prompt again, or does your shell session hang?

Not that it should make a difference, how are you getting to the shell (cli) prompt? Directly on the Pi, via an ssh login, or from a virtual terminal session via the 'Big Raspberry' gui?
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

raspytongue
Posts: 7
Joined: Sat Apr 13, 2013 8:42 pm

Re: Installing RPi.Gpio for python

Wed Apr 17, 2013 6:51 pm

Tried again, and acted on the three forward arrows this time:

Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>>
Looks like yours, but nothing else.
What should happen now? Return just repeats the arrows.
BTW, I am on a Mac using Terminal.
I checked the folder, and the latest update of RPi GPIO is already there! But I can't get to it. Any code lines referring to GPIO returns:

command not found

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Installing RPi.Gpio for python

Wed Apr 17, 2013 9:02 pm

raspytongue wrote:Tried again, and acted on the three forward arrows this time:

Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>>
Looks like yours, but nothing else.
What should happen now? Return just repeats the arrows.
BTW, I am on a Mac using Terminal.
I checked the folder, and the latest update of RPi GPIO is already there! But I can't get to it. Any code lines referring to GPIO returns:

command not found
Since no error kicked out, it means that RPi.GPIO is installed, and you've successfully imported it in python. You're ready to start hooking up LEDs and playing.
There are 10 types of people in this world. Those that understand binary, and those that don't.

texy
Forum Moderator
Forum Moderator
Posts: 5004
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Installing RPi.Gpio for python

Thu Apr 18, 2013 8:39 am

raspytongue wrote:Tried again, and acted on the three forward arrows this time:

Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>>
Looks like yours, but nothing else.
What should happen now? Return just repeats the arrows.
BTW, I am on a Mac using Terminal.
I checked the folder, and the latest update of RPi GPIO is already there! But I can't get to it. Any code lines referring to GPIO returns:

command not found
That is expected operation - you have successfully entered the python command line interpreter, so each line you enter will be acted upon as you hit enter.
If you wish to write a program (or a script if you like), then I'd suggest you enter the X GUI and run python's editor 'Idle' from the desktop.
Actually if you want to access the GPIO port you will need to run xterminal and type 'sudo Idle', and then write your program. When you are ready to run it, hit F5

Hope this helps,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

toxibunny
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm

Re: Installing RPi.Gpio for python

Thu Apr 18, 2013 9:03 am

when I'm working through SSH, I usually 'sudo nano myfilename.py', type my stuff in, save it, exit, and then 'sudo python myfilename.py' to run it...
note: I may or may not know what I'm talking about...

texy
Forum Moderator
Forum Moderator
Posts: 5004
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Installing RPi.Gpio for python

Thu Apr 18, 2013 9:08 am

I do as well, but if you are brand new to python, then Idle gives you more formatting clues......

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

raspytongue
Posts: 7
Joined: Sat Apr 13, 2013 8:42 pm

Re: Installing RPi.Gpio for python

Thu Apr 18, 2013 10:10 am

Thanks for all the ideas. I'm slowly getting it.

Am I right in thinking that any GPIO code written directly to Terminal (on Mac) needs to be given a name, saved, then put in a named file, then referred to in the script before it can run? I hope I have got this right.
My SD card already includes the latest Raspbian and GPIO.
I want to run a small stepper motor, and there is a lot of info for doing this, but haven't seen any which shows to open a new file, name it, then save it.
I need to access the RPi GPIO ports. I have wired the motor correctly, copied and pasted some code to run the motor directly into Terminal, but only get
bash: command not found
when trying to run it. Tried sudo, same result.
So....I open a new file, copy the stepper code into it, save with a name like "stepper" etc. Then go in as root sudo etc.....open the saved file and run it. Am I close.....?

toxibunny
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm

Re: Installing RPi.Gpio for python

Thu Apr 18, 2013 8:13 pm

"So....I open a new file, copy the stepper code into it, save with a name like "stepper" etc. Then go in as root sudo etc.....open the saved file and run it. Am I close.....?"

Use a text editor to write your python program in. Any plain text editor will do, but if you use one specially for programming, it'll colour the text as you go through, which is handy for spotting spelling mistakes, etc.

Like I said, when running through SSH, I use nano, which I think does the colour-coding, but it's been a while so I'm not 100% sure. So, at the terminal, type:

Code: Select all

sudo nano stepper.py
This will open the text editor program (it's text mode so it looks like an old DOS program - no GUI, no mouse control) - you type your code in there. CTRL+x will quit the program, giving you a chance to save first if you've made any changes. do so. Then, to try it out, type:

Code: Select all

sudo python stepper.py
This loads and runs your program through the python interpreter (there's no compiling with python. No .exe or .app files or anything - just a text file that runs through an interpreter. This is just how python works) - now it's pretty likely that it won't work and will just throw up an error. Read what it says, then go back into nano to fix it:

Code: Select all

sudo nano stepper.py
Fix your stuff, save and exit, and then again:

Code: Select all

sudo python stepper.py
It's likely to show other errors you missed, so just repeat the 'fix, try' cycle until it works :)

You don't have to type the sudo nano etc every time - just press the cursor up and it'll run through the most recent commands. This will save you a little bit of hassle at least. Enjoy and good luck!
note: I may or may not know what I'm talking about...

raspytongue
Posts: 7
Joined: Sat Apr 13, 2013 8:42 pm

Re: Installing RPi.Gpio for python

Fri Apr 19, 2013 5:07 am

Got it! Followed your useful instructions, and got the motor working first time. Easy-peasy when you know how. Now I am having probs editing the nano text file. I really want to delete all of it, and copy in more code tweaking the variables to increase motor speed. There is a guide at the bottom of the window, but no delete all option. I cant seem to get the cursor to move to a line and modify the line. I am working in an alien environment here, so different to "Word", (obviously), but still frustrating.

toxibunny
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm

Re: Installing RPi.Gpio for python

Fri Apr 19, 2013 7:33 pm

I have heard there's a way to get the Raspi's graphical desktop working through SSH or something similar - this'll let you use the friendlier 'Idle', and also use the mouse. I don't know how to do it though, or even if it really helps...

It's all pretty foreign to me too, to be honest.
note: I may or may not know what I'm talking about...

raspytongue
Posts: 7
Joined: Sat Apr 13, 2013 8:42 pm

Re: Installing RPi.Gpio for python

Sun Apr 21, 2013 6:22 pm

I came up with a simple way of changing code in a nano box. I just copied and pasted new code into the box, and when saving it, got message if I wanted to overwrite. Y will then overwrite the older code. Not sure if this is the accepted way, but worked for me.

fredhatfield
Posts: 22
Joined: Fri Jan 11, 2013 12:28 pm

Re: Installing RPi.Gpio for python

Mon May 06, 2013 7:32 pm

I have been having trouble getting the initial load of GPIO into Python. When I type:

import RPi.GPIO as GPIO

I get an error message "syntax error" pointing out "import" -- this is when I am using
the graphical interface IDLE. I tried all kinds of things but to no avail.

After 2 days of frustration, I tried searching this forum and it has been very helpful.
I discovered that the import function works successfully from the Pi command line
when I access Python there as shown by your example. I get a successful download
and response to GPIO.VERSION command. But the import will not work from the
IDLE graphic interface.

Could there be a problem in the IDLE graphics interface?

Another noobie learning step-by-step......

Fred.

Return to “The Staffroom”

Who is online

Users browsing this forum: No registered users and 0 guests