Search code examples
cembedded-linuxlibusbrelayusbserial

How to controll relay (one channel) connected to USB port in Linux?


How to controll relay (one channel) connected to USB port in Linux?

This pic ilustrate the usb cable connection. Relay connected to usb cable

When connect relay to usb port the relay set on continuosly. But when execute lsusb in terminal, the system not find the device.

lusb output before connection:

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 1358:c123  
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 13d3:56f9 IMC Networks 
Bus 001 Device 004: ID 27c6:5110  
Bus 001 Device 003: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 002: ID 0458:0189 KYE Systems Corp. (Mouse Systems) 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

lusb with device connected:

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 1358:c123  
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 13d3:56f9 IMC Networks 
Bus 001 Device 004: ID 27c6:5110  
Bus 001 Device 003: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 002: ID 0458:0189 KYE Systems Corp. (Mouse Systems) 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

[UPDATE]

this is the output of dmesg:

[ 3975.045806] usb 1-3: new low-speed USB device number 23 using xhci_hcd
[ 3975.657743] usb 1-3: new low-speed USB device number 24 using xhci_hcd
[ 3976.801721] usb 1-3: new low-speed USB device number 25 using xhci_hcd
[ 3977.345746] usb 1-3: new low-speed USB device number 26 using xhci_hcd
[ 3977.761777] usb usb1-port3: unable to enumerate USB device

Thankyou for any suggestions.

Greetings!


Solution

  • Except for the fact, that we do not see your code, I strongly doubt, that this setup is going to work the way you intended.

    Assuming this is USB 2.x the signal lines (white) will have a voltage level of 0V to 400 mV, while the power line (red) operates at 5V against GND(black). I strongly doubt, that this is within the specs of your relay.

    Even if it is, you can not easily steer one of the signal lines from operating system level as you need some abstraction layer in between. The normal OS drivers can not work with your setup as they expect a controller at the other end of the line doing USB standard compliant stuff like enumeration, speed and current settings, etc. For your OS this is just a cut off line plugged into USB port.

    The approach your looking for might be the following:

    A OS application on your PC is connected to a microcontroller via USB or Serial-USB-Adapter. The Microcontroller recieves simple commands via this connection and in turn sets and resets his I/O pins. Those I/O pins are level-driven and fed into your relay. Depending on your relay you need some amplification in between the microcontroller and the relay.

    If you're really sure your hardware setup can work, please include a detailed description, including electrical levels, used USB port, datasheet of the relay and the code you're trying to run.