0

I'm using the Raspberry Pi for a little project but I would like to program on windows and then later transfer the code onto the Pi. Is there any way to use the RPi.GPIO library on windows? I am using Python to code in

2 Answers2

0

I work remote with VisualStudio2017 on my raspberry in C++. Including the use of GPIOs. Remote debugging is also possible. VisualStudio is also capable to programm in python.

I thought it should be possible that someone has it already done. Then i found these links:

https://learn.microsoft.com/en-us/visualstudio/python/debugging-cross-platform-remote

Importing RPi.GPIO into a Python Project within Visual Studio

Until now it seems to work only if you didn't use Pi only libs.

Another soution might be to edit the files via ssh and run them direct on the pi. There are many programms for this. I use cyberduck and sublime text. To run the programms use putty.

Christoph
  • 1
  • 1
  • 4
0

Ok....this is an old thread but I hit this issue recently when learning python and I came up with a reasonable workaround.

I've got a project structure similar to this;

helloworld
├── main.py
├── common
│   ├── foo.py
│   ├── bar.py
│   └── __init__.py
├── rpi
│   ├── __init__.py
│   └── gpio_proxy.py

I've created my own rpi package with a custom gpio module within it. This gpio facade then attempts to import RPi.GPIO and falls back to default behavior if it can't.

(I've only stubbed out the methods & props that I needed, you'll probably need to add more)

_rpiLoaded = True

try:
    import RPi.GPIO as GPIO
except:
    _rpiLoaded = False

class GPIOProxy():
    BCM = GPIO.BCM if _rpiLoaded else 'BCM'

    HIGH = GPIO.HIGH if _rpiLoaded else 'HIGH'
    LOW = GPIO.LOW if _rpiLoaded else 'LOW'

    IN = GPIO.IN if _rpiLoaded else 'IN'
    OUT = GPIO.OUT if _rpiLoaded else 'OUT'

    FALLING = GPIO.FALLING if _rpiLoaded else 'FALLING'
    RISING = GPIO.RISING if _rpiLoaded else 'RISING'
    BOTH = GPIO.BOTH if _rpiLoaded else 'BOTH'

    PUD_UP = GPIO.PUD_UP if _rpiLoaded else 'PUD_UP'
    PUD_DOWN = GPIO.PUD_DOWN if _rpiLoaded else 'PUD_DOWN'

    def setmode(*args, **kwargs):
        if _rpiLoaded:
            GPIO.setmode(*args, **kwargs)
        else:
            pass

    def setwarnings(*args, **kwargs):
        if _rpiLoaded:
            GPIO.setwarnings(*args, **kwargs)
        else:
            pass

    def setup(*args, **kwargs):
        if _rpiLoaded:
            GPIO.setup(*args, **kwargs)
        else:
            pass

    def output(*args, **kwargs):
        if _rpiLoaded:
            GPIO.output(*args, **kwargs)
        else:
            pass

    def add_event_detect(*args, **kwargs):
        if _rpiLoaded:
            GPIO.add_event_detect(*args, **kwargs)
        else:
            pass

Then in the rest of the project, you can import your facade and use normally, obviously, you won't get any of the GPIO behavior....but at least it'll hang together and you can unit test it all.

What I haven't accounted for; when the code is running on an RPi but the RPi.GPIO library isn't installed then this solution will act as it would when being run on windows and not actually do anything. Not sure if it's an issue though if your project is installing all of its dependencies prior to running =]

jrwood
  • 11
  • 2