Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit a0cac2a

Browse files
author
K. Townsend
committedDec 6, 2012
Added rev auto-check
1 parent ee702e8 commit a0cac2a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

Diff for: ‎Adafruit_I2C/Adafruit_I2C.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@
88

99
class Adafruit_I2C :
1010

11-
def __init__(self, address, bus=smbus.SMBus(0), debug=False):
11+
def getPiRevision():
12+
"Gets the version number of the Raspberry Pi board"
13+
# Courtesy quick2wire-python-api
14+
# https://github.com/quick2wire/quick2wire-python-api
15+
try:
16+
with open('/proc/cpuinfo','r') as f:
17+
for line in f:
18+
if line.startswith('Revision'):
19+
return 1 if line.rstrip()[-1] in ['1','2'] else 2
20+
except:
21+
return 0
22+
23+
def __init__(self, address, bus=smbus.SMBus(1 if getPiRevision() > 1 else 0), debug=False):
1224
self.address = address
1325
self.bus = bus
1426
self.debug = debug

0 commit comments

Comments
 (0)