Raspberry Pi-Python-rpi.gpio

User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Raspberry Pi-Python-rpi.gpio

Post by WMc »

Hello all
'
I'm trying to find the "python-rpi.gpio" library used in the May2013 article of N/V's p.36.
'
I have downloaded Python 2.7.4 in the Rasp-Pi
'
The article link says the page has been moved, And Google returns no usable results.
'
Any help would be great.
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
aries
Posts: 2
Joined: Wed Jan 02, 2013 10:48 am
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by aries »

Hi Walt,

I have successfully imported rpi.gpio by changing it to RPi.GPIO as in

Pi@raspberrypi ~ $ sudo apt-get install python RPi.GPIO (enter)

The response was,

Reading package lists... Done
Building dependency tree
Reading state information--- Done
Note, selecting 'python3-rpi.gpio' for regex 'RPi.GPIO'
Note, selecting 'python-rpi.gpio' for regex 'RPi.GPIO'
python is already the newest version.
python-rpi.gpio is already the newest version.
python3rpi is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
Pi@raspberrypi ~ $

I had previously installed RPi.GPIO and that's why you see "0 upgraded, 0 newly installed, etc.

I have the leds working. However, I'm having a problem with detecting the 18B20 temperature sensor's ID#.

(From Pg 37, left column at bottom)

Pi@raspberrypi ~ $ sudo modprobe w1-gpio (enter)
Pi@raspberrypi ~ $
Pi@raspberrypi ~ $sudo modprobe w1-gpio (enter)
Pi@raspberrypi ~ $
(No error messages indicates, no problems with the above two commands).

Now going into the bus directory

Pi@raspberrypi ~ $ cd /sys/bus/w1/devices (enter)
Pi@raspberrypi /sys/bus/w1/devices $

Pi@raspberrypi /sys/bus/w1/devices $ ls
w1_bus_master1

(Typing "ls" to list the directories doesn't list the directory named for the serial number of the 18BS20. It
only displays one directory named "w1_bus_master1").

I'm up against the wall on this one. If you get to the point where you can read the ID#, please let me know.

Jerry
User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by WMc »

Jerry'
I tried your "sudo apt-get install python RPi.GPIO"
I'm still getting an error "E: Unable to locate package RPi.GPIO" ?
'
I can see the file but it's in the setup folder...Not sure where to go from here?
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
aries
Posts: 2
Joined: Wed Jan 02, 2013 10:48 am
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by aries »

Walt,

Saw your response and as I'm fairly new to Linux, I'm wondering if it makes a difference if you
are not is the correct directory. When I initially down loaded the file, I did a "cd /home/pi".

I don't think it makes a difference which directory your in, but it might be worth a try.

I sent an email to the NutVolts editor and asked him to forward the email to Ben Kibalo and
attached the info in my post to you. If he responds, I'll ask him about your problem as well.

Jerry
User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by WMc »

Jerry
'
Many Thanks for the reply and the e-mail you sent.
'
I'm new to linux as well...So I'll keep reading.
'
Thanks again
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by WMc »

I was really hoping the Aurthur would had chimed in by now.
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
bkibalo
Posts: 9
Joined: Thu May 09, 2013 1:39 pm
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by bkibalo »

Jerry,

Sorry for not getting on here sooner. Seems like you have gotten the GPIO installed properly. The w1_bus_master1 is a directory, open that up and the serial number folder to access your devices should be in there.

I'll check back and see if that worked for you.

Thanks
Ben
bkibalo
Posts: 9
Joined: Thu May 09, 2013 1:39 pm
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by bkibalo »

Jerry

The commands should be:
>sudo modprobe w1-gpio
>sudo modprobe w1-therm

I'm not sure if this was a typo in the post - this is as listed in the article. Make sure this is correct and let me know if you are still having issues.

Sorry again for not being on here sooner.

Thanks
Ben
bkibalo
Posts: 9
Joined: Thu May 09, 2013 1:39 pm
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by bkibalo »

WMC,

You may be having some trouble because you need to update your package list. Try:

>sudo apt-get update

then try

>sudo apt-get install python-rpi.gpio

If that isn't working, do a package search, for example:

>sudo apt-cache search gpio

This should provide a list of applicable programs for you to install.

If that still doesn't work, try installing the python-dev library too:

