Author Topic: Raspberry Pi GPIO output direct to SSR board  (Read 12254 times)

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,856
  • Kudos: 214
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #15 on: December 16, 2015, 09:08:13 PM »
I would be in someones gratitude if this became a reality.

The other thing that would make my year is if the GPIO ports from expanders could be used/mapped - this is the one I have providing 32 GPIOs -  https://www.abelectronics.co.uk/products/3/Raspberry-Pi/18/IO-Pi

I'm going to pull the code and have a look, but if someone could point me in the right direction, it would be greatly appreciated.

The mcp23017 is supported by the wiringPi library, so it would be easy to add support for that board using by just copying our existing GPIO channel output and modifying it a little.  It is probably less than 10-15 lines of code to be changed not counting renaming the C++ class itself.  It could also be added as an option to the existing GPIO output type like I added the 'invert' option recently.  I don't know that wiringPi could support PWM on the mcp23017 though.
-
Chris

Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #16 on: December 21, 2015, 03:51:06 AM »
Thanks for the reply Chris. I've pulled the code and will have a look.

I've never used/coded C++, predominantly PHP, so this will be interesting.

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,856
  • Kudos: 214
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #17 on: December 21, 2015, 08:14:10 AM »
For the C++ backend you can copy channeloutputs/GPIO.* to channeloutputs/GPIO-MCP.* and edit the new files.  Here is a page which describes the function call to initialize the MCP:  http://wiringpi.com/extensions/i2c-mcp23008-mcp23017/   We will need to pass in the I2C address and it is probably easiest to calculate a PIN number based on that.  channeloutputs/channeloutput.c will need to be modified to add the new GPIO-MCP channel output and the Makefile will need to be modified to do the same.  Then www/channeloutputs.php will have to have the setup UI added.  If you want to try to tackle adding this I can help educate.  It would probably be good for me to type up some instructions for adding a new channel output so others can chip in in the future.

Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #18 on: December 22, 2015, 04:32:15 AM »
Perfect, thanks mate.

I am very interested in adding this functionality to FPP. I've pulled the code and configured it in Netbeans (it may not be the ideal, but I've been using it as an IDE for years). There are a couple of issues with the actual compiling that I know nothing about and need to figure out/configure correctly. Also need some advice on compiling and testing. I'm currently coding in Win10, but have access to my Ubuntu 14.04LTS CLI which I'm fairly comfortable with also.

In relation to functionality, I'm looking to accomplish the following with FPP:

1. Add the channel output for this extender. Apparently I can daisy-chain 4 of these boards for a total of 128 GPIOs. It still leaves me short formy project, but will at least get me a long way there. I need to figure out the best way to add pixels to my show. Currently only running static SSR and a number of RGB 5050 strips.
2. Add support for soft PWM.
3. Happy to help document as needed (I've documented in a private Wiki before).

Do you have a preferred communication channel? IM/Email/etc.?

Cheers,

Craig.

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,856
  • Kudos: 214
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #19 on: December 22, 2015, 12:26:56 PM »
I think there are quite a few issues compiling under windows currently, so you will want to use Ubuntu or do it right on the Pi or BBB.

We have a Makefile which builds everything, you may be able to call that directly, I don't use netbeans so I am not sure.

If you need more outputs than supported on one Pi, you can run multiple Pi's synced together using FPP MultiSync.

I am not sure how fast soft PWM can be on GPIO pins other than the built in GPIO pins on the Pi.  I am also not sure if the SoftPWM support in the wiringPi library can be used for anything other than the built in pins.  If it does then we can also look at converting the GPIO-595 output to use wiringPi's 595 support, right now I only use wiringPi to manipulate the Pi's pins directly.

We are working on getting a better doc system up and also have one user who has started on a manual.  I think our current plan is that the new doc system will be open to updating by users so we can get more contributors.

Thread posting or PM on here is probably the best method of communication for now.  I prefer to keep conversations like this on adding a new channel output in the public area so other users can benefit from the knowledge later.

Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #20 on: January 02, 2016, 08:11:52 PM »
Thanks for that. I'll build it on the Pi then if that's the way to go.

I've modified most of the files and am currently working out the best way to define the I2C addresses in the GUI. My thought is to simply replicate the interface for the GPIO 595 and instead of a dropdown with pre-filled values, have a text box where each MCP chip could be mapped to it's unique I2C address.

i.e.
Code: [Select]
#   |   Act   |   Type       |   Start Ch.   |   Ch. Count                                          |   Output Config
1   |    X    |   GPIO-MCP   |       1       |   <Auto populated when chip is selected - 8 or 16>   |  Chip Type - <Dropdown - Chip Select - MCP23008 or MCP23017> - Chip Address - <Textbox - I2C Address>

The tricky part would be where you have multiple chips with the Start Channel I think. Not especially hard, but forces the user to calculate the next Start Channel. Based on what I can see, the Start Channel is not dynamically populated based on the previous Start Channel + Channel Count? I might have a look at this also in due course.

I'm going to concentrate on this initially and then look at the PWM. It seems that we need to use wiringPi for the MCP chips anyway, hopefully getting a working model of the PWM won't be too difficult.

Any thoughts on the above?

Also, am I losing my mind - where is USEWIRINGPI defined - in a config file somewhere???
« Last Edit: January 02, 2016, 08:22:27 PM by powerfix »

Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #21 on: January 03, 2016, 04:43:04 AM »
Hey there,

Progress update.

I found the USEWIRINGPI variable - passed in the Makefile correct?

The GUI is complete, as well as the vast majority of code. I've got a logic issue that I'm working on now relating to the fact that in the GPIO.c it's a 1 to 1 relationship. But now, I've got a 1 to Many relationship which causes some grief on the initialisation and pin selection (as that is where m_GPIOPin is set in GPIO.c). I'm just trying to determine where/how the channel is sent in the data stream and how to grab it, convert it and output it.

Other than that, I've managed to successfully compile and run the new version, so I'll need some help on what the protocol is for submitting changes to GITHUB for review and hopefully inclusion in the next FPP version.

I've also discovered that there is an SPI version of the MCP chip - MCP23S08 and MCP23S17 which I'll attempt to add in when I receive the chip. Adding two of these onto the SPI pins should bring the Pi to an absolute maximum of 384 GPIO pins.

Cheers,

Craig.

Offline Bshaver

  • Developer
  • ******
  • Join Date: Aug 2014
  • Location: Denver, CO
  • Posts: 1,426
  • Kudos: 22
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #22 on: January 03, 2016, 09:14:09 AM »
Absolutely amazing! now with PWM control so you can dim channels as well? :)
Denver Colorado
45,000 blinky blinks mix of pixels and 130 AC Channels (powered by Minleon & Lynx) ALL Powered by FPP and Falcon!

Offline techathead

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 1
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #23 on: January 03, 2016, 02:52:29 PM »
I am willing and able to be a tester if needed. This is my first year in the hobby and I have a RPi2 with an 8 Channel Sainsmart SSR (ran this years display using Lightshowpi since I didn't have time to sequence once I decided to get my Griswald on). Excited to be able to help...

Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #24 on: January 03, 2016, 05:33:11 PM »
Absolutely amazing! now with PWM control so you can dim channels as well? :)

Unfortunately not just yet. Currently due to the learning curve, I'm currently still working on the logic issue as previous post.

And the more I look into the MCP specifications, the more I'm concerned that the speed is going to be an issue (max. 1.7Mhz apparently) with the MCP23008 and MCP23017. i.e. flickering lights. I'm yet to build a working model and will hopefully get something together shortly.

I doubt the MCP23S08 and MCP23S17 will have any issues as they are SPI based and run at 10Mhz.

