cscuilla
Posts: 58
Joined: Tue Apr 26, 2016 6:35 pm

Adafruit Python library and basic python structure help

Wed Aug 02, 2017 3:27 pm

I have a script ~/scripts/pins.py which controls some GPIO pins using RPi.GPIO

I found an oled display to add to my project which I'm connecting w/ i2c. I found a python library from adafruit..
https://github.com/adafruit/Adafruit_Python_SSD1306

I can run the examples from ~/Adafruit_Python_SSD1306/examples and it works.

Now, I'd like to write to the display from my original ~/scripts/pins.py script..
- I tried to copy the ONLY the "Adafruit_SSD1306" folder into my ~/scripts folder.
- I get the error that Adafruit GPIO is set to a differnet mode (I use Board mode)
- I found the following lines..

Code: Select all

  # Default to platform GPIO if not provided.
 self._gpio = gpio
 if self._gpio is None:
       self._gpio = GPIO.get_platform_gpio()
- I can't figure out where the GPIO.get_platform_gpio() function lives. ( where the Adafruit library is setting the GPIO mode at)??
- I see this "import Adafruit_GPIO as GPIO" but cannot find the script anywhere to adjust/make changes. Is it downloading it online somewhere?


If I comment out the lines above the display works with my script. Does this mean w/ i2c that it's not really using the GPIO?

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Adafruit Python library and basic python structure help

Wed Aug 02, 2017 4:00 pm

The Adafruit_Python_GPIO library can be found here.

Installing the Adafruit_Python_SSD1306 library should install the GPIO library by default but I'm guessing you didn't install it, just copied and pasted.
Installing python libraries places them in a common location for all python scripts and is commonly controlled via the setup.py file that comes with many libraries.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

cscuilla
Posts: 58
Joined: Tue Apr 26, 2016 6:35 pm

Re: Adafruit Python library and basic python structure help

Wed Aug 02, 2017 4:21 pm

Actually, I did install it using sudo python setup.py install. I get this folder afterwards..
Adafruit_SSD1306.egg-info ... which has
PKG-INFO, SOURCES.txt, dependency_links.txt, requires.txt, top_level.txt

dependency_links.txt has this..
https://github.com/adafruit/Adafruit_Py ... GPIO-0.6.5

I cant find the file anywhere?? I think it is finding it somehwere because if I uncomment the lines i get the error so it's finding Adafruit_GPIO somewhere.

pcmanbob
Posts: 9464
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Adafruit Python library and basic python structure help

Wed Aug 02, 2017 7:58 pm

Hi

If you are getting this error "- I get the error that Adafruit GPIO is set to a differnet mode (I use Board mode)"
then why don't you change your script so that it uses BCM mode then it will match the adafruit library you are importing.

I have often found when working with imported libraries that you have to adapt to the GPIO mode they are using.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”