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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adafruit/Adafruit-Raspberry-Pi-Python-Code
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nmadura/Adafruit-Raspberry-Pi-Python-Code
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Jan 11, 2013

  1. modifications to the i2c/backpack code

    modifications to the i2c/backpack code to make it more compatible with
    other linux machines that have an i2c bus available to it. Of
    particular intrest to me is the BeagleBone.
    Nathaniel Madura committed Jan 11, 2013
    Copy the full SHA
    ccb3fcf View commit details
  2. fixed minor bugs

    Nathaniel Madura committed Jan 11, 2013
    Copy the full SHA
    fbd5b8e View commit details
  3. fixed some minor formatting issues

    Nathaniel Madura committed Jan 11, 2013
    Copy the full SHA
    d64e053 View commit details
16 changes: 11 additions & 5 deletions Adafruit_I2C/Adafruit_I2C.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

class Adafruit_I2C :

@staticmethod
def getPiRevision():
"Gets the version number of the Raspberry Pi board"
# Courtesy quick2wire-python-api
@@ -19,14 +20,19 @@ def getPiRevision():
return 1 if line.rstrip()[-1] in ['1','2'] else 2
except:
return 0

@staticmethod
def getPiI2CBusNumber():
# Gets the I2C bus number /dev/i2c#
return 1 if Adafruit_I2C.getPiRevision() > 1 else 0

def __init__(self, address, bus=smbus.SMBus(1 if getPiRevision() > 1 else 0), debug=False):
def __init__(self, address, bus=-1, debug=False):
self.address = address
# By default, the correct I2C bus is auto-detected using /proc/cpuinfo
self.bus = bus
# Alternatively, you can hard-code the bus version below:
# self.bus = smbus.SMBus(0); # Force I2C0 (early 256MB Pi's)
# By default, the correct I2C bus is auto-detected using /proc/cpuinfo
# Alternatively, you can hard-code the bus version below:
# self.bus = smbus.SMBus(0); # Force I2C0 (early 256MB Pi's)
# self.bus = smbus.SMBus(1); # Force I2C1 (512MB Pi's)
self.bus = smbus.SMBus(Adafruit_I2C.getPiI2CBusNumber() if bus == -1 else bus)
self.debug = debug

def reverseByteOrder(self, data):
5 changes: 3 additions & 2 deletions Adafruit_LEDBackpack/Adafruit_7Segment.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import time
import datetime
from Adafruit_LEDBackpack import LEDBackpack
from Adafruit_I2C import Adafruit_I2C

# ===========================================================================
# 7-Segment Display
@@ -19,10 +20,10 @@ class SevenSegment:
0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 ]

# Constructor
def __init__(self, address=0x70, debug=False):
def __init__(self, address=0x70, bus=Adafruit_I2C.getPiI2CBusNumber(), debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
self.disp = LEDBackpack(address=address, bus=bus, debug=debug)

def writeDigitRaw(self, charNumber, value):
"Sets a digit using the raw 16-bit value"
5 changes: 3 additions & 2 deletions Adafruit_LEDBackpack/Adafruit_8x8.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import time
import datetime
from Adafruit_LEDBackpack import LEDBackpack
from Adafruit_I2C import Adafruit_I2C

# ===========================================================================
# 8x8 Pixel Display
@@ -12,10 +13,10 @@ class EightByEight:
disp = None

# Constructor
def __init__(self, address=0x70, debug=False):
def __init__(self, address=0x70, bus=Adafruit_I2C.getPiI2CBusNumber(), debug=False):
if (debug):
print "Initializing a new instance of LEDBackpack at 0x%02X" % address
self.disp = LEDBackpack(address=address, debug=debug)
self.disp = LEDBackpack(address=address, bus=bus, debug=debug)

def writeRowRaw(self, charNumber, value):
"Sets a row of pixels using a raw 16-bit value"
4 changes: 2 additions & 2 deletions Adafruit_LEDBackpack/Adafruit_LEDBackpack.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ class LEDBackpack:
0x0000, 0x0000, 0x0000, 0x0000 ]

# Constructor
def __init__(self, address=0x70, debug=False):
self.i2c = Adafruit_I2C(address)
def __init__(self, address=0x70, bus=Adafruit_I2C.getPiI2CBusNumber(), debug=False):
self.i2c = Adafruit_I2C(address, bus)
self.address = address
self.debug = debug

12 changes: 11 additions & 1 deletion Adafruit_LEDBackpack/ex_7segment_clock.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -3,11 +3,21 @@
import time
import datetime
from Adafruit_7Segment import SevenSegment
from Adafruit_I2C import Adafruit_I2C

# ===========================================================================
# Clock Example
# ===========================================================================
segment = SevenSegment(address=0x70)
i2CBus = Adafruit_I2C.getPiI2CBusNumber()

# if using this example with a BeagleBone, uncomment the line below and specify
# which I2C Bus the backpack is connected on. If connected to I2C1 (Header P9,
# pin 17 & 18) specify 1, if connected to I2C2 (Header P9, pin 19 & 20) specify 3.
# WARNING: if using with a BeagleBone use a logic-level convertor such as this one
# https://www.adafruit.com/products/757
# i2CBus = 1 | 3

segment = SevenSegment(address=0x70, bus=i2CBus)

print "Press CTRL+Z to exit"

12 changes: 11 additions & 1 deletion Adafruit_LEDBackpack/ex_8x8_pixels.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -3,11 +3,21 @@
import time
import datetime
from Adafruit_8x8 import EightByEight
from Adafruit_I2C import Adafruit_I2C

# ===========================================================================
# 8x8 Pixel Example
# ===========================================================================
grid = EightByEight(address=0x70)
i2CBus = Adafruit_I2C.getPiI2CBusNumber()

# if using this example with a BeagleBone, uncomment the line below and specify
# which I2C Bus the backpack is connected on. If connected to I2C1 (Header P9,
# pin 17 & 18) specify 1, if connected to I2C2 (Header P9, pin 19 & 20) specify 3.
# WARNING: if using with a BeagleBone use a logic-level convertor such as this one
# https://www.adafruit.com/products/757
# i2CBus = 1 | 3

grid = EightByEight(address=0x70, bus=i2CBus)

print "Press CTRL+Z to exit"