LED Backpacks, Changing the address in your code for Python

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
limko
 
Posts: 3
Joined: Fri Jan 31, 2014 5:18 pm

LED Backpacks, Changing the address in your code for Python

Post by limko »

To Adafuit Support,
I'm working on a project involving the 1.2" 8x8 Matrix and since having 4 of these Matrixs wired up this morning I'm having trouble changing the address for the Matrix's in the Code and so far haven't come across a solution. so I know I have the address 0x70,0x71,0x74,0x75, and from this guide: http://learn.adafruit.com/adafruit-led- ... 2c-address ,the example for changing the code is in Arduino library and not the Python library I understand.
If you could point me in the right direction that'd be great.

Cheers,
Liam
Attachments
example of set up
example of set up
matrix.png (320.36 KiB) Viewed 312 times
example of function grid and the 4 address I want to implement
example of function grid and the 4 address I want to implement
code 1.png (259.61 KiB) Viewed 312 times

User avatar
cameraready
 
Posts: 55
Joined: Wed Jan 30, 2013 11:10 pm

Re: LED Backpacks, Changing the address in your code for Pyt

Post by cameraready »

I hooked up 3 of the 8x8 matrices to my pi last year and posted the code here. http://forums.adafruit.com/viewtopic.php?f=47&t=38417

If I remember correctly you have to be careful not to overpower the pi by running more than one matrix. I used a level shifter so that I could power the matrices separate from the pi. http://forums.adafruit.com/viewtopic.php?f=19&t=40791

limko
 
Posts: 3
Joined: Fri Jan 31, 2014 5:18 pm

Re: LED Backpacks, Changing the address in your code for Pyt

Post by limko »

Thank you cameraready for the quick reply,
I've looked through both links you send me and the level shifter is is defiantly something I'll need to get. Though I should have said this early but my problem is I want to run all 4 matrix's at the same time, using the adafruit code which I've edited slightly, (using setPixel and writeRowRaw to create certain modes) though can't get all martix's to light up at the same time and can only do one at a time because I'm unsure as how to define the code to run 4 of them together in "grid" which declares which address the code is going to (0x70,0x71,0x74,0x75).
There are other things I need to consider with the project but first things first I need all these matrix's working together :)

Thanks,
Liam

User avatar
cameraready
 
Posts: 55
Joined: Wed Jan 30, 2013 11:10 pm

Re: LED Backpacks, Changing the address in your code for Pyt

Post by cameraready »

To get all 4 matrices working you can make an array. I used a for loop to instantiate them but you could do it manually for the different addresses.

Code: Select all

grid = []

# add each matrix to the array with the append method and specify the address of each
grid.append(EightByEight(address=0x70))
grid.append(EightByEight(address=0x71))
grid.append(EightByEight(address=0x74))
grid.append(EightByEight(address=0x75))

# address the matrices in the array
grid[0].writeDisplay()
grid[1].writeDisplay()
grid[2].writeDisplay()
grid[3].writeDisplay()

limko
 
Posts: 3
Joined: Fri Jan 31, 2014 5:18 pm

Re: LED Backpacks, Changing the address in your code for Pyt

Post by limko »

Again cameraready thanks for the reply,
I've been trying out this code you've given me but seem to get the following errors for:

Code: Select all

import time
import datetime
from Adafruit_8x8 import EightByEight
import sys

# ===========================================================================
# STATIC
# ===========================================================================

# a function to all led's on
def turnAllOn(grid):
  # loop through the rows
  for x in range(0, 8):
    # write the row data
    grid.writeRowRaw(x, 0xFF)

grid = []

# add each matrix to the array with the append method and specify the address of each
grid.append(EightByEight(address=0x70))
grid.append(EightByEight(address=0x71))
grid.append(EightByEight(address=0x74))
grid.append(EightByEight(address=0x75))

# address the matrices in the array
grid[0].writeDisplay()
grid[1].writeDisplay()
grid[2].writeDisplay()
grid[3].writeDisplay()

print "Press CTRL+C to exit"

try:
  #loop forever
  while(True):
    # turn all the leds ons
    turnAllOn(grid)

except KeyboardInterrupt:
  print " user cancelled with CTRL C" #if user presses CTRL C then program will stop

except:
  print "Unexpected error:", sys.exc_info()[0] #otherwise this except is run if there is a error where sys will show the error
  raise

finally:
  grid.clear()

# example of using writeRowRaw
# 0x defines that we are going to use hex
#   binary pattern e.g. 10101010 = 170 = AA
#grid.writeRowRaw(1, 0xAA)


which is:
"sudo python staticV2.py
Traceback (most recent call last):
File "staticV2.py", line 33, in <module>
grid[0].writeDisplay()
AttributeError: EightByEight instance has no attribute 'writeDisplay'"

Or when I edit the array:

Code: Select all

#!/usr/bin/python

import time
import datetime
from Adafruit_8x8 import EightByEight
import sys

# ===========================================================================
# STATIC
# ===========================================================================

# a function to all led's on
def turnAllOn(grid):
  # loop through the rows
  for x in range(0, 8):
    # write the row data
    grid.writeRowRaw(x, 0xFF)

grid = []

# add each matrix to the array with the append method and specify the address of each
grid.append(EightByEight(address=0x70))
grid.append(EightByEight(address=0x71))
grid.append(EightByEight(address=0x74))
grid.append(EightByEight(address=0x75))

# address the matrices in the array
#grid[0].writeDisplay()
#grid[1].writeDisplay()
#grid[2].writeDisplay()
#grid[3].writeDisplay()

print "Press CTRL+C to exit"

try:
  #loop forever
  while(True):
    # turn all the leds ons
    turnAllOn(grid)

except KeyboardInterrupt:
  print " user cancelled with CTRL C" #if user presses CTRL C then program will stop

except:
  print "Unexpected error:", sys.exc_info()[0] #otherwise this except is run if there is a error where sys will show the error
  raise

finally:
  grid.clear()

# example of using writeRowRaw
# 0x defines that we are going to use hex
#   binary pattern e.g. 10101010 = 170 = AA
#grid.writeRowRaw(1, 0xAA) 
where the matrixs flash for half a second and then I get:
"sudo python staticV2.py
Press CTRL+C to exit
Unexpected error: <type 'exceptions.AttributeError'>
Traceback (most recent call last):
File "staticV2.py", line 57, in <module>
grid.clear()
AttributeError: 'list' object has no attribute 'clear'"

Any ideas what's the problem? :?

User avatar
cameraready
 
Posts: 55
Joined: Wed Jan 30, 2013 11:10 pm

Re: LED Backpacks, Changing the address in your code for Pyt

Post by cameraready »

It's been a while since I wrote my code. I think the big difference was that I created the GFX library and used in the Adafruit_LEDBackpack library. It looks like your staticV2.py file isn't seeing the Adafruit_LEDBackpack library or it doesn't contain the .writeDisplay() method.

You might try downloading my version of the Backpack library from github and try it with your code. Unfortunately I'm using my Pi for XBMC at the moment and don't have the matrices hooked up to test.

https://github.com/cameraready/Adafruit ... ython-Code

allard01
 
Posts: 1
Joined: Tue May 20, 2014 3:07 am

Re: LED Backpacks, Changing the address in your code for Pyt

Post by allard01 »

Its very nice to read your post and I can say that this post gathering lots of useful information about LED backpacks, Changing the address in you code for python.

skiing accessories

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”