WiringPython - WiringPi for Python


206 posts   Page 3 of 9   1, 2, 3, 4, 5, 6 ... 9
by Greebie » Thu Jul 19, 2012 11:33 am
Actually, ignore that, seems I may have worked it out! (didn't take too long did it!?) ;)

It seems I need to put wiringpi.wiringPiSetupGpio()!
Posts: 7
Joined: Wed Jun 27, 2012 8:25 am
by canyon » Thu Jul 19, 2012 1:17 pm
I'm a bit vague about building packages in Linux, but I successfully installed wiringpi and WiringPython in Wheezy-beta. I can't seem to manage it with the new official Raspbian distro.
In my (several!) first attempts, I got this message:
wiringpi_wrap.c:3309:40: fatal error: WiringPi/wiringPi/wiringPi.h: No such file or directory
compilation terminated.

Eventually, I think I fudged the issue by putting the WiringPython files in the same directory as the files for the original wiringpi installation, and changing the capitalisation of one of the "wiringPi" directories.

I think WiringPython is there, but it seems to be missing some bits as now I get this error message when I try to import it:
root@raspberrypi:/home/jim/tmp# python
Python 2.7.3rc2 (default, May 6 2012, 20:02:25)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wiringpi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "wiringpi.py", line 26, in <module>
_wiringpi = swig_import_helper()
File "wiringpi.py", line 18, in swig_import_helper
import _wiringpi
ImportError: /usr/local/lib/python2.7/dist-packages/_wiringpi.so: undefined symbol: shiftOutWithDelay

I'm sorry if this seems somewhat confused, but I've been playing with it for hours and uninstalling/reinstalling bits, so I don't know whether I'm coming or going. :?
Can some kind soul provide some more explicit instuctions for Dummies like me?
Thanks...
Posts: 31
Joined: Sun Jan 29, 2012 9:47 am
by canyon » Fri Jul 20, 2012 9:50 am
Hooray!
I solved it by myself :D
I suspect that I was using the instructions I wrote down from previous versions, and got a bit mixed up (aka completly confused).
So, I went back to the start and carefully followed the instructions in the new README with success.

As a bit of a 'Dummy', I found the instructions to be too terse for me to understand easily. For others like me, could they be made more verbose. For example:
- Use only one shell command per line.
- Don't assume that necessary dependencies are present: both 'swig' and 'python-dev' have caught me out (you have already sorted the python-dev issue in the readme, thanks!).

For me, the Raspberry Pi's IO capabilities are tremendously exciting and being able to easily utilise them from python is a great step forward. So a big thanks to Gordon and gadgetoid for a great addition to the Raspberry Pi's repetoire.
Posts: 31
Joined: Sun Jan 29, 2012 9:47 am
by kghunt » Fri Jul 27, 2012 2:44 pm
WiringPython Git Hub is giving 404 not found?
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by texy » Fri Jul 27, 2012 2:54 pm
Are you sure you are using the correct address ?

git clone https://github.com/WiringPi/WiringPi-Python.git

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2385
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by kghunt » Fri Jul 27, 2012 3:33 pm
I was using the link in the first post also tried googling it.
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by kghunt » Fri Jul 27, 2012 4:02 pm
Is it just me or does non of the documentation show how to set up a pin as an input?
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by kghunt » Fri Jul 27, 2012 4:09 pm
why doesnt this work?

Code: Select all
#!/usr/bin/env python
import wiringpi
wiringpi.wiringPiSetupGpio



def main():
   print "test"
   wiringpi.pinMode(3,wiringpi.INPUT)
   d0 = wiringpi.digitalread(3)
   print d0



      
      
if __name__ == '__main__':
   main()
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by texy » Fri Jul 27, 2012 4:11 pm
kghunt wrote:Is it just me or does non of the documentation show how to set up a pin as an input?


Yes, the README is a little sparce on info, but Gordon's page https://projects.drogon.net/raspberry-pi/wiringpi/functions/ here explains it.

Note the python version does not support PWM, but it would be really nice if it did ;) ;)

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2385
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by kghunt » Fri Jul 27, 2012 4:31 pm
I think it was because wiringpi doesnt have physical pin numbering. Change that now but still cant get it to work...

