Read Mouse Input from Arduino Giga R1 WiFi USB

I'm new to Arduino so I'm trying to wrap my head around the Arduino rules. Can someone point me to the right direction please? I am trying to read mouse input from the Arduino Giga R1 WiFi and I'm not quite clear how I'm supposed to achieve that. What library/command do I use? Appreciate any guidance.

Hi @arduinoob99. It looks like the developers made at least a start at adding mouse support to the alpha stage "USBHostGiga" library:

I notice that, even though the added an example sketch for keyboard, they didn't do the same for mouse, which I take as a sign the implementation is not yet complete.

I wrote a simple test sketch to check:

// Print the mouse position and button values to Serial Monitor
#include <USBHostGiga.h>

REDIRECT_STDOUT_TO(Serial)  // Uncomment this to get debug information
Mouse mouse;

void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  Serial.println("Starting...");
  pinMode(92, OUTPUT);
  digitalWrite(92, HIGH);  // Power the USB-A connector
  mouse.begin();
}

void loop() {
  if (mouse.available()) {
    Serial.println("Mouse data available!");
    auto mouseData = mouse.read();
    Serial.print("x: ");
    Serial.println(mouseData.x);
    Serial.print("y: ");
    Serial.println(mouseData.y);
    for (byte buttonIndex = 0; buttonIndex < sizeof(mouseData.buttons) / sizeof(mouseData.buttons[0]); buttonIndex++) {
      Serial.print("button ");
      Serial.print(buttonIndex);
      Serial.print(": ");
      Serial.println(mouseData.buttons[buttonIndex]);
    }
  }
}

I do see that the mouse I connected to the USB-A port on the Giga board is powered and recognized:

USB Device Connected
USB Device Reset Completed
PID: c00eh
VID: 46dh
Address (#1) assigned.
Manufacturer : Logitech
Product : USB-PS/2 Optical Mouse
Serial Number : N/A
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Device remote wakeup enabled
Switching to Interface (#0)
Class    : 3h
SubClass : 1h
Protocol : 2h
Mouse device found!
HID class started.

But Mouse::available() never returns a non-zero value even when I move the mouse and press the buttons. So I'm not sure whether I did something wrong or if the library doesn't yet have mouse support as suspected.

Maybe it will at least will give you a starting point though.

@ptillisch this is awesome. I wasn't expecting an example. Thanks so much. This will definitely get me going in the right direction :smile:.

1 Like

Got the same issue here, giga can detect the mouse but can’t read data from it, any idea how to make it work?

Hi @zisarduino. I haven't done any further work with connecting a mouse to the USB host port of the GIGA R1 WiFi board since the time I wrote my previous reply so unfortunately the information I posted here is everything I know on the subject.

Hopefully one of the other forum helpers will be able to provide assistance.

1 Like

Job done. Actually the Keyboard demo works with mouse. The uint8_t keys[2] and keys[4] carries mouse x/y info.

1 Like