Giter VIP home page Giter VIP logo

adafruit_python_gpio's Introduction

!!!Deprecation Warning!!!

This library has been deprecated in favor of our python3 Blinka library. We have replaced all of the libraries that use this repo with CircuitPython libraries that are Python3 compatible, and support a wide variety of single board/linux computers!

Visit https://circuitpython.org/blinka for more information

CircuitPython has support for almost 200 different drivers, and a as well as FT232H support for Mac/Win/Linux!

!!!Deprecation Warning!!!

Adafruit Python GPIO Library

Library to provide a cross-platform GPIO interface on the Raspberry Pi and Beaglebone Black using the RPi.GPIO and Adafruit_BBIO libraries.

The library is currently in an early stage, but you can see how its used in the Adafruit Nokia LCD library to write Python code that is easily portable between the Raspberry Pi and Beaglebone Black.

Note that you typically don't need to install this library directly as other libraries will depend on it in their setup and automatically install it. However if you do need to manually install do so by running these commands:

  • On a Debian-based Linux like Raspbian, Ubuntu, etc. in a terminal execute:

    sudo apt-get update
    sudo apt-get install build-essential python-pip python-dev python-smbus git
    git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
    cd Adafruit_Python_GPIO
    sudo python setup.py install
    
  • On Mac OSX, first install PIP by downloading the python script here and execute it with python get-pip.py in a terminal, then install the git source control system. Then in a terminal execute:

    git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
    cd Adafruit_Python_GPIO
    sudo python setup.py install
    
  • On Windows, first install the latest Python 2.7 version, then install PIP by downloading the python script here and execute it with python get-pip.py in a terminal, and finally install the git source control system. Then in a git bash prompt execute:

    git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
    cd Adafruit_Python_GPIO
    python setup.py install
    

Contributing

For information on contributing, such as how to run tests, etc. please see the project wiki on GitHub.

adafruit_python_gpio's People

Contributors

abhinuvpitale avatar andysmithfal avatar asomov avatar ehooo avatar gizmohd avatar guillier avatar ladyada avatar lsellens avatar matthw avatar mrnuke avatar pelado-mat avatar tdicola avatar vestom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_python_gpio's Issues

TypeError:ftdi.write_data() function takes exactly 2 arguments (3 given)

I met this error ever since I installed libftdi version 1.3 by homebrew,while evertying works fine in libftdi version 1.2.

By looking in to the libftdi python wrapper,the ftdi.write_data() changed from :
def write_data(ftdi, buf, size):
to:
def write_data(context,buf)

This change caused this error.

I tried to modify adafruit python gpio library to match the new libftdi by simply change code to:
FT232H.py,line 189:
ret = ftdi.write_data(self._ctx, string)

But it still failed in line 194 for some error code like "usb bulk write failure"
Anyone got any idea?

Incorrect detection of Raspberry Pi version

Platform.py detects Raspberry Pi version on Kernel 4.9 incorrectly. It assumes BCM2708 as Pi 1, BCM2709 as Pi 2 and BCM2835 as Pi 3. In contrast BCM2835 is Pi 1, BCM2836 is Pi 2 and BCM2837 is Pi 3 on kernel 4.9.

Wrong Platform detection (Raspberry Pi Linux kernel 4.9.13)

I have the following Traceback :

File "/usr/lib/python3.6/site-packages/Adafruit_SSD1306-1.5.0-py3.6.egg/Adafruit_SSD1306/SSD1306.py", line 242, in __init__
  File "/usr/lib/python3.6/site-packages/Adafruit_SSD1306-1.5.0-py3.6.egg/Adafruit_SSD1306/SSD1306.py", line 87, in __init__
  File "/usr/lib/python3.6/site-packages/Adafruit_GPIO-1.0.1-py3.6.egg/Adafruit_GPIO/GPIO.py", line 426, in get_platform_gpio
RuntimeError: Could not determine platform.

I look into the source code Adafruit_Python_GPIO/Adafruit_GPIO/Platform.py
You determine the Raspberry pi version from /proc/cpuinfo
PI1 => BCM2708
PI2 => BCM2709
but because I have updated my arch linux distrib, now I have on my raspberry Pi 1 Version B:

$ cat /proc/cpuinfo 
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 697.95
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2835
Revision	: 000f
Serial		: 0000000021596408
$ uname -a
Linux alarmpi 4.9.13-3-ARCH #1 SMP Sat Mar 4 01:28:29 UTC 2017 armv6l GNU/Linux

With my other raspberry Pi 1 Version B on Raspbian :

$ uname -a
Linux rp1 4.1.15+ #831 Tue Jan 19 18:36:09 GMT 2016 armv6l GNU/Linux
$ cat /proc/cpuinfo
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 2.00
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2708
Revision	: 000f
Serial		: 000000008c97cdf4

So I suggest you to add the following check:
PI1 => BCM2708 or BCM2835

Unable to read user registry using readRaw8 with Adafruit_GPIO.FT232H i2c connection

Machine Specs: Ubuntu 18.04 Desktop on an i7 based workstation.

Background: I'm using an Adafruit HTU21D-F Humidity/Temp sensor connected to a USB pluggable FT232H breakout board (C232HM-DDHSL‌-0 USB2.0/I2C cable). Adafruit GPIO has support for FT232H (https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/FT232H.py)

Question: I found a smbus script to retrieve data from my sensor; however, would much prefer to use the Adafruit_GPIO.FT232H module. My issue is when trying to read user registry I get an error saying RuntimeError: Failed to find expected I2C ACK!. Anybody know why that is? How would I fix it? I have already added a pull-up resistor.

Code

import time
from Adafruit_GPIO import FT232H

HTU21DF_ADDRESS        = 0x40
HTU21DF_READTEMPCMD    = 0xE3
HTU21DF_READHUMCMD     = 0xE5
HTU21DF_READUSERREGCMD = 0xE7
HTU21DF_SOFTRESETCMD   = 0xFE

# Temporarily disable FTDI serial drivers.
FT232H.use_FT232H()
# Find the first FT232H device
ft232h=FT232H.FT232H()
# Create an I2C device at address 0x70.
i2c = FT232H.I2CDevice(ft232h, HTU21DF_ADDRESS)
print(i2c.ping())

# Soft Reset 
i2c.writeRaw8(HTU21DF_SOFTRESETCMD)
time.sleep(0.015)

# read_user_reg
i2c.writeRaw8(HTU21DF_READUSERREGCMD)
print(i2c.readRaw8()) # Error occurs on this line

Execution & Full error

ubuntu@sonoma:~$ sudo python3 setup_adafruit_FT232H.py 
[sudo] password for ubuntu: 
True
Traceback (most recent call last):
  File "setup_adafruit_FT232H.py", line 27, in <module>
    print(i2c.readRaw8())
  File "/usr/local/lib/python3.6/dist-packages/Adafruit_GPIO-1.0.3-py3.6.egg/Adafruit_GPIO/FT232H.py", line 743, in readRaw8
    self._verify_acks(response[:-1])
  File "/usr/local/lib/python3.6/dist-packages/Adafruit_GPIO-1.0.3-py3.6.egg/Adafruit_GPIO/FT232H.py", line 647, in _verify_acks
    raise RuntimeError('Failed to find expected I2C ACK!')