Code: Select all
#!/usr/bin/env python
import wiringpi
wiringpi.wiringPiSetupGpio

def main():
   print "test"
   wiringpi.pinMode(0,0)
   wiringpi.pinMode(1,0)
   data0 = wiringpi.digitalRead(0)
   data1 = wiringpi.digitalRead(1)
   print data0
   print data1
if __name__ == '__main__':
   main()
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by canyon » Fri Jul 27, 2012 5:14 pm
@texy - wiringpi for python does support pwm:
Here are the relevent commands:
Note that wiringpi pin 1 == BCM_GPIO 18, which is the one that supports PWM.
Code: Select all
# Set up pin 1 to PWM mode:
wiringpi.pinMode(1,2)

# Write an integer x to pin 1 ( 0 < x < 1023):
pwmWrite(1,x)

I've just tried this on my Pi, and it does work.
Posts: 31
Joined: Sun Jan 29, 2012 9:47 am
by texy » Fri Jul 27, 2012 5:23 pm
canyon wrote:@texy - wiringpi for python does support pwm:
Here are the relevent commands:
Note that wiringpi pin 1 == BCM_GPIO 18, which is the one that supports PWM.
Code: Select all
# Set up pin 1 to PWM mode:
wiringpi.pinMode(1,2)

# Write an integer x to pin 1 ( 0 < x < 1023):
pwmWrite(1,x)

I've just tried this on my Pi, and it does work.


Great! I didn't realise it was supported :)

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2385
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by texy » Fri Jul 27, 2012 5:52 pm
Don't forget its :

wiringpi.pwmWrite(1,x)


Confirmed it works as expected.
T.
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2385
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by texy » Fri Jul 27, 2012 6:00 pm
kghunt wrote:I think it was because wiringpi doesnt have physical pin numbering. Change that now but still cant get it to work...

Code: Select all
#!/usr/bin/env python
import wiringpi
wiringpi.wiringPiSetupGpio

def main():
   print "test"
   wiringpi.pinMode(0,0)
   wiringpi.pinMode(1,0)
   data0 = wiringpi.digitalRead(0)
   data1 = wiringpi.digitalRead(1)
   print data0
   print data1
if __name__ == '__main__':
   main()


With
Code: Select all
wiringpi.wiringPiSetupGpio

you will need
Code: Select all
   wiringpi.pinMode(17,0) # 17 = wiringpi pin 0, physical pin 11
   wiringpi.pinMode(18,0) # 18 = wiringpi pin 1, physical pin 12
   data0 = wiringpi.digitalRead(17)
   data1 = wiringpi.digitalRead(18)


I haven't tried Inputs yet, but those numbers work for my LCD, obviously as Outputs.


Update : confirmed it works ;) I have a wire coming from physical pin 13 (wiringpi pin 21), and I can
Code: Select all
print wiringpi.digitalRead(21)
and it will return a 0 if unconnected, or a 1 if connected to 3v3.


Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2385
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by kghunt » Fri Jul 27, 2012 8:00 pm
Do you find wiring pi faster? I am trying to get data from a wiegand proximity reader but RPi.GPIO doesn't seem quick enough to capture all the bits.
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by texy » Sat Jul 28, 2012 6:22 pm
Speed wise they are now very similar, although I haven't tried any extensive testing with the latest releases.

T.
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2385
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by kghunt » Mon Jul 30, 2012 8:14 am
Still can't get this working. Now I am at least getting 0's back but there is no change. It works fine using RPi.GPIO

Code: Select all
#!/usr/bin/env python
import wiringpi
from time import sleep
wiringpi.wiringPiSetupGpio
wiringpi.pinMode(17,0)
wiringpi.pinMode(18,0)

def main():
   while True:
      sleep(1)
      data0 = wiringpi.digitalRead(17)
      data1 = wiringpi.digitalRead(18)
      print data0
      print data1
if __name__ == '__main__':
   main()


