Jump to content

I Created A Sainsmart (Cheap Relay Board) Driver


Recommended Posts

I have a small cab with no Ledwiz.   With the release of the new Whirlwind table, I just had to have a fan.    The cheapest path was a 12V attwood 4000 fan and a cheap SainSmart 12V 4-port relay board.   I might have just splurged on a ledwiz, but it appeared I'd need some kind of booster board to deal with the higher amperage of a fan.    

 

I downloaded the DOF sources and it's delightfully well organized and documented.   It was a relative snap to create a driver based on a  SainSmart c# sample someone else wrote.      

 

I had a lot more trouble configuring DOF than I did writing a driver, LOL.   The config test tool needs you to start with an XML config that's not provided.   Found one somewhere on a forum, but then the config editor won't actually let me save changes (it complains about something being out of range).   My plugin and its outputs were showing up nicely, but it wasn't finding my ledcontrol.ini until I explicitly specified its location in the cab config file.    Then the line for Whirlwiind's fan relay showed up in the config tool (good) and I could turn my fan on and off (yay!).

 

Then I tried to get it working on a table.   I had trouble getting B2S to find the plugin.  The documentation says to put it in a "plugins" folder but it the b2s server seems to want it in a "plugin" folder.    I kept fighting with that for a while, the plugins button was grayed out when I'd click on the backglass options.    After a lot of trial and error I got it going, but I'm not even really sure what it was that fixed it.   It's working now, that's all that matters.  

 

Anyhow, if anyone has interest in a SainSmart output driver for el-cheapo toy control, let me know and I'll be happy to share. 

 

 

 

 

 

 

Link to comment
Share on other sites

The SainSmart relay driver boards are a nice item ... they come in all flavors ie: 5v, 12v, solid state and mechanical, 1, 2, 4, 8, 16 port variety. I am using a off brand from china (eBay) with my LedWiz and it is working great. Price is very low and quality seems good. I am glad to see some alternative development other than the standard use items. Great work

Sent from my SAMSUNG-SGH-I747 using Tapatalk

Link to comment
Share on other sites

I have the 4-port 12V USB version, the code should work with the 8 port model too.

 

I've attached the compiled DOF, sources, and working config files from my cabinet.     The readme is below.   Please let me know if you have any questions.

 

 

SainSmart DOF Output Driver
Submitted by DJRobX - 1/24/2014

ABOUT
-----

This is a version of the Direct Output Framework with an added output driver for inexpensive SainSmart relay boards.  I wanted to add fan and shaker support to my small cab, and didn't want the expense of the LedWiz and booster boards needed to support higher amperage devices.   The SainSmart boards are about $20!   The only negative is that they click on and off briefly a couple times during boot.  
 
It currently only supports one board.  The beginnings of support for multiple SainSmart boards is there (it should enumerate them), but as I only have one, there's not much point in fleshing that out as I can't debug it.    I also suspect that if you have another USB device that uses the FTDI serial driver, this code will pick them up as SainSmart relay boards.  Source code is included if you need to make adjustments!

CREDITS
-------

Thanks to the following:
Swisslizard for his excellent DOF framework, making this integration possible!
http://directoutput.github.io/DirectOutput/index.html

Anthony Marshall for his SainSmart C# sample code
http://antmarshall.wordpress.com/2013/02/06/sainsmart-5v-usb-relay-board-c-source-code/

FTDI for the driver and C# wrapper
http://www.ftdichip.com/Drivers/D2XX.htm
http://www.ftdichip.com/Support/SoftwareExamples/CodeExamples/CSharp.htm

USAGE
-----

Please see the DOF framework site for more information on configuring DOF if this is your first time.

I've included my working global and cab configs.  Here's a high level summary of how this works:

1) Create a custom configuration for your cab. here:
http://vpuniverse.com/ledwiz/login.php
This is where you can assign your physical toys (i.e. Whirlwind fan to Relay Port 1).  This produces a ledcontrol.ini file for you.

2) Install DOF.   Please follow the instructions here.  http://directoutput.github.io/DirectOutput/installation.html.     

3) Prepare the config files.   I've provided working samples from my cab in the "config" subfolder.   In my global config file, there is a section that references the location of the ledcontrol.ini produced in step 1.   Reading the documentation and instructions others have posted, it seems I should not need to do this, but DOF wasn't able to find it on my system without it no matter where I put it.    

These config files specify a custom "toy" that is a "ledwiz emulator" of sorts (lets you assign SainSmart 1 to Ledwiz 1, which is connected to the .INI file instep 1).    This custom device requires custom configs to be present.

4) You can use the DirectOutputConfigTester tool to confirm that your configs are good.   If everything is in place, you should be able to pick a table/ROM and see the devices that will be controlled show up.  There are buttons where you can manually control them to see that they work.
 

SOURCE CODE
-----------

