SainSmart 4 Channel USB Relay Web Controlled
This post is about how to remote control the SainSmart 4 Channel USB Relay Module through a web browser with a Raspberry Pi and NodeJs - Express. This should be a very simple project, but it was not there is very little programing information available on the Web for the SainSmart 4 Channel USB Relay Module. It took a week of experimenting just turn the relay ON/OFF.
Now have access to the SainSmart 4 Channel USB Relay Module, it took another day to create a Web APP with NodeJs - Express. The SainSmart 4 Channel USB Relay Module can now be Web controlled though a Browser or as a Simple Ham Radio Remote PlugIn.
How to Access the SainSmart 4 Channel USB Relay Module
For those who are interested in writing there own interface with NodeJs - Express.
The first thing to do is install the D2XX Driver. The Raspberry Pi requires the "Hard-Float" Driver there are three available Here.
- 1.4.24 ARMv6 hard-float
- 1.4.24 ARMv7 hard-float
- 1.4.24 ARMv8 hard-float
Which one for your Raspberry Pi?
From a Raspberry Pi Terminal enter:
Command-> uname -m
Reply-> armv7l
For this Raspberry Pi will install "1.4.24 ARMv7 hard-float" driver.
Download the D2XX Driver
- cd ~/
- Available Driver:
# ARMv6 hard float
sudo wget https://ftdichip.com/wp-content/uploads/2021/09/libftd2xx-arm-v6-hf-1.4.24.tgz
# ARMv7 hard float
sudo wget https://ftdichip.com/wp-content/uploads/2021/09/libftd2xx-arm-v7-hf-1.4.24.tgz
# ARMv8 hard float
sudo wget https://ftdichip.com/wp-content/uploads/2021/09/libftd2xx-arm-v8-1.4.24.tgz
- Extract the Drive:
# ARMv6 hard float
sudo tar xzvf libftd2xx-arm-v6-hf-1.4.24.tgz
# ARMv7 hard float
sudo tar xzvf libftd2xx-arm-v7-hf-1.4.24.tgz
# ARMv8 hard float
sudo tar xzvf libftd2xx-arm-v8-1.4.24.tgz
Next: Install the Driver.
- cd /home/pi/release/build
- sudo -s
- cp libftd2xx.* /usr/local/lib
- chmod 0755 /usr/local/lib/libftd2xx.so.1.4.24
- ln -sf /usr/local/lib/libftd2xx.so.1.4.24 /usr/local/lib/libftd2xx.so
- cd ..
- cp ftd2xx.h /usr/local/include
- cp WinTypes.h /usr/local/include
- ldconfig -v
- exit
Next: Check if ftdi_sio module is running.
- sudo lsmod | grep ftdi_sio <- Check if ftdi_sio module is running if it is
- sudo rmmod ftdi_sio <- uninstall this
- sudo rmmod usbserial <- Possibly this
- To reverse the operation the kernel modules can be reloaded using [ modprobe ] instead of rmmod.
Test the Driver...
- cd /home/pi/release/examples
- make -B
- cd EEPROM/read
If you have a FTDi USB Relay plugged in then run.
If you see the Device info then FTDI Driver is installed...
Made it through the Driver install Next...
Tried to access the SainSmart 4 Channel USB Relay Module using Python, Java, Bash no luck. Started searching for a package for NodeJs found:
- npm install ftdi - Here <- Would not install.
- Tried many npm install ftdi packages finally found:
- npm install ft245rl - Here
But it said "It relies on the ftdi package: ftdi" which would not install. Finally got ftdi installed but require("ftdi") would not load it. Installed a new Raspberry Pi .img on SD card started all over again.
This time only used package: ft245rl Here. It had a a sample test page Here. which said "relies on the ftdi package".
Installed the "node-FT245RL-test" project on the Raspberry Pi ran "npm install" then ran "node index.js" and 3.30am in the morning three Relays on the SainSmart USB 4 Channel Relay Module click ON. Wow!
Now have access to the SainSmart 4 Channel USB Relay Module, can create an APP with NodeJs - Express. Still have not figured out how to get the status of all the relays.
Conclusion
There is not allot of detailed information on how to access these USB Relay modules.