Interestingly though if I use pin 0 and 1 (physical pins 3 and 5) it does not work at all.
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by canyon » Mon Jul 30, 2012 11:23 am
I tried it using your code, and got the same results.
You have entered the following line wrong:
Code: Select all
wiringpi.wiringPiSetupGpio

It should have empty brackets at the end:
Code: Select all
wiringpi.wiringPiSetupGpio()

I made the change, tried it again and it now works as you wanted. :D

Hope that helps...
Posts: 31
Joined: Sun Jan 29, 2012 9:47 am
by texy » Mon Jul 30, 2012 12:21 pm
Thats annoying, cos python doesn't come up with a syntax error :?

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2385
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by canyon » Mon Jul 30, 2012 12:42 pm
Thats annoying, cos python doesn't come up with a syntax error

Yes, that suprised me too..
Posts: 31
Joined: Sun Jan 29, 2012 9:47 am
by kghunt » Mon Jul 30, 2012 4:34 pm
doh! School boy...

This is now working yay (9 times out of 10 anyway).
#!/usr/bin/env python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
from time import sleep

GPIO.setup(3, GPIO.IN) #data 0
GPIO.setup(5, GPIO.IN) #data 1

def test():
result = []
print "pres
ent badge"
while True:
data0 = GPIO.input(3)
data1 = GPIO.input(5)
if data0 == False or data1 == False:
result.append(data0)
sleep(0.0001)
if len(result) >= 26:
break


sc = result[1:9]
sco=""
for i in sc:
i = int(i)
i = str(i)
sco = sco + i
sco = int(sco,2)
print "site code is: ", sco

badge = result[10:25]
badge0 = ""
for i in badge:
i = int(i)
i = str(i)
badge0 = badge0 + i
badge0 = int(badge0,2)

print "badge number is: ", badge0

if __name__ == '__main__':
test()

The reader if anyone is interested is a HID iClass reader. Thats 2 readers I have interface with the pi now. :-)

[code][/code]
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by kghunt » Mon Jul 30, 2012 4:37 pm
I switched back to RPi.GPIO as there was no difference in speed that I could tell. And RPi is better structured I think. I find it much easier to use as I prefer to use the board pin numbers. It is quite hard to catch all the bits from something that is sending bits every 40 ms.

I suspect it would be much better in c.
Posts: 355
Joined: Sun Mar 04, 2012 9:28 am
by MadCow42 » Mon Jul 30, 2012 8:53 pm
texy wrote:Thats annoying, cos python doesn't come up with a syntax error :?

Texy


Well, surprising but also useful. When you leave off the braces, it simply returns a reference to the function itself. That sucks when you forget to put them on, but it allows you to pass in a reference to a function to another function.

If you look at the stepper motor code I posted a while back, I do this in the "ramp" method - you pass in the stepping function that you want to use during the ramp. That allows me to use one ramp method with several different stepping methods (full step, half step, full step reverse, half step reverse) - instead of having four separate ramp methods.

Kevin.
Posts: 86
Joined: Sun Jul 01, 2012 12:48 am
by Grumpy Mike » Tue Aug 14, 2012 4:04 am
kghunt wrote: It is quite hard to catch all the bits from something that is sending bits every 40 ms.


So use the GPIO edge detection mode rather than simply looking at the logic level on the pin.
User avatar
Posts: 784
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by kcranley » Tue Aug 14, 2012 11:39 am
I'm a newbie, and I'm getting very confused about getting WiringPi for Python working. I have installed python-dev, and run the following lines:
Code: Select all
wget http://raspberry-gpio-python.googlecode.com/files/python-rpi.gpio_0.3.1a-1_armhf.deb
sudo dpkg -i python-rpi.gpio_0.3.1a-1_armhf.deb

but when I run the following line within a Python program:
Code: Select all
import wiringpi
, it seems to run that OK, but within wiringpi, it gives the error:
Code: Select all
ImportError: No module named _wiringpi

I would be very grateful if someone could put me right - I have a Python version of the Pelican Crossing which works with GPIO, and I would like to get it going with wiringPi. Has anyone else done this?
Posts: 9
Joined: Fri Jan 20, 2012 10:33 am