The sources for the SainSmart output are provided.   Get the current sources from https://github.com/DirectOutput/DirectOutput/.     You simply need to add the included SainSmart files to the appropriate place in the project (you can see the path in the source - it goes in DirectOutput\Cab\Out\SainSmart).  In visual studio, click 'show all files' so you can right click on the SainSmart folder and include it in the solution.   You'll also need to add a reference to the FTD2XX_net.dll file (included in the binary).  You don't need to change any of the existing source files, they seem to automatically detect the presence of the new driver module.

My changes are completely free for any sort of use, modification, or re-release.

 

 

 

 

DOF-Sainsmart.zip

Link to comment
Share on other sites

I notice the omron SSRs on those relay modules are not rated for DC current. Is that a problem? I'm considering buying one of these, but If it's going to fail because it's designed for AC loads, I think I'll stick with the mechanical relay modules.

Link to comment
Share on other sites

I notice the omron SSRs on those relay modules are not rated for DC current. Is that a problem? I'm considering buying one of these, but If it's going to fail because it's designed for AC loads, I think I'll stick with the mechanical relay modules.

.

.

I'm sorry I might have linked to incorrect listing. Please use the search feature and make sure you put DC .... "X port SS relay board Yvolts DC" where X is the number of port you are looking for and Y is the voltage. I have had trouble finding 12v 8 port boards from time to time.

Sorry for the confusion

Sent from my SAMSUNG-SGH-I747 using Tapatalk

Link to comment
Share on other sites

Sainsmart makes a bunch of USB mechanical relay boards.  That is what this DOF module will control directly.  Ledwiz is not needed.   There's 4 and 8 port versions, and they need +5 or +12V to power them up.     The 5V varieties can apparently be modified to self-power from USB but they don't come that way.

 

The exact one I'm using is:

 

http://www.ebay.com/itm/SainSmart-12V-4-Channel-USB-Relay-Board-Automation-Module-4-Arduino-Robotics-AVR-/281027911107?pt=LH_DefaultDomain_0&hash=item416e919dc3

 

This uses the SRD-12VDC-SL-C relay.  The code should also work with the 8 port and 5v varieties.

Link to comment
Share on other sites

Yes, I am using it for a 12v shaker and a 12v fan.      The relay appears to support up to a 10A draw, up to 28V DC. 

 

I'm currently using a 9V 2A wall wart to the relays (I've also tried 12V versions, which work, but both are stonger than I like).    I'm sure there are better options.   I'm using the PC PSU to provide the board itself with power (VCC/GND).   

Link to comment
Share on other sites

  • Content Provider

That page describes a lighting system connected to an Arduino.    If I had an Arduino I might just buy a relay that I can connect directly to one of the Arduino's outputs.     Then again the USB SainSmart board is so cheap that it probably doesn't matter.  

 

The trick with making that light kit work with pinball is, of course, making an Arduino output driver for DOF.     Probably wouldn't be hard to do, based on what I saw doing the SainSmart driver.   That particular project only seems to be able to set the strand of lights to a particular color (it's a bus of lights with only 3 outputs: R, G, B connected to the Adruino).    

 

-- Rob  

Link to comment
Share on other sites

  • Content Provider

Yes but my programming knowledge is as much as I can read the words of the script.

 

The idea is to use that adalight system, with or without a relay, to work with the backglass monitor, so the ambient lighting matches that screen (that's why I think it's neat) but with a relay powering it on/off, it could instead flash in tune with the table lighting while also giving ambient backlighting. It's not really something that's been done but it sounds neat. 

Link to comment
Share on other sites

I see.   That's sort of like the undercab lighting option in the ledwiz config.     Yes, you could in theory send the wires from the +5VDC 2A wall power supply through one of the Sainsmart relays and let the adalight system otherwise do its thing.    I'd just check to see if the Adalight software works with multiple monitors, I imagine it would work better if it only picks up what's on the backglass display.  

Link to comment
Share on other sites

  • Content Provider

@DJRobX:

 

This is excellent. Thanks for the contribution. I will have a look at your source as soon as possible and integrate your drive into the official DOF release. Unfortunately, I got some time constraints at the moment, since I'm quite budy with some "real world" freelance projects.

Link to comment
Share on other sites

Sounds great, swisslizard.      Thanks again for your great work with this project.  

 

The only thing I'd want to add before going into the trunk is to ensure there's a way to disable the driver.   It's a simple device based on a generic FTDI serial chip, so there's a good chance the detection routine can pick up something that's not really a Sainsmart board.  

Link to comment
Share on other sites

Yes, I am using it for a 12v shaker and a 12v fan.      The relay appears to support up to a 10A draw, up to 28V DC. 

 

I'm currently using a 9V 2A wall wart to the relays (I've also tried 12V versions, which work, but both are stonger than I like).    I'm sure there are better options.   I'm using the PC PSU to provide the board itself with power (VCC/GND).   

This seems like a great solution to work as an add-on as I'll be hooking up a LEDWiz, but all ports will be taken up and I'd love to have a fan.

 

Would you mind giving a quick write-up or diagram on how you did the wiring?  I'm learning fast, but I'm still somewhat electrically challenged :P

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
  • Create New...