HeCoding
Posts: 1
Joined: Tue Apr 23, 2019 10:19 am

Use RPi.GPIO Library on Eclipse (mac)

Tue Apr 23, 2019 10:43 am

Hi everyone!

I've got a Project thesis (Raspberry Pi -> Python) from school. I started using Eclipse (on Mac) and installed PyDev on it.
So now I have the problem, that I havn't got the Library «RPi.GPIO» on Eclipse...
Is it possible to install the RPi.GPIO Library on Eclipse?

(I have a Raspberry Pi and i could use a USB-stick to get the data from the Raspberry Pi to my Computer)

Thank you!

User avatar
ben_nuttall
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 231
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridge, UK
Contact: Website

Re: Use RPi.GPIO Library on Eclipse (mac)

Tue Apr 23, 2019 2:57 pm

You could use GPIO Zero's remote GPIO feature: https://gpiozero.readthedocs.io/en/stab ... _gpio.html
Community Manager - Raspberry Pi Foundation
Author of GPIO Zero and creator of piwheels

ghp
Posts: 1419
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Use RPi.GPIO Library on Eclipse (mac)

Tue Apr 23, 2019 6:27 pm

Hello, welcome to the world of cross-deleveopment. Depending on what you want to achieve, there are different strategies:
(A) develop on computer, transfer to pi and test on pi. Run on pi.
(B) develop on computer, test on computer using mockup, transfer to pi and test on pi. Run on pi.
(C) develop on computer, test on computer using connection to a pi's GPIO, transfer to pi and test on pi. Run on pi.
(D) develop on computer, test on computer using connection to a pi's GPIO, run on computer with a pi's GPIO.

(A) is very simple. Just write your code on computer and accept that eclipse is showing errors that libs are not found. Transfer to pi and test there. As python code does not need to be compiled, this is easy. When problems found, correct on computer and transfer again. A tedious process, but when you automate the transfer and execution within eclipse, it is quite straightforward.

(B) I usually develop in eclipse on a laptop. The hardware access is in one class, which has two implementations: one for the pi using GPIO, the other is for the development environment.

Code: Select all

try:
    import RPi.GPIO as gpio
    mockup = False
except Exception:
    mockup = True

class HardwareMockup:
    """Mockup class"""
    def motor_on(self):
        print("motor_on")
        
class HardwareGPIO:
    MOTOR_PIN = 18
    def __init__(self):
        gpio.setmode(gpio.BCM)
        gpio.setup(self.MOTOR_PIN, gpio.OUT) 

    def motor_on(self):
        gpio.output(self.MOTOR_PIN, True)
        
if mockup:         
    hardware =  HardwareMockup()
else:
    hardware =  HardwareGPIO()
    
hardware.motor_on()
Unfortunately, the idea of 'interfaces' and 'implementing classes' is not very good in python. But you see the idea: classes with same methods but completely different internal implementation.
For inputs, it is getting more complicated.

(C) when on computer the programm should be fully testable, then use an access method which is both available on computer on pi. pigpiod allows remote access. This runs same way on both remote and local environment. Possibly GPIO Zero has the same features.

(D) this is less cross development but remote execution. Remote access to a pi is needed. Either use low level GPIO access on a pi, or work with a small layer of code on the pi which allows to execute fast thinks on pi but control is performed by remote computer.

Return to “Python”