Go Down

Topic: Interfacing Arduino Uno Joystick with Windows for Mouse Movement (Read 600 times) previous topic - next topic

sawyersh

Hello all, first off, I apologize if this is the incorrect forum category for the following request.

History:

I have an Arduino Uno with which I have connected a 2-axis PS2 joystick.

I am attempting to move my Windows 10 mouse cursor via movements of the PS2 joystick.

Currently I have is connected via the COM7 port and have software running on the Uno that gives 3 outputs via the serial monitor: 0-1023 (x-axis), 0-1023 (y-axis), and 0-1 (push-button).

Now my question is: How, if it is possible, would I be able to make my Windows 10 PC recognize a change in the values from the COM7 port as movements of my mouse cursor.

I have seen other boards accomplish the same with micro usb connections, however I would like to do so with the current Uno/A B USB Connection.

Below is the code I have uploaded to the Uno:

// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(9600);
}

void loop() {
  Serial.print("Switch:  ");
  Serial.print(digitalRead(SW_pin));
  Serial.print(" | ");
  Serial.print("X-axis: ");
  Serial.print(analogRead(X_pin));
  Serial.print(" | ");
  Serial.print("Y-axis: ");
  Serial.print(analogRead(Y_pin));
  Serial.println(" | ");
  delay(200);
}

And below is the ouput from the Serial Monitor:

Switch:  1 | X-axis: 514 | Y-axis: 511 |
Switch:  1 | X-axis: 514 | Y-axis: 511 |
Switch:  1 | X-axis: 514 | Y-axis: 511 |
Switch:  1 | X-axis: 514 | Y-axis: 511 |
Switch:  1 | X-axis: 514 | Y-axis: 511 |
Switch:  1 | X-axis: 514 | Y-axis: 511 |


Thank you in advance.

pert

I have seen other boards accomplish the same with micro usb connections, however I would like to do so with the current Uno/A B USB Connection.
The type of USB socket on the board is irrelevant. It's about whether the microcontroller has native USB capabilities. The ATmega328P on your Uno does not.

If you have a real Arduino Uno or a faithful clone, then the ATmega16U2 microcontroller on the Uno can be reprogrammed with a special firmware that allows you to do this. Once of the options for doing that is here (with lots of information):
https://github.com/NicoHood/HoodLoader2

The other option is to use a program running on your computer that receives the serial communication and then translates it to mouse emulation. I have done things like this using a free open source program named EventGhost:
http://www.eventghost.net/

There are other options that will do the same, including just writing your own program. I suspect that autohotkey can do it, though I don't have much experience with that program:
https://www.autohotkey.com/

Go Up