RuntimeError: Failed to find expected I2C ACK!```

RE: Using Your Software and Changing It/Seth

Hello,

My name is Seth. I understand the fact that I can change this software to suit my needs but I wanted permission. I see the Adafruit_I2C.py library has changed some to Adafruit_GPIO.I2C, right?

Anyway...

I wanted to use this software and some Adafruit_BBIO version 1.0.3 instead of the newer, 1.0.10 version to make my Motor Bridge Cape work. Seeed-Studio produced this Cape in 2015. I have it working on two other boards but my updated, expansive board, the BBG, cannot seem to run the software with or without errors.

So...

I just wanted permission from whomever typed up all this software.

Seth

P.S. I know I can use it since it is in the public domain and has a license on it. I would rather have permission. I have been dealing w/ a person on the Forums at Adafruit.com and he/she has been very helpful but this dang board, the BBG, and the Motor Bridge Cape are not working w/ the 4.9.x kernel and the 01.28.2018 image from bbb.io/latest-images. So, I thought I would reach out.

Add GPIO cleanup function.

Now that there's event detection logic we should add a cleanup function to the GPIO base class and have it call the appropriate Pi, BBB, etc. library cleanup. See #14

Building community

a few steps can help to build a community for this project:

  1. How to contact developers ? Is there a maling list ? (Google should help to make it a reference documentation in the future.)
  2. Description of how to develop code should be very useful. How to launch tests (I got an error: "ImportError: No module named mock") ? Do you use remote development (PyCharm Pro)
  3. wiki can help to share and support the documentation for usage and developmenbt

Not work for python3 with too many problems...

First:

Python 3.5.2 (default, Jul 28 2016, 18:18:57) 
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import Adafruit_GPIO as GPIO
>>> import Adafruit_GPIO.FT232H as FT232H
>>> FT232H.use_FT232H()
>>> ft232h = FT232H.FT232H()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 165, in __init__
    self._mpsse_sync()
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 249, in _mpsse_sync
    data = self._poll_read(2)
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 229, in _poll_read
    raise RuntimeError('Timeout while polling ftdi_read_data for {0} bytes!'.format(expected))
RuntimeError: Timeout while polling ftdi_read_data for 2 bytes!
>>> 

after comment out this line: self._mpsse_sync():

Python 3.5.2 (default, Jul 28 2016, 18:18:57) 
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_GPIO as GPIO
>>> import Adafruit_GPIO.FT232H as FT232H
>>> FT232H.use_FT232H()
>>> ft232h = FT232H.FT232H()
>>> 
>>> ft232h.setup(8, GPIO.OUT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 341, in setup
    self.mpsse_write_gpio()
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 313, in mpsse_write_gpio
    self._write(self.mpsse_gpio())
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 309, in mpsse_gpio
    return str(bytearray((0x80, level_low, dir_low, 0x82, level_high, dir_high)))
TypeError: an integer is required
>>> 

after remove all chr in function mpsse_gpio:

Python 3.5.2 (default, Jul 28 2016, 18:18:57) 
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_GPIO as GPIO
>>> import Adafruit_GPIO.FT232H as FT232H
>>> FT232H.use_FT232H()
>>> ft232h = FT232H.FT232H()
>>> 
>>> ft232h.setup(8, GPIO.OUT)
>>> ft232h.output(8, GPIO.HIGH)
>>> ft232h.output(8, GPIO.LOW)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 368, in output
    self.mpsse_write_gpio()
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 313, in mpsse_write_gpio
    self._write(self.mpsse_gpio())
  File "/mnt/TT/SA/tools/Adafruit_Python_GPIO/Adafruit_GPIO/FT232H.py", line 194, in _write
    raise RuntimeError('ftdi_write_data failed with error {0}: {1}'.format(ret, ftdi.get_error_string(self._ctx)))
RuntimeError: ftdi_write_data failed with error -1: usb bulk write failed
>>> 

Adafruit_Python_GPIO version:

commit 060f6d6782768b1f6a4713f369db2740e79ec61e
Author: Tony DiCola <[email protected]>
Date:   Mon Mar 6 22:44:49 2017 -0800

    Minor bump for Pi 3 on 4.9.x kernel detection.

libftdi vertion:
libftdi1-1.2

python version:
Python 3.6.0 Python 3.5.2

no problem with Python 2.7.12

Adafruit_I2C.reverseByteOrder() in Adafruit_I2C.py is broken

@tdicola: this issue for Adafruit_I2C.reverseByteOrder() in adafruit-beaglebone-io-python was raised by @phrogger:
adafruit/adafruit-beaglebone-io-python#82

The method Adafruit_I2C.reverseByteOrder() in Adafruit_I2C.py does not work.

It tries to automatically detect the presence of a 16 bit or 32 bit value by detecting the first byte containing non-zero bits. This fails whenever there are valid leading bytes containing zeros.

@jwcooper commented in adafruit-beaglebone-io-python/Adafruit_I2C.py:

Adafruit_I2C.py is essentially a fork of the Adafruit Raspberry Pi I2C module. Any pull requests for this module should be directed to the following, and I can pull them. I'd rather not deviate from the original: https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/tree/master/Adafruit_I2C

However, Adafruit_I2C now resides in this repo. reverseByteOrder() is located in Adafruit_GPIO/I2C.py

nvidia Jetson TX1 support

[proposed Label] enhancement

I am running this library on a TX1 along with the Adafruit_Python_ADS1x15 library in order to use the ADS1015 chip through the built in I2C port.

I modified the I2C.py file, replaced the raise on line 55 with a return 0 and it works, which suggests that the default I2C bus on the TX1 board is 0 (like the original raspberry pi).

If support for the TX1 where added to the platform_detect() function then the I2C bus could be dynamically set here.

FTH232H.py has import ftdi1 as ftdi

There seems to be no such library as ftdi1 that FTH232H.py is trying to import.
pip doesn't seem to know about it.

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.):
    macOS

  • Python version (run python -version or python3 -version):
    2.7.10

  • Error message you are receiving, including any Python exception traces:
    Traceback (most recent call last):
    File "./ft232h.py", line 4, in
    from Adafruit_GPIO import (
    File "/Users/myusername/Library/Python/2.7/lib/python/site-packages/Adafruit_GPIO/FT232H.py", line 30, in
    import ftdi1 as ftdi
    ImportError: No module named ftdi1

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):
    Try to import like
    from Adafruit_GPIO import FT232H

Adafruit_Python_CharLCD - fails if left running

Using the demo char_lcd_plate.py from Adafruit_Python_CharLCD, if you leave the script running waiting for input i eventually get the following error:
:~/Adafruit_Python_CharLCD/examples $ Press Ctrl-C to quit. Traceback (most recent call last): File "char_lcd_plate.py", line 71, in <module> if lcd.is_pressed(button[0]): File "build/bdist.linux-armv6l/egg/Adafruit_CharLCD/Adafruit_CharLCD.py", line 450, in is_pressed File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/MCP230xx.py", line 95, in input File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/MCP230xx.py", line 103, in input_pins File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/I2C.py", line 129, in readList IOError: [Errno 5] Input/output error

using raspiaban - both wheezy and jessie on raspberry pi B

PCF8574

Dear friends, thanks a lot for porting to python 3. I tried to run the following code:

from Adafruit_GPIO. PCF8574 import PCF8574,OUT
from time import  sleep

expander=PCF8574(address=0x38)
expander.setup(0,OUT)

while True:
    expander.output(0,True)
    sleep(0.5)
    expander.output(0,False)

and caught an exception

Traceback (most recent call last):
  File "/share/rover/trash/PCF8574_test.py", line 6, in <module>
    expander.setup(0,OUT)
  File "/root/rover3/lib/python3.4/site-packages/Adafruit_GPIO-1.0.0-py3.4.egg/Adafruit_GPIO/PCF8574.py", line 68, in setup
  File "/root/rover3/lib/python3.4/site-packages/Adafruit_GPIO-1.0.0-py3.4.egg/Adafruit_GPIO/PCF8574.py", line 71, in setup_pins
AttributeError: 'dict' object has no attribute 'iteritems'

I think this is issue.
pep-0469

init function for MCP230xx assumes part is operating with IOCON.BANK = 0

  • Platform/operating system:
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 8.0 (jessie)
Release:	8.0
Codename:	jessie
  • Python version (run python -version or python3 -version): Python 2.7.9

  • Error message you are receiving, including any Python exception traces: Writes/reads do not work as expected when part was operated in IOCON.BANK=1 mode previously

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):

    1. i2cset -y 1 0x20 0x0A 0x80
    2. use the example char_lcd_plate.py from Adafruit_Python_CharLCD and observe no output

The char_lcd_plate script showcases the issue, but the root of the problem is that the MCP part should be reset to IOCON.BANK=0 before using it. The current script assumes it is in this mode. It would also be a good idea to reset registers to their POR value.

error on windows10 X64 (ver1803)

python 2.7.15 32bit
module ft232h

work on windows 7, just upgrade os to windows10, code and package are the same

Traceback (most recent call last):
File "C:\Users\Fr\Desktop\SW_2-9_SP8T.py", line 10, in
ID_list=FT232H.enumerate_device_serials()
File "build\bdist.win32\egg\Adafruit_GPIO\FT232H.py", line 124, in enumerate_device_serials
ftdi.list_free(device_list)
File "C:\Python27\lib\site-packages\ftdi1.py", line 1055, in list_free
return _ftdi1.list_free(*args)
TypeError: in method 'list_free', argument 1 of type 'struct ftdi_device_list **

Switch to relative import statements

Right now a lot of imports use the absolute name of a module since it was quick and easy and worked. However going forward relative imports are the right way to reference modules inside modules and are supported by later python 2.7 and 3 releases.

I2C readList() function error in device address and missing restart condition

I recently used the I2C readList() function to make a sequential read on AT24C04 EEPROM and got an Non ACK Error.Then I look into the code and I found something wrong in this funciton.

in Line 720 of FT232H.py:

self._i2c_write_bytes([self._address_byte(True), register])

Obviously,it's IMPOSSIBLE to WRITE a value (register) to a READ DEVICE ADDRESS.

I think this function should work just like I2C readU8() funtion except changing the length.

Here below is my modification which works for me:

def readList(self, register, length):
    if length <= 0:
        raise ValueError("Length must be at least 1 byte.")
    self._idle()
    self._transaction_start()
    self._i2c_start()
    #Write to a write addr here
    self._i2c_write_bytes([self._address_byte(False), register])
    self._i2c_stop()
    self._i2c_idle()
    self._i2c_start()
    #And generate a read restart here
    self._i2c_write_bytes([self._address_byte(True)])
    self._i2c_read_bytes(length)
    self._i2c_stop()
    response = self._transaction_end()
    self._verify_acks(response[:-length])
    return response[-length:]

So,can you confirm is this a bug or something I might missed?

Platform.pi_version() regex fails

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): INSERT PLATFORM/OPERATING
    SYSTEM HERE

    rpi 3 running jessie
  • Python version (run python -version or python3 -version): INSERT PYTHON
    VERSION HERE

2.7.9

  • Error message you are receiving, including any Python exception traces: INSERT
    ERROR MESAGE/EXCEPTION TRACES HERE
    *

whenever i run Platform.pi_version(), it returns None, which led me to think that the regex was not parsing the info from /proc/cpuinfo properly. i was able to get it to grab the hardware group properly by changing the regex to this:
Hardware\\t+:\s+(\w+)
When re.match parses cpuinfo it reads in the escaped characters. I am sure there is a more elegant solution but I am not familiar enough with python to parse cpuinfo with the characters unescaped.

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run): LIST REPRO STEPS BELOW

run Platform.pi_version()

Missing installation requirement

If the package python-dev is not installed, the following error will occur error: Setup script exited with error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1.

I think this should be mentioned in the README file.

IO Error when trying to get i2c device on Raspberry Pi B+

I'm having some difficulty connecting to my MCP9808 temperature sensor while using this library.

I had attempted to use the python mcp9808 library https://github.com/adafruit/Adafruit_Python_MCP9808, but kept receiving an IOError from this library. Using the default address specified in that library (https://github.com/adafruit/Adafruit_Python_MCP9808/blob/master/Adafruit_MCP9808/MCP9808.py#L27), I can reproduce these steps in the python console as shown below :

pi@raspberrypi ~ $ python
Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_GPIO.I2C as I2C
>>> address=0x18
>>> I2C.get_i2c_device(address)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/I2C.py", line 66, in get_i2c_device
  File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/I2C.py", line 95, in __init__
IOError: [Errno 2] No such file or directory

My platform info is shown as below :

pi@raspberrypi ~/servos $ python
Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_GPIO.Platform as Platform
>>> Platform.platform_detect()
1
>>> Platform.pi_revision()
2
>>> 

my pi version is

Linux 4.1.7+ armv6l GNU/Linux

My hardware setup is shown below :

20151208_233919
20151208_233908
20151208_233858
20151208_233844

In my boot/config.txt I have added

dtparam=i2c_arm=on

and enabled I2C via raspi-config.

Is there anything that I'm missing, or could it just be faulty hardware?

Beaglebone Black Jessie returns the wrong I2C bus value and cannot communicate on the default bus.

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): BEAGLEBONE BLACK DEBIAN JESSIE [KERNEL VERSION 4.4.16-ti-r38]

  • Python version (run python -version or python3 -version): PYTHON 2.7.9

  • Error message you are receiving, including any Python exception traces:

    import Adafruit_LED_Backpack.SevenSegment as ss
    seg = ss.SevenSegment(address=0x72)
    seg.begin()
    Traceback (most recent call last):
    File "", line 1, in
    File "/usr/local/lib/python2.7/dist-packages/Adafruit_LED_Backpack/HT16K33.py", line 53, in begin
    self._device.writeList(HT16K33_SYSTEM_SETUP | HT16K33_OSCILLATOR, [])
    File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO/I2C.py", line 127, in writeList
    self._bus.write_i2c_block_data(self._address, register, data)
    File "/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO/smbus.py", line 274, in write_i2c_block_data
    self._device.write(data)
    IOError: [Errno 110] Connection timed out

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):
    Try to address anything on I2C using existing module

In the newest version of the kernel for the BBB, the default address on pins P9_19 and P9_20 now addresses i2c-2 instead of i2c-1. This can be mitigated by checking which version of the kernel the is being run on the BBB and returning the appropriate value.

No attribute 'setmode'

Hello,
I 'm testing this lib, but or my code is wrong or can be a bug :)

import Adafruit_GPIO as GPIO
GPIO.setmode(GPIO.BCM)

This code cause error

Traceback (most recent call last):
  File "text.py", line 2, in <module>
    GPIO.setmode(GPIO.BCM)
AttributeError: 'module' object has no attribute 'setmode'

Does someone have idea ?

Regards,

Carlos

ImportError: No module named GPIO

Hi,

I'm a bit puzzled by the meaning of the import in Adafruit_GPIO/init.py which systematically throws an error: ImportError: No module named GPIO

I can think of 3 possible fixes (depending on the original idea behind this import):

  • Removing it completely
  • from Adafruit_GPIO.GPIO import *
  • from Adafruit_GPIO import *

Regards,
François.

I2C library assumes 8-bit registers

Some sensors (like the VL6180x from ST) and larger EEPROMs use 16 bits for their register addresses; the library assumes 8 bits. It would be great if class I2CDevice had a parameter in init for the width of a device's register.

Getting SPI error after Kernel module reload

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.):
    Raspberry Pi with Raspbian operating system Kernel 4.9.24+ #991

  • Python version (run python -version or python3 -version):
    Python 2.7.9

  • Error message you are receiving, including any Python exception traces:
    File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/SPI.py", line 42, in init
    IOError: [Errno 2] No such file or directory

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):

  1. Instantiate display via the Adafruit SSD1306 library.
  2. Load FBTFT kernel modules
  3. Remove FBTFT kernel modules
  4. Reload the spi_bcm2835 kernel module
  5. Try to reinstantiate display via Adafruit SSD1306
  6. Get error message

Wondering if this is a Kernel 4.9 thing? It was working with Kernel 4.4

Local variable 'gpio' shadows self.gpio

Should the implementation of MCP230xxBase#input_pins() be consistent with the local buffers (self.iodir, self.gppu) where the local copy of the self.gpio bytes should be the last known state?

Currently, in input_pins() when gpio is read, the resulting bytes are not stored to self.gpio but instead to a gpio variable with local scope, meaning the read may not have the side-effect of updating the MCP230xxBase object's knowledge of the current GPIO state as some may expect.

no module named 'Adafruit_GPIO' (even though I checked everything)

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspbian GNU/Linux 9 (stretch)

  • Python version (run python -version or python3 -version): python 2.7.13 and 3.5.3

  • Error message you are receiving, including any Python exception traces:
    Traceback (most recent call last):
    File "/home/pi/Desktop/python-lis3dh-master/LIS3DH_bus1.py", line 2, in
    from Adafruit_GPIO import I2C
    ImportError: No module named 'Adafruit_GPIO'

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):

  • installed Adafruit_GPIO for both python and python3 (it appears on the lists of pip and pip3).

  • checked for RPi.GPIO and it is installed as well

  • still after just first line which is 'from Adafruit_GPIO import I2C' I get the error I mentioned, no idea what's wrong

  • checked every step, power is adequate, and 'sudo i2cdetect -y 1' detects the device

FT232H.py multi-byte reads does not comply to the SMBus standard

The mutli-byte write commands do not adhere to the SMBus standard and as such, devices that adhere strictly to the standard will return 0xFF as they stop sending data on the stop.
SMBus Specification Page 41.
This is due to SMBus standard not using the stop after the register is written.

 def readU16(self, register, little_endian=True):
        """Read an unsigned 16-bit value from the specified register, with the
        specified endianness (default little endian, or least significant byte
        first)."""
        self._idle()
        self._transaction_start()
        self._i2c_start()
        self._i2c_write_bytes([self._address_byte(False), register])
        self._i2c_stop() /* NOT SMBUS COMPLIANT */
        self._i2c_idle()
        self._i2c_start()
        self._i2c_write_bytes([self._address_byte(True)])
        self._i2c_read_bytes(2)
        self._i2c_stop()
        response = self._transaction_end()
        self._verify_acks(response[:-2])
        if little_endian:
            return (response[-1] << 8) | response[-2]
        else:
return (response[-2] << 8) | response[-1]

This is simply fixed by removing the first stop:

 def readU16(self, register, little_endian=True):
        """Read an unsigned 16-bit value from the specified register, with the
        specified endianness (default little endian, or least significant byte
        first)."""
        self._idle()
        self._transaction_start()
        self._i2c_start()
        self._i2c_write_bytes([self._address_byte(False), register])
        self._i2c_idle()
        self._i2c_start()
        self._i2c_write_bytes([self._address_byte(True)])
        self._i2c_read_bytes(2)
        self._i2c_stop()
        response = self._transaction_end()
        self._verify_acks(response[:-2])
        if little_endian:
            return (response[-1] << 8) | response[-2]
        else:
return (response[-2] << 8) | response[-1]

Comment in MCP370xx __init__ inconsistent with code

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): RasPi 3, Raspbian Jessie
  • Python version (run python -version or python3 -version): 3.4.2
  • Error message you are receiving, including any Python exception traces: N/A
  • List the steps to reproduce the problem below (if possible attach code or commands
    to run): N/A

The __init__ code comment in MCP370xx.py says it is setting the iodir register for all inputs. However, all inputs would be [0xFF]*self.gpio_bytes. The code sets iodir register for all outputs.

TypeError: __init__() got an unexpected keyword argument 'busnum'

The instructions at https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi/usage no longer work. It appears that this change is the cause. Running the char_lcd_plate.py example script (or any other attempt to use Adafruit_CharLCDPlate now gives an error:

$ sudo ./examples/char_lcd_plate.py 
Traceback (most recent call last):
  File "./examples/char_lcd_plate.py", line 10, in <module>
    lcd = LCD.Adafruit_CharLCDPlate()
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_CharLCD-1.0.0-py2.7.egg/Adafruit_CharLCD/Adafruit_CharLCD.py", line 434, in __init__
    self._mcp = MCP.MCP23017(address=address, busnum=busnum)
  File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-0.6.5-py2.7.egg/Adafruit_GPIO/MCP230xx.py", line 154, in __init__
    super(MCP23017, self).__init__(address, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'busnum'

Library needs support for Odroid-C2 (ubuntu)

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.):
    Linux odroid 3.16.60-28 #1 SMP PREEMPT Thu Nov 15 06:06:45 -02 2018 aarch64 aarch64 aarch64 GNU/Linux

  • Python version (run python -version or python3 -version):
    Python 2.7.15rc1

  • Error message you are receiving, including any Python exception traces: Could not determine default I2C bus for platform.

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):
    Issue seems to be in I2C.py file, get_default_bus():
    please change so that default bus 1 is returned for Odroid C2 rather than an exception.
    I have already tested with above change and it works well.

Adafruit_Python_GPIO not compatible with Python 3.6.1, only Python 2.7.9

I have both Python 2.7.9 and Python 3.6.1 installed on my RPi2. I'm using the MPC3008 interfaced to the hardware port for SPI. And I use the example program from Adafruit_Python_MPC3008 library called "simpletest.py".
This works perfectly when I use Python 2.7.9.

However, when I try using Python 3.6.1, I get this error message
ModuleNotFoundError: No Module named 'Adafruit_GPIO'
As I mentioned, I'm using the hardware port for the SPI. So I followed the instructions to uncomment those steps and comment out the steps for the software port.

I installed the MPC3008 library using the instructions from this homepage on github
https://github.com/adafruit/Adafruit_Python_MCP3008
And I installed the GPIO library using the instructions from your homepage here on github.
https://github.com/adafruit/Adafruit_Python_GPIO

Unless I'm mistaken, I couldn't find any solutions to this problem in the previous issues.
I'm trying to merge this example code into my new project, but I'm using Python3 with networking code. And I like to remain with this version.

below is the code showing what I did

# Simple example of reading the MCP3008 analog input channels and printing
# them all out.
# Author: Tony DiCola
# License: Public Domain
import time

# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008

# Software SPI configuration:
#CLK  = 18
#MISO = 23
#MOSI = 24
#CS   = 25
#mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)

# Hardware SPI configuration:
SPI_PORT   = 0
SPI_DEVICE = 0
mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

print('Reading MCP3008 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
print('-' * 57)
# Main program loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*8
    for i in range(8):
        # The read_adc function will get the value of the specified channel (0-7).
        values[i] = mcp.read_adc(i)
    # Print the ADC values.
    print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)

FT232H code should use a lock to serialize access to the chip

Right now if you use FT232H code in a multithreaded app you need to be careful to serialize access to the library since two calls to the same FT232H at the same time will trample over each other reading data from the chip. Consider adding a lock to serialize access at the library level.

Put package on PyPi

I think it would be really useful to put this (and all of your) packages onto PyPi so people can actually pip install the packages directly instead of running setup.py manually. You can do so by using the sdist command on setup.py.

Example:

python setup.py sdist upload -r pypi

With example .pypirc:

[distutils]
index-servers =
    pypi

[pypi]
repository: <repository-url>
username: <username>
password: <password>

Runtime Errors when reading large amounts of data

Hi,

I'm using the Adafruit_GPIO library to talk to an SD card via SPI.

I have noticed that if I wanted to read back a large amount of data >1000 bytes by using either the .read or .transfer functions I get an error from the _poll_read functions.

"RuntimeError('ftdi_read_data failed with error code {0}.'.format(ret))
RuntimeError: ftdi_read_data failed with error code -9."

Any ideas why?
When using a slow baud rate it works so do i need a delay before calling the _poll_read functions, i'll try this.

Thanks

Support arm64 for platform version

On linux arm64 there is no hardware info in /proc/cpuinfo, it needs to get platform from /proc/device-tree/model

$ sudo python3 examples/simpletest.py 
Traceback (most recent call last):
  File "examples/simpletest.py", line 12, in <module>
    adc = Adafruit_ADS1x15.ADS1115()
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_ADS1x15-1.0.2-py3.5.egg/Adafruit_ADS1x15/ADS1x15.py", line 319, in __init__
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_ADS1x15-1.0.2-py3.5.egg/Adafruit_ADS1x15/ADS1x15.py", line 82, in __init__
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_GPIO-1.0.3-py3.5.egg/Adafruit_GPIO/I2C.py", line 65, in get_i2c_device
  File "/usr/local/lib/python3.5/dist-packages/Adafruit_GPIO-1.0.3-py3.5.egg/Adafruit_GPIO/I2C.py", line 57, in get_default_bus
RuntimeError: Could not determine default I2C bus for platform.

Initial issues :
bamarni/pi64#35
raspberrypi/linux#2110

Would it be possible for support for the FT232H chip to be added?

Having support for a usb->GPIO breakout would be great for prototyping/rapid development on a workstation.

Support for something like the FT232H or a USB-RPi compatible breakout board like one of these:

http://garagetech.tips/rtk-gpio-usb-raspberry-pi-compatible-gpio-header/
http://garagetech.tips/rtk-gpio-usb-raspberry-pi-compatible-gpio-header/

In fact, it would be awesome if Adafruit would make something like one of those two boards.

If only support for the FT323H could be added, code could be run on from a PC workstation running Linux, a RPi or a BB.

Expose polarity argument on BBIO_PWM_Adapter.start()

Adafruit's dedicated Beaglebone Black Python API allows the use of the polarity argument upon calling PWM.start(), which determines whether the duty cycle setting affects the high or low part of the signal's period.

This is useful in cases where an output is driven with inverted logic (e.g. using a transistor in inverter configuration to switch a +12V load).

BBIO_PWM_Adapter.start() in the PWM.py module does neither expose nor initialise the polarity argument, thus it can't be used.

error accessing p8_7 and p8_8 on BBB

  • Platform/operating system: Beagle Bone Black - Angstrom image

  • Python version: 2.7

  • Error message you are receiving, including any Python exception traces: ~~GPIO set failed - insufficient permissions or file does not exist.*

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):

  • install old angstrom linux image,
  • install python GPIO using tutorial on adafruit for angstrom linux,
  • write any python script that tries to set pins 7 or 8 as GPIO pins GPIO.Setup("P8_7",GPIO.OUTPUT)
  • error above occurs on run using python
  • I am logged in as root user
  • pins P8_9-18 seem to work.

Can PCF8574 be used for LCD control with CharLCD library?

The MCP23XXX GPIO extender is used as custom gpio for the CharLCD class.

Can the PCF8574 also be used as custom gpio for that purpose? (are all needed methods worked out?)
After my first attempts i cannot get it to work although code is executed without errors.

Alternating variable name in I2C.py

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.):

Ubuntu 16.04 but i havent run the code yet, pylint just picked up the unused variable

  • Python version (run python -version or python3 -version): 3.5.1+
  • Error message you are receiving, including any Python exception traces:

Pylint Warning W0612 Unused variable 'i' at line 33 col 8 in Adafruit_GPIO/I2C.py

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):

here's the section

 def reverseByteOrder(data):
 """Reverses the byte order of an int (16-bit) or long (32-bit) value."""
 # Courtesy Vishal Sapre
 byteCount = len(hex(data)[2:].replace('L','')[::2])
  val       = 0
  for i in range(byteCount):
      val    = (val << 8) | (data & 0xff)
      data >>= 8
   return val

It's a counter, there's a variable declared, val, then in the for statement i is used but only in the first line after which val is used again

Like I say I opened the file in atom to have a look and pylint pointed it out, (also a bunch of convention messages about the method names being in camelcase when they should be separated with underscores but, that's not gonna break anything and when it gives me an option to auto fix them, i'll happily let that fix it and you'll see a PR 🚮 )

The variable name thing i thought I'd mention it looks like it should break that function, probably without an error. My Python's not great though but if it doesn't break it I'd love to understand why, it's been there since the code has been on github and it's not been fixed so either that function isn't used much (at all?) or I'm going to learn something.

So in advance return, like a knowledge exchange, the unambiguous name for this symbol #️⃣ is an octothorpe, the origin is strange but it is the same as the origin of the word sextile * (six points)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.