So for my setup, I'm probably going to use the 128 channels of multiple  MCP23017's as my SSR GPIO's and then 256 channels of multiple MCP23S17's as the PWM RGB strands. For my config, this will be more than enough (i.e. 128 static strands + ~85 RGB PWM strands (SMD5050).

Then, for the pixels side I'll use the PixLite 16's. Hopfully FPP will cope with all of this, and if not, I'll simply split the channels to another (or more) slave RPi's.

Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #25 on: January 04, 2016, 08:07:44 AM »
I've managed to get a working circuit for software PWM working through the MCP23017 chip. As anticipated, there is much flickering as the speed is just too slow, and also each SoftPWM enabled pin consumes approx 4-5% of CPU. FPPD running with 4 single LED's equated to 26% CPU. I'm not sure how the SPI chip will fare either. Based on this testing, we could only use a max. of 10-15 LEDs (strings?) before topping out PWM on the Pi.

I suspect that I might have to invest in a dedicated hardware PWM chip and configure that also to achieve my goal.

I have, however, just remembered that I haven't got an inline MOFSET in the breadboard...more testing to do.


Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #26 on: January 04, 2016, 09:43:08 PM »
So a little more progress.

The MCP chips are working as expected using on/off only.

The PWM through wiringPi is still flickering. But to clear up my previous post, the CPU utilisation appears as below:

0 PWM GPIOs (idle) = ~2% CPU
0 PWM GPIOs (load) = ~24% CPU

16 PWM GPIOs (idle) = ~6.5% CPU
16 PWM GPIOs (load) = ~26% CPU

32 PWM GPIOs (idle) = ~12.5% CPU
32 PWM GPIOs (load) = ~31% CPU

I've also found another library for DMA based software PWM which looks far more promising - http://pythonhosted.org/RPIO/pwm_py.html and https://github.com/metachris/RPIO/tree/master/source/c_pwm. I'm certainly no expert, but the DMA implementation looks to be far quicker and basically zero load on the CPU with an (ahem) unlimited number of GPIOs enabled.

I'm currently building in this library to test it out - if the testing works well, I think it should be added to the core FPP rather than just my channel development. Seems to be pretty straight forward, although CaptainMurdoch may have other idea's/objections.

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,856
  • Kudos: 214
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #27 on: January 05, 2016, 12:57:42 AM »
What channel outputs do you have enabled, your load shouldn't be going up that high normally for the 0 GPIO stats.  From your stats, it looks like your CPU utilization per PWM GPIO is only about 0.22% since the difference between 0 GPIO and 32 GPIO is only 7% CPU utilization.

I looked through that pwm code, but don't see where it would work for the MCP chip.  Is it supposed to or does it just work with the built in GPIO on the broadcom chip?

You could possibly cut down on CPU usage by caching the previous channel data values and comparing them in RawSendData() so that you don't have to call softPwmWrite() again if a channel value hasn't changed from the last frame to the current frame.

Offline powerfix

  • Newbie
  • *
  • Join Date: Dec 2015
  • Location:
  • Posts: 14
  • Kudos: 0
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #28 on: January 05, 2016, 01:11:35 AM »
On the 0 PWM GPIO's I had a single MCP23017 configured in the outputs with 16 channels using digitalWrite instead of the PWM.

Yeah, I was also surprised at the 0.22% per GPIO so it may not be a linear 0.5% increase in CPU usage with the addition of more chips?

I've also gone through the code and found the same thing unfortunately. This is a noob talking, but can we not initialise the MCP chips using wiringPi (to obtain the standard GPIO pin numbers), then pass those pin numbers to the RPIO.PWM call? This is where I'm probably getting out of my depth...

I too have penciled in here to cache the previous values and only output the changed values, but my thinking is that shouldn't that be done higher up the heirarchy - in the base channel output? It would be beneficial across the board, not just for MCP chips?

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,856
  • Kudos: 214
Re: Raspberry Pi GPIO output direct to SSR board
« Reply #29 on: January 05, 2016, 01:23:05 AM »
If you left the 16 non-PWM outputs enabled, that seems to indicate that 32 PWM outputs used less CPU than 16 non-PWM.

The wiringPi GPIO pin numbers are just virtual numbers, wiringPi is talking to the i2c bus in the background, so you can't use the normal DMA code that is in the software pwm code you found.

The caching has to be done inside each individual channel output.  FPP's main channel output thread effectively calls each individual output's RawSendData() for every frame of data and the individual channel output code is responsible for sending the data it needs to send.  For the main channel output code to do the caching, it would have to call the individual channel output code (GPIO-MCP, GPIO, etc.) if any single channel changed so it would likely be called most of the time.  In the individual channel output, you can cache and eliminate softPwmWrite() calls on a channel by channel basis, sometimes only 3 channels might be changed so it would only be called for those 3, sometimes all 16 might change so softPwmWrite() would be called 16 times inside RawSendData(), and sometimes all channels might be unchanged, so there would be no calls to softPwmWrite().

 

Back to top