maurice1
Posts: 37
Joined: Tue Mar 05, 2013 8:55 am
Location: Dublin

Using both python and wiringpi

Mon Jun 15, 2015 4:06 pm

I have used python on my rpi for:
monitoring my house alarm via MCP3008 to send sms
DS18B20 Temp graphs by anita2r
water meter
Elec meters
switching via 8 relay board and MCP23017

However I want to use 433mhz Maplin remote socket, I tried Raspberry-strogonoff, which insists using wiringpi. I find that wiringpi upsets my python scripts that I have running.

Is it possible to install wiringpi to only look at one GPIO for strogonoff and to leave all the other GPIOs intact using python.

Alternatively is there a python raspberry-strogonoff that doesn't require wiringpi
Thanks
maurice

User avatar
paddyg
Posts: 2360
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Using both python and wiringpi

Tue Jun 16, 2015 12:14 pm

It only looks to use wiringpi in one place and I wouldn't have thought it would be hard to do that using different GPIO library... But would other libraries not conflict also? Are all your different things running as different programs and initializing the GPIO themselves?
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

maurice1
Posts: 37
Joined: Tue Mar 05, 2013 8:55 am
Location: Dublin

Re: Using both python and wiringpi

Tue Jun 16, 2015 1:48 pm

Thanks Paddy for your reply.
Are all your different things running as different programs and initializing the GPIO themselves? -- Yes, all my scripts use "import RPi.GPIO as GPIO".

They all work on different GPIO, MCP23017, MCP3008 pins and they don't seem to conflict with each other.
I tried raspberry-strogonanoff including installing wiringpi and my existing programmes wouldn't work afterwards, yet they were working before wiringi.

I tried using raspberry-strogonanoff alone with nothing else on my pi and it worked fine.

If I install wiringpi and then start my other python scripts, will python will take back use of its RPi.GPIOs and leave the other GPIOs to wiringpi ?

User avatar
paddyg
Posts: 2360
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Using both python and wiringpi

Tue Jun 16, 2015 3:10 pm

I don't know if there's some non-obvious reason why strogonanoff needs to use wiringpi but after a quick look I would have thought you could modify (make a copy first) the WiringPin class, swapping wiringpi functions for RPi.GPIO functions as per your other programs. NB you will need to make sure about pin numbering systems etc.

Code: Select all

import wiringpi ######## <<<<<<< here

wiringpi.wiringPiSetup() ######## <<<<<<< and here

class WiringPin:

    def __init__(self, gpio_number, direction="out"):
        self.gpio_number = gpio_number
        self.direction = direction

    def export(self):
        wiringpi.pinMode(self.gpio_number,
            wiringpi.OUTPUT if self.direction == "out" else wiringpi.INPUT) ######## <<<<<<< and here
        return self

    def set_value(self, value):
        wiringpi.digitalWrite(self.gpio_number, value) ######## <<<<<<< and here

    def get_value(self):
        return wiringpi.digitalRead(self.gpio_number) ######## <<<<<<< and here

    def unexport(self):
        pass # for now
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”