#!/usr/bin/python
# square.py
# Light square on the Pi Matrix demonstrating simple multiplexing
import smbus #Python access to I2C bus
import time #For timing delays
addr = 0x20 #I2C bus address of the 23017
dirA = 0x00 #PortA I/O direction register
dirB = 0x01 #PortB I/O direction register
portA = 0x12 #PortA data register
portB = 0x13 #PortB data register
print "Pi Matrix - Square demo"
bus = smbus.SMBus(1) #Use '1' for newer Pi's and 0 for revision 1 Pi's
bus.write_byte_data(addr, dirA, 0x00) #all zeros = all outputs on PortA
bus.write_byte_data(addr, dirB, 0x00) #all zeros = all outputs on PortB
for i in range(0,500) :
bus.write_byte_data(addr, portA, 0x00)
bus.write_byte_data(addr, portB, ~0b00100000)
bus.write_byte_data(addr, portA, 0b00111100)
time.sleep(0.001)
bus.write_byte_data(addr, portA, 0x00)
bus.write_byte_data(addr, portB, ~0b00010000)
bus.write_byte_data(addr, portA, 0b00100100)
time.sleep(0.001)
bus.write_byte_data(addr, portA, 0x00)
bus.write_byte_data(addr, portB, ~0b00001000)
bus.write_byte_data(addr, portA, 0b00100100)
time.sleep(0.001)
bus.write_byte_data(addr, portA, 0x00)
bus.write_byte_data(addr, portB, ~0b00000100)
bus.write_byte_data(addr, portA, 0b00111100)
time.sleep(0.001)
print "Clearing display"
bus.write_byte_data(addr, portA, 0x00)
#!/usr/bin/python
# singleframe.py
# Single frame on the Pi Matrix demonstrating simple multiplexing
import smbus #Python access to I2C bus
import time #For timing delays
addr = 0x20 #I2C bus address of the 23017
dirA = 0x00 #PortA I/O direction register
dirB = 0x01 #PortB I/O direction register
portA = 0x12 #PortA data register
portB = 0x13 #PortB data register
print "Pi Matrix - Single frame demo"
bus = smbus.SMBus(1) #Use '1' for newer Pi's and 0 for revision 1 Pi's
bus.write_byte_data(addr, dirA, 0x00) #all zeros = all outputs on PortA
bus.write_byte_data(addr, dirB, 0x00) #all zeros = all outputs on PortB
def drawRow(row,display):
bus.write_byte_data(addr, portA, 0x00) # clear the column data
bus.write_byte_data(addr, portB, ~row) # set the row
bus.write_byte_data(addr, portA, display) # set column data
time.sleep(0.001)
def drawFrame(data):
for b in range(0,7+1) :
drawRow(0x01<<b,data[b])
for i in range(0,500) :
drawFrame([
0b10000000,
0b01000000,
0b00100000,
0b00010000,
0b00001000,
0b00000100,
0b00000010,
0b00000001])
print "Clearing display"
bus.write_byte_data(addr, portA, 0x00)
#!/usr/bin/python
# animation.py
# Multiple frame animation on the Pi Matrix demonstrating simple multiplexing
import smbus #Python access to I2C bus
import time #For timing delays
addr = 0x20 #I2C bus address of the 23017
dirA = 0x00 #PortA I/O direction register
dirB = 0x01 #PortB I/O direction register
portA = 0x12 #PortA data register
portB = 0x13 #PortB data register
print "Pi Matrix - Multiple frame demo"
bus = smbus.SMBus(1) #Use '1' for newer Pi's and 0 for revision 1 Pi's
bus.write_byte_data(addr, dirA, 0x00) #all zeros = all outputs on PortA
bus.write_byte_data(addr, dirB, 0x00) #all zeros = all outputs on PortB
def drawRow(row,display):
bus.write_byte_data(addr, portA, 0x00) # clear the column data
bus.write_byte_data(addr, portB, ~row) # set the row
bus.write_byte_data(addr, portA, display) # set column data
time.sleep(0.001)
def drawImage(data):
for b in range(0,7+1) :
drawRow(0x01<<b,data[b])
def drawFrame(frameData,refreshes):
for i in range(0,refreshes) :
drawImage(frameData)
def displayAnimation(frames,frameRefreshes):
for i in range(0, len(frames)) :
if (i<len(frameRefreshes)) :
fallBackRefresh=frameRefreshes[i]
drawFrame(frames[i], fallBackRefresh)
displayAnimation([
[
0b00000000,
0b00000000,
0b00000000,
0b00000001,
0b00000001,
0b00000001,
0b00000001,
0b00000001]
,[
0b00000000,
0b00000000,
0b00000001,
0b00000010,
0b00000010,
0b00000010,
0b00000010,
0b00000010]
,[
0b00000000,
0b00000001,
0b00000010,
0b00000101,
0b00000101,
0b00000100,
0b00000100,
0b00000101]
,[
0b00000000,
0b00000011,
0b00000100,
0b00001110,
0b00001110,
0b00001000,
0b00001000,
0b00001101]
,[
0b00000000,
0b00000111,
0b00001000,
0b00010110,
0b00010110,
0b00010000,
0b00010000,
0b00010101]
,[
0b00000000,
0b00001111,
0b00010000,
0b00111011,
0b00111011,
0b00100000,
0b00100000,
0b00110101]
,[
0b00000000,
0b00011110,
0b00100001,
0b01011011,
0b01011011,
0b01000000,
0b01000000,
0b01010101]
,[
0b00000000,
0b00111100,
0b01000011,
0b11101101,
0b11101101,
0b10000001,
0b10000001,
0b11010101]
,[
0b00000000,
0b00111100,
0b01000011,
0b10110111,
0b10110111,
0b10000001,
0b10000001,
0b10101011]
,[
0b00000000,
0b00111100,
0b01000011,
0b11101101,
0b11101101,
0b10000001,
0b10000001,
0b11010101]
,[
0b00000000,
0b00111100,
0b01000011,
0b10110111,
0b10110111,
0b10000001,
0b10000001,
0b10101011]
,[
0b00000000,
0b00111100,
0b01000011,
0b11101101,
0b11101101,
0b10000001,
0b10000001,
0b11010101]
,[
0b00000000,
0b00111100,
0b01000011,
0b10110111,
0b10110111,
0b10000001,
0b10000001,
0b10101011]
]
,[20])
print "Clearing display"
bus.write_byte_data(addr, portA, 0x00)
#!/usr/bin/python
#
# columnstep.py
#
# Lights each column in turn on the Pi Matrix
import smbus #Python access to I2C bus
import time #For timing delays
# Definitions for the MCP23017 chip
addr = 0x20 #I2C bus address of the 23017
dirA = 0x00 #PortA I/O direction register
dirB = 0x01 #PortB I/O direction register
portA = 0x12 #PortA data register
portB = 0x13 #PortB data register
# Program start
print "Pi Matrix - Column step demo"
bus = smbus.SMBus(1) #Use '1' for newer Pi's and 0 for revision 1 Pi's
bus.write_byte_data(addr, dirA, 0x00) #all zeros = all outputs on PortA
bus.write_byte_data(addr, dirB, 0x00) #all zeros = all outputs on PortB
bus.write_byte_data(addr, portB, 0x00) #set row outputs low
for i in range(0,7+1) :
bus.write_byte_data(addr, portA, 0x01<<i) #set column outputs low = LEDs off
time.sleep(0.25) #keep LEDs off for 0.5 secs
bus.write_byte_data(addr, portA, 0x00) #set column outputs low = LEDs off
#!/usr/bin/python
#
# rowstep.py
#
# Lights each row in turn on the Pi Matrix
import smbus #Python access to I2C bus
import time #For timing delays
# Definitions for the MCP23017 chip
addr = 0x20 #I2C bus address of the 23017
dirA = 0x00 #PortA I/O direction register
dirB = 0x01 #PortB I/O direction register
portA = 0x12 #PortA data register
portB = 0x13 #PortB data register
# Program start
print "Pi Matrix - Row step demo"
bus = smbus.SMBus(1) #Use '1' for newer Pi's and 0 for revision 1 Pi's
bus.write_byte_data(addr, dirA, 0x00) #all zeros = all outputs on PortA
bus.write_byte_data(addr, dirB, 0x00) #all zeros = all outputs on PortB
bus.write_byte_data(addr, portA, 0xFF) #set column outputs high
for i in range(0,7+1) :
bus.write_byte_data(addr, portB, ~(0x01<<i)) #set column outputs low = LEDs off
time.sleep(0.25) #keep LEDs off for 0.5 secs
bus.write_byte_data(addr, portA, 0x00)
sudo apt-get update
sudo apt-get install python-smbus
sudo apt-get install i2c-tools
sudo adduser pi i2c
i2cset -y 1 0x20 0x00 0x00
i2cset -y 1 0x20 0x01 0x00
i2cset -y 1 0x20 0x13 0x00
ic2set -y 1 0x20 0x12 0xFF
-bash: ic2set: command not found
i2cset -y 1 0x20 0x12 0xFF
i2cset -y 1 0x20 0x12 0x00
email
root
flog archives
In fact I'm not responsible for anything ever, so there!
Disclaimer:
This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk
I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk