gadgetoid
Posts: 152
Joined: Wed Mar 07, 2012 9:58 pm

Re: WiringPython - WiringPi for Python

Mon Sep 03, 2012 9:41 pm

Pushed an update to the repo if anyone would care to test: https://github.com/WiringPi/WiringPi-Python

Haven't wrapped this one up as a PyPI package yet, but it should be good to go.

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

Re: WiringPython - WiringPi for Python

Tue Sep 04, 2012 6:20 am

Hi Gadgetoid.
So to update, or install from fresh is it :

Code: Select all

git clone https://github.com/WiringPi/WiringPi-Python.git
...also going by the 'age' of the various files, the readme has'nt been updated, so we don't know how to use the new features.
Apologies in advance, if I am misunderstanding - I haven't actually tried the update ;)

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

kcranley
Posts: 16
Joined: Fri Jan 20, 2012 10:33 am

Re: WiringPython - WiringPi for Python

Wed Sep 12, 2012 8:21 am

Hi Gadgetoid
I previously had WiringPi working but on upgrading my Wheezy from 2012-07-15-wheezy-raspbian to the 2012-08-16-wheezy-raspbian version, I'm getting:

ImportError: No module named _wiringpi

I have tried

sudo apt-get install python-dev python-pip

Then:

sudo pip install wiringpi

but the wiring.py module seems to be having trouble finding _wiringPiGpioMode

I would be very grateful if you could help
Many thanks in advance
KC

sparkyhall
Posts: 170
Joined: Mon Aug 27, 2012 9:14 am

Re: WiringPython - WiringPi for Python

Wed Sep 12, 2012 8:19 pm

As far as I know there is no "wiringPiGpioMode" command, perhaps there used to be in earlier versions?

In your python code to setup wiringpi with gpio pin numbering you should use something like:

Code: Select all

import wiringpi
wiringpi.wiringPiSetupGpio()
Regards,

sparkyhall

kcranley
Posts: 16
Joined: Fri Jan 20, 2012 10:33 am

Re: WiringPython - WiringPi for Python

Thu Sep 13, 2012 9:16 am

In my wiringpi.py, there is the following section:

Code: Select all

83   def wiringPiGpioMode(*args):
84      return _wiringpi.wiringPiGpioMode(*args)
85   wiringPiGpioMode = _wiringpi.wiringPiGpioMode
and this last line is where it's failing:
AttributeError: 'module' object has no attribute 'wiringPiGpioMode'

sparkyhall
Posts: 170
Joined: Mon Aug 27, 2012 9:14 am

Re: WiringPython - WiringPi for Python

Thu Sep 13, 2012 7:44 pm

It looks like you still have an out of date wiringpi.py there, here's what I have in mine after a "pip install wiringpi":

Code: Select all

79  def wiringPiSetupGpio():
80    return _wiringpi.wiringPiSetupGpio()
81  wiringPiSetupGpio = _wiringpi.wiringPiSetupGpio
82  
83  def pullUpDnControl(*args):
84    return _wiringpi.pullUpDnControl(*args)
85  pullUpDnControl = _wiringpi.pullUpDnControl
Note: my wiringpi.py is located in /usr/lib/python2.7/site-packages

kcranley
Posts: 16
Joined: Fri Jan 20, 2012 10:33 am

Re: WiringPython - WiringPi for Python

Fri Sep 14, 2012 4:36 pm

Thank you!! I copied wiringpi.py from /usr/local/lib/python2.7/dist-packages to /home/pi where my Python program lives, over-writing the old file - and it now works!! My old version of wiringpi.py was evidently out of date.

ACP_
Posts: 33
Joined: Sat Aug 18, 2012 10:40 pm

Re: WiringPython - WiringPi for Python

Fri Sep 14, 2012 6:33 pm

When compiling today's code form git repository gcc has problem finding wiringPi.h on my Raspbian wheezy:

Code: Select all

