Mouse input, game pad output. Which board is best?

Hi all,

I’ve been searching Google and the forums for days, and I know the answer must be out there, but I must be searching for the wrong thing or not understanding the answers or something.

I’m a programmer, but an Arduino noob, so I’m enjoying Arduino coding, but I’m not great understanding the different boards, libraries and shields etc.

I want to plug a modern usb mouse in to a board, capture its X and Y, manipulate the data and then send the manipulated data to a PC, as if it’s the left stick of a game pad.

So my questions are:

  1. Is there a board that accepts standard USB mouse input. If so, which board and which library would give me a simple X & Y of what the mouse is doing, (buttons not necessary at this time). If not “just” a board, perhaps there’s a best board, shield, library combo to achieve the goal?
  2. Assuming I can then get my coding hands dirty, can I use the same board to output to PC as a game pad? Does this change the board I would require?

I don’t mind using multiple boards if it gets the job done.

Hmph. Sounds like I want you to figure out my project for me, but really any help at this point would be so gratefully received.

Best to all, Steve

For mouse input..

Maybe look into using a USB Host shield.

For sending HID (human input device) commands to a PC...

Maybe look into a:

  • Leonardo
  • Micro
  • Pro-Micro..

I havent messed with the mouse stuff in a while.. but years back.. there was some limit (on default libraries) that only allowed mouse movements in certain/limited increments... kinda fuzzy as this was a while back.

A more compact solution is a Teensy 3.6 or Teensy 4.1. Both have 1 USB host port (connect to USB mouse) and 1 USB device port (connect to PC). Teensy boards work with the Arduino IDE.

Thanks both for the replies.

So feasible then... that’s great news. More and more, I was seeing that Arduino wasn’t capable.

I already have a Leonardo on the way, and a shield in my box of bits, so that’s fab, but what the heck is a teensy!?! :smiley:

I’m getting one just cause of the name lol

In either of these solutions, is there a library that will just work “because it’s Arduino”, or is it more I have to get a library that’s specific to the device?

Thanks again both of you, your help has put a smile on my face already! :smiley:

Teensy.. well think of it as an Arduino on steroids!

MUCH more powerful! (and apparently some versions have a USB host port!) nice.

Search the Arduino IDE Library manager for "USB Host shield".

Joystick/gamepad libraries.

All the information about Teensy boards. pjrc also sells the USB host to 5 pin header cable.

https://www.pjrc.com/teensy/

Guys! I got it working! :smiley:

With a Leonardo with USB Host Shield. Turns out I had a defective Host Shield, which I was able to fix using these instructions:

Soon as I did that, my sketch started working!

#include <hidboot.h>
#include <usbhub.h>

#include <Joystick.h>
// Create Joystick
Joystick_ Joystick;
void updateXYAxis(unsigned int xAxis,unsigned int yAxis)
{  
  Joystick.setXAxis(xAxis);
  Joystick.setYAxis(yAxis);
}

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

class MouseRptParser : public MouseReportParser
{
protected:
 void OnMouseMove (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
    Serial.print("dx=");
    Serial.print(mi->dX, DEC);
    Serial.print(" dy=");
    Serial.println(mi->dY, DEC);
    updateXYAxis(mi->dX, mi->dY);
};

USB     Usb;
USBHub     Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE>    HidMouse(&Usb);

MouseRptParser                               Prs;

void setup()
{
    Serial.begin( 115200 );
    
    Joystick.setXAxisRange(-127, 127);
    Joystick.setYAxisRange(-127, 127);
    Joystick.begin();
    
    #if !defined(__MIPSEL__)
        while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    #endif
    Serial.println("Start");

    if (Usb.Init() == -1)
        Serial.println("OSC did not start.");

    delay( 200 );

    HidMouse.SetReportParser(0, &Prs);
}

void loop()
{
  Usb.Task();
}

Thanks for your help!