Just to start the conversation here on bitbucket. Sounds like this is what Chris and I had in mind.
Implement MCP23017 IO expander.
Chris do you plan on using more than one 23017? I wasn't planning on it at this point, but might be something to consider during coding.
Along the lines of more channels... there are more than just the 8 available on pi too isn't there? I am not certain, but I thought even the pins designated as uart, i2c and spi could be used the same way as the 8 gpio. Then there are also the other 4 pins available on the unpopulated P5 header. Am I right thinking those can just be added to Todd's list of pins? Along with making changes in the rest of the code to handle more than just 8.
I hope I am not coming across as trying to run things. That isn't my intention. I just wanted to get my thoughts out there before anyone was a long ways down the road.
I have tested using the other pins on the pi, which is why I started using wiringpi2-python in the first place. I was able to get other pins ( 16 in my test case ) such as i2c, api, to be output pins and control my 16 channels. The problem I ran into (and excuse my lack of correct terminology here ) is that some of the pins are linked to other devices on board, such as the sound output and the LED onboard. So when testing I would get strange results. It worked most of the time, and at other times I would get random dimming etc. Im sure all could have been corrected with code, but I didn't dive much further into it because my 23017 arrived that day :). I will look into coding it in a way that allows for a defined amount of pins, but time will be my enemy at this time. The house is almost wired, and my daughter is getting anxious lol. 16 is the goal but Ill see what I can do to make it more applicable to other setups !
One more question for you. Does the mechanical sainsmart relay board you are using have logic 0 to turn on a relay? I think the solid state Todd used is the other way around with logic 1 to turn relay on.
Correct Ryan, mine is opposite, which will be accounted for in code. Quick update, converting to wiringpi2 was an easy fix. I currently have 8 channels running and operating on the 23017. Will work on the 16 channels tonight.
Todd can you quickly explain what the weighting list and limit list accomplish?
The combination of the weighting list and limit list end up setting the thresholds to cross for each channel - in reality they could be combined into a single limit list and do away with the weighting list altogether. The weights were picked to generally keep each channel between 0 and 100 - although this was before I added the dynamic limit. With the dynamic limit there really is no need to normalize each channel between 0 and 100.
The limit list is dynamically adjusted during playback. The limit is increased by 20% whenever the amplitude for that particular channel is more than 60% of the current limit (see line 232). The limit is decreased by 20% whenever the light in that channel has been off for 10 cycles in a row. This dynamic limit was created after I had played multiple songs with a static limit per channel which wasn't as responsive as I'd like.
You can get a feel to how often the limits are changing by passing --verbosity=2 to the script when playing back a file that hasn't already had its synchronization cached.
I just pushed a new commit to beta. I won't explain it all here, but basically I added support for a .cfg file to hold many settings. See the .cfg file for a good explanation of most. I also implemented Ryans dynamic channel setup based on number of GPIO's defined in the .cfg file. I also added a channel mapping setting which basically allows channel assignment to pins programmatically instead of having to physically rewire pins. see the cfg file for a full explanation. I have not fully tested the code, but it all seems to be function with the limited testing I did. It still needs a bit of cleaning, and some word choices may not be the best / correct but Ill get to that later.
This is awesome - I finally got around to actually downloading and using it all! Love it! Thanks both for all the enhancements. Will try to spend some time cleaning up a few things and then merge these changes into the main branch.
I'm now using it on my own system - will record a video and upload my christmas lights using this latest update!
Just ran into this post and sorry for reviving a post that's kind of old but I was able to extend this a little more. I am currently running lightshowpi on 32 mechanical relays via the 16 port Sainsmart board I am sure most are aware of. While the pi struggles with 32 channel real time output (while generating the cache file), once the cache file is generated it seems to handle 32 channels and mp3 playback just fine. However I have run into some odd behaviour.
It seems that when setting the frequency range to 20 - 20000 channels I always have 2 low and 2 mid low freq ranges showing up as in in the cache file no matter what song I feed through it.... I was able to get the lows back by reducing the range to 100 - 20000 however then I would lose the 4 highest freq ranges..... have to look at the fft code to see what's going on there and why certain freq ranges always evaluate to inf depending on the freq range used. Still need to try and figure out what's going on here but will post the code changes necessary to basically use up to the maximum of 8 mcp23017 GPIO expander if you are bold enough to do so. (P.S. for those of you that are interested I have successfully been able to actually wire MORE than 8 mcp23017 chips to a pi with some caveats. Post here if you are interested but I have successfully controlled 64 mcp23017s (1024 pins) with the aid of an ATX PS as both the pi's power source and the other components. Anyhow if anyone wants to know lemme know and I will repo the code and some basic information on the hackish way I was able to accomplish this. Anyhow as to the lighting pi code (I am not submitting the code as a push due to the dead freq range issue I have encountered)
# line 60 I believe but you should be able to figure this out# change # wiringpi.mcp23017Setup(expander['pin_base'], expander['i2c_addr'])# toforexpanderin_MCP23017:wiringpi.mcp23017Setup(expander['pin_base'],expander['i2c_addr'])
Then in the overrides.cfg (or default config if using that) change the mcp23017 dictionary to a list of dictionaries like so: