I generally copy paste existing code and fiddle with it til it works how i want.
So my plea for help is i have a python script i use for my xmas lights every year.
I had been limited to 15 channels but this year i have added a MCP23S17 io expander.
I have managed to get this to work with LightshowPi easy enough but i have python scripts which just toggle gpio in binary sequences.
Attached is the code in question.
What i need to do is add the mcp23s17 outputs to the list so i can expand the sequences from 15 to 30.
I just have no idea how to include the mcp23s17 in the script...
For example - where the gpio are defined at the beginning
# Define GPIO outputs
RpiGPIO = [30,28,29,17,18,27,10,24,22,23,31,8,9,11,25]
I want to add the mcp23s17 gpio to the end so it would be like -
# Define GPIO outputs
RpiGPIO = [30,28,29,17,18,27,10,24,22,23,31,8,9,11,25,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
where the gpio 65 to 80 are the mcp23s17 gpio
Then i can expand my sequences to suit the extra gpio
Hopefully that makes sense to someone and i will be eternally grateful to whoever can assist me!
here is one of the shorter scripts, i want to basically add the new gpio to it .
ie: where i define gpio outputs i want to add the mcp23 gpio outputs and extend the sequences to suit
Code: Select all
#!/usr/bin/python
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Define GPIO outputs
RpiGPIO = [30,28,29,17,18,27,10,24,22,23,31,8,9,11,25]
# Set all pins as output
for pinref in RpiGPIO:
# print "Setup pins"
GPIO.setup(pinref,GPIO.OUT)
# Define some settings
StepCounter = 0
StepDir = 1
WaitTime = 0.2
# all flash then sequential
StepCount3 = 24
Seq3 = []
Seq3 = range(0,StepCount3)
Seq3[0] =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
Seq3[1] =[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Seq3[2] =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
Seq3[3] =[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Seq3[4] =[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Seq3[5] =[1,1,0,0,0,0,0,0,0,0,0,0,0,0,0]
Seq3[6] =[1,1,1,0,0,0,0,0,0,0,0,0,0,0,0]
Seq3[7] =[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0]
Seq3[8] =[1,1,1,1,1,0,0,0,0,0,0,0,0,0,0]
Seq3[9] =[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0]
Seq3[10] =[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0]
Seq3[11] =[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]
Seq3[12] =[1,1,1,1,1,1,1,1,0,0,0,0,0,0,0]
Seq3[13] =[1,1,1,1,1,1,1,1,1,0,0,0,0,0,0]
Seq3[14] =[1,1,1,1,1,1,1,1,1,1,0,0,0,0,0]
Seq3[15] =[1,1,1,1,1,1,1,1,1,1,1,0,0,0,0]
Seq3[16] =[1,1,1,1,1,1,1,1,1,1,1,1,0,0,0]
Seq3[17] =[1,1,1,1,1,1,1,1,1,1,1,1,1,0,0]
Seq3[18] =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,0]
Seq3[19] =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
Seq3[20] =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
Seq3[21] =[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Seq3[22] =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
Seq3[23] =[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
# Choose a sequence to use
Seq = Seq3
StepCount = StepCount3
# Start main loop
while True:
# print "-- Step : %i --" %StepCounter
for pinref in range(0, 15):
xpin=RpiGPIO[pinref]#
# Check if LED should be on or off
if Seq[StepCounter][pinref]!=0:
# print " Enable %i" %xpin
GPIO.output(xpin, True)
else:
# print " Disable %i" %xpin
GPIO.output(xpin, False)
StepCounter += StepDir
# If we reach the end of the sequence reverse
# the direction and step the other way
if (StepCounter==StepCount) or (StepCounter<0):
StepDir = StepDir * -1
StepCounter = StepCounter + StepDir + StepDir
# Wait before moving on
time.sleep(WaitTime)
