So this is a weird issue I have been trying to debug for a couple days. I've been trying to read mouse inputs using a USB host shield connected to a Arduino UNO for a project I'm working on however, I haven't been able to do much progress with the example codes offered by the USB Host Shield Library 2.0 because for some reason both mice I plugged in did not respond to the requests the code was doing. I already checked the voltages within the board using a multimeter and the shield is getting both 3.3volt and 5volt in, the VBUS and the voltage pin inside the usb connection itself and all of them output ~5v at more than enough power to make the mice function, one of them a 5v 20ma and another 5v 200ma, both wired. I have tried using other USB devices and using their example code but I got nothing. However the mice themselves noticed they were receiving power, turned on shortly before "turning back off" (I checked that by looking at the laser sensor beneath each mice and looking if it turned on, which it latter dimmed while connected to the shield).
I had a mechatronics friend help me out and their theory was that somehow the mice were receiving power and somehow not receiving data, and quickly powered down. I highly doubt the issue is with the code I'm using since I just copy and pasted some example code for a proof of concept that compiles perfectly using the libraries that were linked by the documentation page on the shield. But I will link it anyways in case some typo is screwing me over. I wasn't able to diagnose the problem myself so here I am hoping someone here can help me out
#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;dr:
- Shield is mounted properly
- Shield is soldered properly on the 3.3v in, 5v in and 5v out gates.
- Shield has 3.3v and 5v running within it
- USB port is receiving 5v power.
- Correct Libraries have been installed
- Code Compiles and uploads perfectly
- Serial bus communicates properly and can print anything that is not related to mouse-related parameters.
- Other USB devices also don't work
- Nothing has been damaged as far as I tested and know.
- Mouse and other devices do not turn on properly and do not seem to be sending any data to the - shield or board.