简体   繁体   English

使用 c 或任何编程语言控制 USB 端口上的电压供应

[英]Controlling voltage supply on usb port using c or any programming language

I don't have much konwledge in electronics.我没有太多的电子知识。 i wanted to turn on/off led connected to usb port using program.我想使用程序打开/关闭连接到 USB 端口的 LED。 usb port consists 4 line (data+,data-,voltage ,ground) if i connect voltage and ground lines to led , it will glow. USB 端口由 4 条线(数据+、数据-、电压、地)组成,如果我将电压和地线连接到 LED,它会发光。 i've been searching on internet this issue and i find that it is not possible to control led connected to usb using program because supply over datapin is too low which can not be used to tun on off led.我一直在互联网上搜索这个问题,我发现无法使用程序控制连接到 USB 的 LED,因为通过 datapin 的供应太低,无法用于关闭 LED。

but what if i connect my led to vol and ground pin and control the entire power supply of usb port , i guess it is possible to control led using program.但是如果我将我的 LED 连接到 vol 和接地引脚并控制 USB 端口的整个电源,我想可以使用程序控制 LED。 there is a way to disable and enable power supply over usb port.有一种方法可以通过 USB 端口禁用和启用电源。

i also want to know is it bad to follow this approach.我也想知道遵循这种方法是否不好。 does it damage usb controller to frequently enable/disable power supply.频繁启用/禁用电源是否会损坏USB控制器。

Algo :

      a = Get_input_from_user() ;
      if(a=="ON")
           turn power supply of usb port ON.
          else
           turn power supply of usb port OFF.

this thing is certainly possible using extra hardwares, i don't want to use any extra hardware.这件事当然可以使用额外的硬件,我不想使用任何额外的硬件。

The power for a computer's USB ports is generally not software controllable.计算机 USB 端口的电源通常不是软件可控的。 In most cases, the power pins of your USB ports are wired directly to the 5V rail of your power supply (usually through a polyfuse), so there is no way to switch them on and off.在大多数情况下,USB 端口的电源引脚直接连接到电源的 5V 轨(通常通过多保险丝),因此无法打开和关闭它们。

Some powered USB hubs do support switching power to their ports , but you said that you didn't want to use any extra hardware, so you're out of luck. 一些有源 USB 集线器确实支持将电源切换到它们的端口,但是您说您不想使用任何额外的硬件,所以您不走运。

you can use any basic Arduino board to do this there is a complete IDE free and a LOT of sample code that will do what you want out of the box您可以使用任何基本的Arduino板来执行此操作,有一个完整的免费IDE和大量示例代码,可以立即执行您想要的操作

阿杜诺在此处输入图片说明

you can also use a COOL board.您也可以使用 COOL 板。

青少年 3.0

Arduino Compatible code is available for the Teensy Arduino 兼容代码可用于青少年

Software Development Tools HERE软件开发工具在这里

You can use an external power supply ( the Vcc and GND pins of the USB port in this case ) with a resistor to power the diode and connect a transistor in the middle working as interruptor.您可以使用带有电阻器的外部电源( the Vcc and GND pins of the USB port in this case )为二极管供电,并在中间连接一个晶体管作为中断器。 Then, yo connect the base and emisor to de data+ and data- of the USB port.然后,将底座和发射器连接到 USB 端口的 de data+ 和 data-。

this page doesnt let me upload images.这个页面不允许我上传图片。

Sorry for the quality of the drawing but all I have on the computer is paint.对不起绘图的质量,但我在电脑上只有油漆。 For a more stable performance make sure to make R1 low enough so that transistor is on saturation mode when data pins are ON but not so low that transistor gets burnt (I dont really know what is the voltage level of the data pins on the USB port, sorry).为了获得更稳定的性能,请确保使 R1 足够低,以便在数据引脚打开时晶体管处于饱和模式,但不要低到晶体管被烧毁(我真的不知道 USB 端口上数据引脚的电压电平是多少, 对不起)。 To choose a proper value of R2, you need to know the current you need to power your diode.要选择合适的 R2 值,您需要知道为二极管供电所需的电流。 It's calculated acording to Ohm law:根据欧姆定律计算:

Idiode = (Vcc - Vce,sat - Vd) / R2.

Where Vce,sat is potencial diference between colector and emisor when transistor is on saturation mode (it is found on the transistor datasheet on the manufacturer webpage, usually around 0.2V) and Vd is the normalized potencial difference of the diode (the same, but this time around 0.6V).其中 Vce,sat 是晶体管处于饱和模式时集电极和发射器之间的电位差(可在制造商网页上的晶体管数据表中找到,通常约为 0.2V),Vd 是二极管的归一化电位差(相同,但这次大约为 0.6V)。

Note that data- and GND pins are connected.请注意,数据引脚和 GND 引脚已连接。 I am 99% sure that this won't harm your USB port, but use it at your own risk.我 99% 确信这不会损害您的 USB 端口,但使用时风险自负。

I would test it out using another external power source first anyways, just to make sure you connected everything properly.无论如何,我会先使用另一个外部电源对其进行测试,以确保您正确连接了所有东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用C或C ++编程来改变USB两端的电压并检测USB两端的电压变化 - How can I vary voltage across USB & detect varying voltage across usb using programming in C or C++ 使用Linux和C编程控制RF遥控器 - Controlling an RF remote using Linux and C Programming 如何使用C语言程序通过计算机的USB端口打开/关闭电灯泡 - How to on/off an electric bulb via computer's usb port using C language program 使用C语言的串口(USB-RS232)的read()问题 - Problems with read() of a Serial Port (USB-RS232) using C language 使用 GCC 或任何其他编译器的 C 编程语言中的编译指示和预定义宏之间是否有任何关系? - Is there any relation between pragma and predefined macros in C programming language, using GCC or any other compiler? 如何将Tcpreplay添加为C语言或任何其他编程语言的库? - How to add Tcpreplay as a library in C language or any other programming language? USB编程:C / Linux - USB Programming: C/Linux 使用C编程语言而不是Arduino处理 - Using C programming language instead of Processing with Arduino 使用 c 编程语言尝试 3 次密码屏蔽 - password masking with 3 attempts using c programming language 使用C#和C语言进行USB到串行(往返)通信 - USB to Serial (to and fro) communication using C# and C language
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM