通过软件控制 USB 灯
我有一个 USB 供电的小灯。我希望能够用软件打开和关闭它。我将把它连接到 Linux 计算机上。我有一个来自 上一个项目,但我宁愿通过简单的修改来完成此操作,而不是重新调整我的微控制器的用途。
这可能吗?我怀疑这无法完成,因为计算机不会与没有某种 USB 兼容固件的设备通信?
我发现这个问题,它有一个评论建议OP使用LM317稳压器来改变USB输出的电压。我认为这不适用于我,但我想我会提到它。
更新:
看起来我可以将 USBtiny 放在我的微控制器上,然后我可以将它连接到灯上,然后我可以编写一个应用程序来控制控制器。不过,听起来工作量很大。我宁愿做一个简单的 hack,但我缺乏 USB 经验。
I have a little USB-powered light. I'd like to be able to turn it on and off with software. I'll be attaching it to a Linux computer. I have an Atmel ATtiny2313 from a previous project, but I'd rather do this with a simple hack than repurpose my microcontroller.
Is this possible? I suspect this can't be done as the computer won't talk to a device without some kind of USB-compliant firmware?
I found this question, which has a comment suggesting that the OP use an LM317 voltage regulator to change the voltage of the USB out. I don't think this is applicable to me, but thought I'd mention it.
Update:
Looks like I could maybe put USBtiny on my microcontroller, then I could wire it up to the light, then I could write an app to control the controller. Sounds like a lot of work, though. I'd rather do a simple hack, but I lack experience with USB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您最好的选择可能是购买 FTDI 接口电缆之类的东西,可以从 Digi-Key 购买,价格为 20 美元。这为您提供了+5、地线和四根电线,您可以在软件控制下切换高电平或低电平。如果您将其用作具有 rx/tx/rts/cts 的逻辑级串行端口,则该软件是最简单的。制造商部件号为 TTL-232R-5V-WE(访问 digikey.com 并在部件搜索框中输入该编号)。 Digi-Key 提供了制造商数据表和网站的链接。
Your best bet is probably to buy something like an FTDI interface cable, available from Digi-Key for $20. That gives you +5, ground, and four wires you can switch high or low under software control. The software's easiest if you use the thing as a logic-level serial port with rx/tx/rts/cts. The manufacturer part number is TTL-232R-5V-WE (go to digikey.com and type that number into the part search box). Digi-Key has links to the manufacturer data sheets and web site.
我认为这是不可能的,因为 USB 上的电源 (Vcc) 线始终处于开启状态——它并不是一条控制线。
除非您的 USB 灯已经提供了一种通过 USB数据 进行自身控制的方法,否则您就不走运了。我不建议尝试更改 USB 电源线的电压。
I don't think it is possible, because the power (Vcc) line on USB is always-on--it is not intended to be a control line.
Unless your USB light already provides a way to control itself via USB data, you are out of luck. I do not recommend trying to change the voltage of the USB power line.
也许您可以告诉 USB 控制器切断 USB 端口的电源。我在我的电脑的省电设置中看到了这个选项。
Maybe you can tell the USB controller to cut off power to the USB port. I've seen this option on the power saving settings on my PC.
我将使用基于 PL-2303 的USB/串行桥和运行 USB 堆栈的 ATtiny2313 微控制器 -可能是USBtiny。它的工作原理如下:
我将考虑对其进行接线,以便有一些在某些输出上安装电阻器,这样我就可以将灯设置为不同的亮度,如果我想做图案或任何东西,我会在软件中完成它们。
I'm going to use my PL-2303-based USB/serial bridge and an ATtiny2313 microcontroller running a USB stack--possibly USBtiny. It'll work like this:
I'll look into wiring it so there are some resistors on some outputs so I can set the light to different brightnesses, and if I want to do patterns or anything, I'll do them in software.
我想这可以通过计算机打开/关闭 USB 端口的功能来节省电池。经过令人惊讶的简短搜索后,我发现了另一个与此相关的问题:
控制USB电源(开/关)与linux
虽然我还没有尝试过。如果有效,请告诉我们!
I guess this could be possible using the computer's ability to switch on/off the USB ports to save battery. After a surprissingly short search I found another question regarding that:
Controlling a USB power supply (on/off) with linux
Though I have not tried it. Please let us know if it worked!
从技术上讲,这并不能回答您的问题,而是提出了替代方案。
我刚刚找到了 BlinkStick。他们销售 USB RGB LED(开放硬件)以及开源 API 库,允许您通过代码控制它。
它使用 ATTiny85 作为控制器,其固件基于 V-USB,您可以自己构建(提供原理图)。
然后,通过下载该应用程序,它会公开与相当多编程语言兼容的API。
Technically this does not answer your question, but rather proposes an alternative.
I just found BlinkStick. They sell a USB RGB led (open hardware) along with an open source API library that allows you to control it by code.
It uses as controller an ATTiny85 with firmware based on V-USB that you can build yourself (schematics are available).
Then by downloading the application it exposes an API compatible with quite some programming languages.
是否可以重新连接 USB 连接器,以便将 USB 灯的电源连接到 USB 端口的数据,而不是连接到 VCC?
然后也许你可以控制它并指定它是 0 伏还是 5 伏。
不确定这是否可能,我对 USB 一无所知。
Would it be possible to rewire the usb connector so that instead of being connected to VCC the power of the usb light would be connected to the data of the usb port?
Then maybe you could control that and specify if it was 0 or 5 volts.
Not sure if that's even possible, I know nothing about usb.
USB 是一种通用总线,需要驱动程序以及如何使用它的说明。它具有更大的灵活性,但同时所有逻辑都应该存储在某个地方(驱动程序/应用程序/等),这并不容易“可扩展”,例如 Windows、Linux、电话等...所有这些都需要不同的应用程序并管理...不幸的是,它无法在本地启用/禁用 USB(例如管理输出电源,因为它主要在 BIOS 级别进行管理,而操作系统级别并不完全可用 - 实际上检查你的主板是否支持 IPMI - 这是一个管理工具,在较低级别上工作,但大多数仅在服务器类型的硬件上可用)
我有类似的打开/关闭灯的需求,但更多的是用于指示。我的用例:我们有一个办公室,负责销售、支持等工作……电话并不常见,但当电话到位时,最好保持安静。而且由于人们使用相同的耳机来听音乐 - 从侧面看你无法了解通话是否正在进行......
所以,想法是:
如果一切顺利 - 可以在顶部添加一些集中管理(所有灯光都可以在系统中注册(例如 WebSocket 或 google pub /sub 用于集中管理),这种情况下,可以通过电话系统集中方式远程触发,例如:如果有来电,灯可以在来电时开始闪烁以引起注意,并在来电时自动打开。呼叫就位...加上可以以类似的方式完成 Google Meeting、Zoom、计算机上的任何其他应用程序)
PS:很高兴能找到类似的任何现成的东西...但是哦,好吧 -目前还没有任何发现。
USB is a universal bus that required drivers and a description of how to work with it. It has greater flexibility, but same time all logic should be stored somewhere (drivers/app/etc) and this is not easy "scalable" such as Windows, Linux, Phone, etc... all required different apps and manages... And unfortunately, it's no way to enable/disable USB locally (like manage outgoing power, since mostly it's managed on BIOS level, which is not fully available from OS level - actually check your Mother Board if it's supporting IPMI - it's a management tool which works on the lower level, but mostly available only on Server type of hardware)
I have similar needs of turning on/off light, but more for indication. My use case: we have an office with sales, support, etc... calls are not often, but when they are in place it's better to keep being quiet. And since people are using the same headsets for listening to music - from the side you can't understand if the call is in progress or not...
So, the idea is:
If all will be good - some centralized management can be added on top (all light can be registered in the system (such as WebSocket for example, or google pub/sub for centralized management). In this case, it can be triggered remotely by a phone system in a centralized way, such as: if incoming call - light can start blink to get attention when the call is in place and automatically turn on when the call in place... plus can be done the similar way for Google Meeting, Zoom, any other app on the computer)
PS: will be good to find anything ready-to-go like that... but oh, well - for now nothing has been found.