WiringPi/wiringPi/piNes.c:25:22: fatal error: wiringPi.h: No such file or directory
You just need to edit piNes.c and change first include line into:

Code: Select all

#include "wiringPi.h"
That fixes the problem.

devnull
Posts: 65
Joined: Sat Dec 24, 2011 7:46 am

Re: WiringPython - WiringPi for Python

Sun Sep 16, 2012 9:46 am

Hi;

Thanks so much for all the work on this, but would it be possible to include wiringpi's latest support for interrupts, ?.

It is exactly what I need to solve a problem that would otherwise involve a tight loop and lots of cpu usage

Many Thanks
> /dev/null 2>&1

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

Re: WiringPython - WiringPi for Python

Mon Sep 24, 2012 4:20 pm

ACP_ wrote:When compiling today's code form git repository gcc has problem finding wiringPi.h on my Raspbian wheezy:

Code: Select all

WiringPi/wiringPi/piNes.c:25:22: fatal error: wiringPi.h: No such file or directory
You just need to edit piNes.c and change first include line into:

Code: Select all

#include "wiringPi.h"
That fixes the problem.
That doesn't fix it for me - the first line is already

Code: Select all

#include <wiringPi.h>
Even if I add your additional line, still get the same error.

The 'pip method does work, however.
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

devnull
Posts: 65
Joined: Sat Dec 24, 2011 7:46 am

Re: WiringPython - WiringPi for Python

Mon Sep 24, 2012 11:07 pm

Hi;

The first line needs to be changed to use speech marks, from:

Code: Select all

#include <wiringPi.h>
to:

Code: Select all

#include "wiringPi.h"
> /dev/null 2>&1

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

Re: WiringPython - WiringPi for Python

Tue Sep 25, 2012 8:46 am

Surely if it had both versions it should be ok?
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

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

Re: WiringPython - WiringPi for Python

Tue Sep 25, 2012 1:20 pm

I've just got past this hurdle...

Code: Select all

#include "wiringPi.h"
...and stumbled at the next fence. :(

Now it's bombing out at the GPIO make stage. I get this...

No rule to make target '/usr/local/lib/WiringPi.a' needed by 'gpio'. Stop.

I'm trying to install on August Raspbian, following these instructions

Any ideas?
Alex Eames RasPi.TV, RasP.iO

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

Re: WiringPython - WiringPi for Python

Tue Sep 25, 2012 1:35 pm

Like I said, using the pip installation method worked for me with the latest raspbian distro.
http://www.raspberrypi.org/phpBB3/viewt ... 00#p162668

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

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

Re: WiringPython - WiringPi for Python

Tue Sep 25, 2012 1:47 pm

Thanks Texy. I saw that but didn't understand what it did. Since I was two commands away from finishing...

What does pip do? Does that replace the entire compile and install process?

I think I've got wiringpi installed OK it's the GPIO bit that failed. So thinking about it, I should still be able to use wiringpi if I run the python scripts as sudo, right?
Alex Eames RasPi.TV, RasP.iO

BlackJack
Posts: 288
Joined: Sat Aug 04, 2012 8:28 am
Contact: Website

Re: WiringPython - WiringPi for Python

Wed Sep 26, 2012 8:25 am

@alexeames: ``pip`` is not replacing compiling and installing — it is doing exactly that.

Code: Select all

while not self.asleep():
    sheep += 1

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

Re: WiringPython - WiringPi for Python

Tue Oct 02, 2012 2:42 pm

OK I've got time to play with this now my Raspberry Jam demo is out of the way.

How would I use wiringpython to read input FROM the serial port?
Serial:
serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID
wiringpi.serialPuts(serial,"hello")
wiringpi.serialClose(serial) // Pass in ID
This shows us how to open and close the port and how to print to it (I think), but what about the opposite?

Suppose, purely hypothetically of course, that I'm running a tmp36 temperature sensor on a Gertboard using the Atmega to ADC and convert to a temperature reading which it outputs to serial.

How can I read this signal into a Python program? Is there a serialGets function to go with serialPuts? Or have I missed the point. :lol:
Alex Eames RasPi.TV, RasP.iO

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

Re: WiringPython - WiringPi for Python

Tue Oct 02, 2012 10:00 pm

Perhaps I have missed the point? I've managed to do what I wanted (read the serial port) with pyserial. :lol:
Alex Eames RasPi.TV, RasP.iO

bitbitbit
Posts: 30
Joined: Thu Aug 30, 2012 3:18 am

Re: WiringPython - WiringPi for Python

Tue Oct 16, 2012 8:19 am

Hi.....

I installed wiringpi (the original one in C) and it worked perfectly

Now, I want to try the wiringpi in python....installed it and ran it successfully....

Wrote a very simple code for testing::

Code: Select all

#!/usr/bin/python
import wiringpi
from time import sleep
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
io.pinMode(13,io.OUTPUT)  # Setup pin 18 (GPIO1)
while True:
    io.digitalWrite(13,io.HIGH)  # Turn on light
    sleep(2)
    io.digitalWrite(13,io.LOW)  # Turn off
    sleep(2)

but nothing happens?? The LED does not blink.... how can I debug the problem? Very much appreciated if somebody could point me to the right direction....as there was no error code coming out and I don't know what went wrong.....

I tried to plug to other pins (if i did the connection wrongly)...and I also tried my LED with the 3.3V, no problem with the LED.....also tried to open python in terminal and type the code line by line, still no results......

Thanks!

User avatar
Grumpy Mike
Posts: 998
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District
Contact: Website

Re: WiringPython - WiringPi for Python

Tue Oct 16, 2012 9:51 am

Change this line to:-

Code: Select all

io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)
Does the program just quit on this line?

If so I don't think it has installed correctly.

bitbitbit
Posts: 30
Joined: Thu Aug 30, 2012 3:18 am

Re: WiringPython - WiringPi for Python

Tue Oct 16, 2012 9:58 am

Grumpy Mike wrote:Change this line to:-

Code: Select all

io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)
Does the program just quit on this line?

If so I don't think it has installed correctly.
Nope....it didn't quit..... :roll:

User avatar
Grumpy Mike
Posts: 998
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District
Contact: Website

Re: WiringPython - WiringPi for Python

Tue Oct 16, 2012 1:14 pm

Yes it looks like stuff that used to work now doesn't.

The joy of the snakes and ladders game that is Linux. :cry:

Off to load the latest version of Rasbain and start from square one again.

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

Re: WiringPython - WiringPi for Python

Tue Oct 16, 2012 2:10 pm

The method I use for my LCD's is slightly different, but still uses wiringpi for python. Try this :

Code: Select all

#!/usr/bin/python
import wiringpi
from time import sleep

LED  = 1  # gpio pin 12 = wiringpi no. 1

wiringpi.wiringPiSetup()
wiringpi.pinMode(LED, 1) # output
while True:
    wiringpi.digitalWrite(LED, 1)  # Turn on light
    sleep(2)
    wiringpi.digitalWrite(LED, 0)  # Turn off
    sleep(2)
...you may need to format it correctly for python, this is just hand cut & paste.

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

User avatar
Grumpy Mike
Posts: 998
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District
Contact: Website

Re: WiringPython - WiringPi for Python

Tue Oct 16, 2012 4:26 pm

Code: Select all

LED  = 1  # gpio pin 12 = wiringpi no. 1
There isn't a GPIO pin 12 on the Pi?

Do you mean physical pin 12 or WiringPi pin 12 which is GPIO pin 10

Or perhaps you mean Physical pin 12 which is GPIO pin 18.

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

Re: WiringPython - WiringPi for Python

Tue Oct 16, 2012 4:35 pm

I mean physical pin 12, yes that's bcm GPIO18, aka wiringpi pi 1, as shown here :
https://projects.drogon.net/raspberry-pi/wiringpi/pins/

Cheers,
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

Return to “Python”