>sudo apt-get install python-dev

Please let me know if you get it all working. Once in python:

>>> import RPi.GPIO as GPIO

should work just fine.

Thanks
Ben
User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by WMc »

Thanks for the reply
'
I'll try the above and report back 5/10/13
'
Thanks for the info and help
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by WMc »

Thanks Ben
'
I needed the update as that fixed the problem.
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
bkibalo
Posts: 9
Joined: Thu May 09, 2013 1:39 pm
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by bkibalo »

WMC,

Glad that fixed the issue. If has been a while since you installed something, you should always update the listing first with the update.

Good luck!
Ben
User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by WMc »

New problem
'
Python keeps kicking me to the curb with a [ "return 0" outside of the command error in line 15]. This is the first return in the code. I checked spelling, indentation, replaced colons with semicolons, Nothing seem to work.
'
I've tested the code "led.py" in IDLE and I get the same error. 'return' outside function(led.py,line 15).
'
Any help or idea's would be greatly appreciated
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
bkibalo
Posts: 9
Joined: Thu May 09, 2013 1:39 pm
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by bkibalo »

WMc,

The returns aren't really necessary - (the last return line should be even-spaced with all of the GPIO statements, ensure that is the case first), If you want to implement them for error handling you can do so - you can simply remove all the return statements safely. If you end up removing the returns, remove entire the else: return 1 part as well for each LED.

Make sure you are using python 2.x (2.7 ideally) and not python 3.

Make sure you are running python as superuser. If you are using idle, type "sudo idle" and if you are using python directly, type "sudo python xxxx.py"

Don't use semicolons, only colons are appropriate here.

Do you have the GPIO.setwarnings commented out? If so, try uncommenting it.

Also, check your raspberry pi version. If you have a model A the pinout may be different. For example, I mention this in the article, I think the GRN pin is actually 21 (as pictured) and not 27 for the model A (or the older version of the model B). Does the RED led work and you get the error on the GRN LED? If you comment out the GPIO.setup(GRN, GPIO.OUT) line does the red led work? if this is the case, try changing the pin assignment for GRN to 21.

I put in some boiled down code here to hopefully help. Make sure the indents are all correct before running:
Have you gotten the temperature sensor working from the console yet?? Best of luck - Ben

#By: Benjamin Kibalo, March 2013
#code to toggle red and green LEDs on Raspberry Pi


import RPi.GPIO as GPIO

RED = 17 #set this to your software GPIO flag for the red LED
GRN = 27 #set this to your software GPIO flag for the green LED try pin 21, if 27 doesn't work on older boards

def set_LED(color, state):
GPIO.setwarnings(False) #Calling set_LED as a function doesn't always release the pins, this avoids conflicts, run with this commented out first
GPIO.setmode(GPIO.BCM) #use BCM pin numbering
GPIO.setup(GRN, GPIO.OUT) #set GRN LED pin to output
GPIO.setup(RED, GPIO.OUT) #set RED LED pin to output
if color == 'red':
if state == 'on':
GPIO.output(RED, True) #turn RED LED on
elif state == 'off':
GPIO.output(RED, False) #turn RED LED off
elif color == 'green':
if state == 'on':
GPIO.output(GRN, True) #turn GRN LED on
elif state == 'off':
GPIO.output(GRN, False) #turn GRN LED off
User avatar
WMc
Posts: 15
Joined: Sat Dec 10, 2011 3:46 pm
Location: Central FL
Contact:

Re: Raspberry Pi-Python-rpi.gpio

Post by WMc »

@Ben
'
I think I have a complier settings issue.
'
I used the code you posted with out the returns an I rem'd (#) out the GPIO.setwarnings(False). I also tried it with this active.
'
Now I'm getting a NameError: name 'color' is not defined
'
I see
'
Python 2.7.3rc3 (default, May 6 2012, 20:02:25)
[GCC 4.6.4] on linux2
'
At the top of the Python window after typing 'sudo python'.
'
I've read into the python compiler but I don't see whats wrong.
'
Any suggestion would be great.
__Walt McDonald__


It's not rocket-surgery
I see why we don't have any water,All of the pipes are full of wires!
E=WMc2
Now with WiFi



ABB M202 certified
ABB M211 certified
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests