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.

sainsmart -usb-4-channel-relay-module -web-controlled-raspberry-pi-simple-ham-radio-remote

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.

sainsmart-usb-relay-module-web-controlled-raspberry-pi-nodejs-express-simple-ham-radio-remote

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. 1.4.24 ARMv6 hard-float
  2. 1.4.24 ARMv7 hard-float
  3. 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

  1. cd ~/
  2. 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

  3. 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.

  1. cd /home/pi/release/build
  2. sudo -s
  3. cp libftd2xx.* /usr/local/lib
  4. chmod 0755 /usr/local/lib/libftd2xx.so.1.4.24
  5. ln -sf /usr/local/lib/libftd2xx.so.1.4.24 /usr/local/lib/libftd2xx.so
  6. cd ..
  7. cp ftd2xx.h /usr/local/include
  8. cp WinTypes.h /usr/local/include
  9. ldconfig -v
  10. exit

Next: Check if ftdi_sio module is running.

  1. sudo lsmod | grep ftdi_sio <- Check if ftdi_sio module is running if it is
  2. sudo rmmod ftdi_sio <- uninstall this
  3. sudo rmmod usbserial <- Possibly this
  4. To reverse the operation the kernel modules can be reloaded using [ modprobe ] instead of rmmod.

Test the Driver...

  1. cd /home/pi/release/examples
  2. make -B
  3. cd EEPROM/read

If you have a FTDi USB Relay plugged in then run.

  • sudo ./read
  • 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:

    1. npm install ftdi - Here <- Would not install.
    2. Tried many npm install ftdi packages finally found:
    3. 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.

    Links

    1. SainSmart 4 Channel USB Relay Module
    2. Controlling a USB Relay with a Raspberry Pi
    3. Preparing the Raspberry Pi
    4. Sainsmart USB Relay
    Simple Ham Radio Remote

    Home | Cookies | Terms of Use | Privacy Policy

    Last updated: 12/06/2023
    sd
    This site uses cookies. By continuing to use this website, you agree to their use.