Adafruit GPIO Library for CHIP


Since I’m planning on using some of the Adafruit Python libraries for my CHIP project, I decided to add support for the CHIP in their GPIO library.

I forked their repo and added support for GPIO (CSI0-7 and XIOP0-7) and I2C; SPI and PWM are not. I don’t have any devices that use SPI or PWM, nor do they show up in CHIPs Debian GUI image.

Edge detection and GPIO callbacks are not implemented at this moment.

I verified that the GPIO functions work for setup, input, and cleanup. I don’t have anything hooked up to write too, but it should work. I haven’t tested the I2C code, but all I did was add support for getting the default I2C bus.

Repo is here:

You also need to install CHIP_IO:

I plan on submitting a pull request to get this merged into Adafruits’ repo.

Scripts created with this library that control the GPIO pins need to be run with root permissions.

  • GPIO: Total control of GPIO through CHIP_IO
  • I2C: Control of i2c devices through python-smbus (in the future it will be with Adafruits native python i2c library)
    The default I2C bus is now i2c-2 as i2c-1 was removed in OS 1.1 (4.4 Kernel)
  • SPI: Control of SPI devices through python-spidev (with appropriate DTB setup)
  • PWM: Control of the Hardware PWM (with appropriate DTB setup) and Software PWM through CHIP_IO

Newbie to CHIP, oldie to RPi Zero. GPIO question
[SOLVED] Problems with GPIO
Some questions about GPIO and C.H.I.P. console emulators
My webcam finally works with old built-root kernel customization, Thanks JKW
Can I make a GPIO controlled video player with C.H.I.P. SDK?
Installing LIRC on C.H.I.P
Programming with GPIO
CHIP IO: Library for interfacing with all the things (v0.7.1)
I wrote a GPIO "library" for Python you guys can use!
Will windows app running under wine on CHIP be able to use the pin inputs and outputs?
Starting point for a complete newb?
Help Connecting 4 digit 7 segment via i2c
Custom Weather Station with Adafruit.IO
Walkthrough for Beginners! Adafruit Sensors+CHIP GPIO
C.h.i.p nixie type clock VFD
C.H.I.P. based S0 logger for digital power meters
Second serial port
GPIO to User Input
Looking for some advice
How do i create an aplicación that is able to use chip i/o

@xtacocorex Great idea and effort! I am a bit curious as to why you set C.H.I.P. to platform number 5 instead of 4 - is it the belief in some cultures that 4 is an unlucky number? Yeah, some of us actually do read all of the code Out There :grinning:


 CHIP             = 5


@Jim_Manley I was wondering if I’d get a comment about this. :slight_smile:

There is currently a pull request in waiting at Adafruits’s repo that adds the Intel Edison as number 4, I didn’t want to cause a merge issue in the future.

Thanks for looking over the code, I appreciate the second set of eyes on it for sanity sake.


Ah, of course, good ol’ Thomas Edison trying to usurp the limelight from the grave (pun fully intended, since he ran the lab that developed the first long-lived incandescent electric light) … with a little help from the 800-pound marketing gorilla, Intel :wink:

That’s interesting that they have a pull request in for an update to the Python GPIO library for the Edison - I wonder what took them so long, given how many engineers work there and the supposed educational purpose of the Edison product line.

As for as a second set of eyes, they’re winding up crossed from reading so much code, and I’m not sure whether anything I had to say would be considered sane by some :stuck_out_tongue_winking_eye:

I will be trying the GPIO library out, though, as I’m using C.H.I.P.s to teach computing principles to kids to whom I will be giving them away given their low cost … once they’re available in volume (heavy sigh).


Thank you for this!

Did you have any issues installing? I did the instructions from the readme, and Python is not finding the module. See below. Perhaps I need to change a location in easy-install.pth?

sudo apt-get update
sudo apt-get install build-essential python-pip python-dev python-smbus git
git clone
cd Adafruit_Python_GPIO
sudo python install

sudo python -c "import Adafruit_BBIO.GPIO as GPIO; print GPIO"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named Adafruit_BBIO.GPIO


@aninternetof you have a typo in your command, it should be:

sudo python -c "import Adafruit_GPIO.GPIO as GPIO; print GPIO"


@xtacocorex, thank you! That fixed it. I had pulled the name from Adafruit’s tutorial.

Do you also have a sec for a quick usage example? The code below is giving me “AttributeError: ‘module’ object has no attribute ‘start’”

import Adafruit_GPIO.PWM as PWM
import time

print "Starting motor"
PWM.start("XIOP1", 50);

print "Sleeping"

print "Stopping motor"


@xtacocorex. Oh, I see in your initial post that PWM is not implemented.


But, clearly I’m still importing incorrectly, because the following code gives me “AttributeError: ‘module’ object has no attribute ‘setup’”

import Adafruit_GPIO.GPIO as GPIO

GPIO.setup("XIOP1", GPIO.OUT);
print "setting GPIO"



You need to create a CHIP GPIO object:

gpio = GPIO.CHIPGPIOAdapter()
print "setting GPIO"

Or you could do the following which auto-detects the type of computer:

gpio = GPIO.get_platform_gpio()
print "setting GPIO"

I wasn’t able to fully test the GPIO portion of library when I ported it, so there may be bugs. I’m currently away from all of my gear as I’m on work travel at the moment so I can’t do any live testing.


Dude thx for great work, but we need spi, for spi tft’s


Thank you, thank you. Looking through the code, I see the structure now: Adafruit_GPIO imports Adafruit_BBIO if the board happens to be a Beaglebone Black.


@pyro0139 I was searching these forums looking for a way to enable spi in the Debian+GUI install on the CHIP, but I wasn’t successful. If you know if a guide in the forums that enables SPI without a kernel update, let me know. I plan on building a custom kernel soon, so if it’s something that has to be built in, I’ll try to add it and then add support for SPI in the library.

I have a feeling PWM will be a kernel update too…


Awesome work! @xtacocorex


I added PWM, I think. I have no way to test currently and I’m not sure it’s fully supported in Debian for the CHIP at the moment. If someone has a buildroot OS installed that has working PWM can you please test?

I’m assuming the PWM stuff in sysfs is


I also looked over the SPI code and there are no hardware specifics for either the RPi or Beagleboard Black; it uses the Python spidev module. This may work on CHIPs that have proper SPI support. For those looking to use this with SPI, I would say try it out and if it doesn’t work, it’s most likely the computer not being setup to deal with SPI (Debian).


Great work, haven’t tested yet but I’m hoping to do it tomorrow. Did a quick review and looks good, saw an astray print on but looks :thumbsup:


Thanks for the heads up! I thought I had removed all of my debug print statements. Fix pushed up to the repo.


Thanks for this! I can confirm that this simple example works (updated for more recent version of the library:

import time

# Pin configuration.
pin = "XIO-P0"
# Setup input for pin

# Poll the pin in a loop
while True:
    # read the pin every half a second
    btn = GPIO.input(pin)
    print btn

except KeyboardInterrupt:
GPIO.cleanup()       # clean up GPIO on CTRL+C exit
GPIO.cleanup()           # clean up GPIO on normal exit


@pnyboer Thanks!

I think I’m going to port over the Beaglebone Black GPIO library (which is itself a port of RPi.GPIO) to the CHIP. That should bring about the edge detection support.



This library now requires CHIP_IO, which can be found here:

@pnyboer: The CHIP_IO requirement allows for event_detection, I haven’t tested it, but I ported the code from the Beaglebone Black, so it should work.