所以这是一个奇怪的问题,我几天来一直在尝试调试。我一直在尝试使用连接到 Arduino UNO 的 USB 主机屏蔽来读取鼠标输入,用于我正在从事的项目,但是,我无法使用 USB 主机屏蔽库提供的示例代码取得太大进展2.0 因为由于某种原因,我插入的两只鼠标都没有响应代码正在执行的请求。我已经使用万用表检查了电路板内的电压,屏蔽板输入了 3.3 伏和 5 伏电压、VBUS 和 USB 连接本身内部的电压引脚,所有这些都以足够的功率输出 ~ 5 伏,足以使鼠标正常工作。功能,其中一个为 5v 20ma,另一个为 5v 200ma,均为有线。我尝试过使用其他 USB 设备并使用它们的示例代码,但我什么也没得到。然而,老鼠本身注意到它们正在接收电源,在“关闭”之前不久就打开了(我通过查看每只老鼠下方的激光传感器并查看它是否打开来检查,然后在连接到屏蔽时它会变暗)。
我有一个机电一体化朋友帮助我,他们的理论是,不知何故,老鼠正在接收电源,但不知何故没有接收数据,并很快断电。我非常怀疑问题出在我正在使用的代码上,因为我只是复制并粘贴了一些示例代码来进行概念验证,该代码可以使用盾牌上的文档页面链接的库完美地进行编译。但无论如何我都会链接它,以防某些拼写错误把我搞砸了。我自己无法诊断问题,所以我希望这里有人可以帮助我
#include <hidboot.h>
#include <usbhub.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
boolean LeftBtn = false;
boolean RightBtn = false;
boolean LeftBtnRls = false;
boolean RightBtnRls = false;
boolean MouseMoved = false;
int x;
int y;
class MouseRptParser : public MouseReportParser
{
protected:
void OnMouseMove (MOUSEINFO *mi);
void OnLeftButtonUp (MOUSEINFO *mi);
void OnLeftButtonDown (MOUSEINFO *mi);
void OnRightButtonUp (MOUSEINFO *mi);
void OnRightButtonDown (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
x = mi->dX;
y = mi->dY;
MouseMoved = true;
};
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
LeftBtnRls = true;
};
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
LeftBtn = true;
};
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
{
RightBtnRls = true;
};
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
{
RightBtn = true;
};
USB Usb;
USBHub Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);
MouseRptParser Prs;
void setup()
{
Serial.begin( 115200 );
#if !defined(__MIPSEL__)
while (!Serial);
#endif
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
HidMouse.SetReportParser(0, &Prs);
}
void loop()
{
Usb.Task();
if(MouseMoved){
Serial.print("dx = ");
Serial.print(x);
Serial.print(" dy = ");
Serial.println(y);
delay(500);
MouseMoved = false;
}
if(LeftBtn){
Serial.println("Left Button Pressed");
LeftBtn = false;
}
if(RightBtn){
Serial.println("Right Button Pressed");
RightBtn = false;
}
if(LeftBtnRls){
Serial.println("Left Button Released");
LeftBtnRls = false;
}
if(RightBtnRls){
Serial.println("Right Button Released");
RightBtnRls = false;
}
}
tl;博士:
您可以尝试使用外部电源,因为大多数 USB 端口仅提供 0.5 A