Code Monkey home page Code Monkey logo

arduinoxinput's Introduction

Arduino XInput Library

arduino-library-badge Build Status

This library lets you easily emulate an Xbox 360 controller using a USB-capable Arduino microcontroller.

Getting Started

void setup() {
	XInput.begin();
}

void loop() {
	XInput.press(BUTTON_A);
	delay(1000);
	
	XInput.release(BUTTON_A);
	delay(1000);
}

Before the library will work, you must install a compatible boards file that contains the XInput USB descriptors, otherwise the microcontroller won't behave like an XInput device. This is not optional. See the compatible boards section below for more information.

After installing a compatible boards package, you must then download and install the library. Once the XInput library is installed, open up the Arduino IDE and load an example sketch, located in File -> Examples -> XInput (I suggest trying the 'Blink' sketch first). Double-check that you have the correct XInput board and/or XInput USB type selected in the 'Tools' menu, then upload the sketch to your microcontroller.

On Windows, you can test that the sketch is working properly by opening up the joystick control panel (joy.cpl) or by using HTML5 Gamepad Tester. If you uploaded the XInput 'Blink' example, the #1 button ('A') should be slowly turning on and off.

Control Surfaces

The library gives you access to the following controls available on the Xbox 360 controller:

  • 10 + 1 Digital Buttons
  • 2 Analog Joysticks (16 bit)
  • 2 Analog Triggers (8 bit)
  • 1 Four-Way Directional Pad (D-Pad)

For the full list of control names as used in the library, see the source files.

The library also processes received data, so you can read the status of the controller's 2 rumble motors (8-bit), the assigned player number (1-4), and the index of the current LED animation. Data is sent and received automatically over USB.

Compatible Boards

To function as an XInput device, you must use a compatible boards package with XInput USB descriptors. This is not optional. Without these descriptors the library will only function in "debug" mode and the microcontroller will not behave as an XInput device.

The following boards packages are available:

  • Modifies the Arduino AVR core to emulate an XInput device. Includes support for the Arduino Leonardo, Micro, Yun, and more.

  • Provides support for the MaKey MaKey, Pro Micro, Fio, Qduino Mini, and LilyPad USB Plus. Requires the XInput AVR Core boards.

  • Includes an 'XInput' USB mode for the Teensy 3.1, 3.2, 3.5, 3.6, LC, 4.0, 4.1, and MicroMod. Requires a preexisting Teensyduino installation.

For a complete list of available packages and compatible boards see the 'supported boards' file. For information on how to add support for another Arduino-compatible board with native USB support, see the documentation on the USB API.

Console Support

Please be aware that none of the currently available board packages support connecting to the console itself. Genuine controllers use a dedicated hardware security chip that handshakes with the console. Arduinos do not have this chip, and its security method has not been (openly) broken.

License

This library is licensed under the terms of the MIT license. See the LICENSE file for more information.

arduinoxinput's People

Contributors

benjaminvanryseghem avatar dmadison avatar wheybags avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduinoxinput's Issues

Joystick and XInput in same board, but not at the same time.

I've got a project in which I would like my Teensy 3.6 to switch between acting as an XInput device and a regular Teensy HID Joystick. Unfortunately, this is not possible with the board provided by the library. The difference with this issue is that only one of the two options will be active at once. Is that possible with some changes to the library, or is it a USB limitation?

ATmega16u2

Hi,
I'm thinking of using ATmega16u2 for my small controller which I hope would works like an xbox360 controller with only one switch and tow led's.
Could you give me suggestions about which files I would need to modify in your XInput library ?
Thank you.

Cannot get board to appear as controller in Windows

I'm using an Arduino Leonardo R3 with version 1.2.5 of XInput downloaded from the library manager. I've uploaded the blink sketch and even one of my own and neither seem to make the device appear as a controller in windows 10. Checking in the device manager, I see it appear on COM5, the sketch uploads successfully and I can see the debug output in the serial monitor if I open it, but it will not show up in windows. Please let me know if I'm doing something wrong.

System Info

Windows version

  • Edition Windows 10 Enterprise
  • Version 20H2
  • Installed on ‎2021-‎03-‎23
  • OS build 19042.867
  • Experience Windows Feature Experience Pack 120.2212.551.0

Board Version

  • Arduino Leonardo R3

Upload log

Custom sketch being uploaded

#include <XInput.h>

// Declare vars
const uint8_t aButt = 3;
const uint8_t bButt = 4;

void setup() {
  // Start XInput library and set pins
  XInput.begin();
  Serial.begin(9600);
  pinMode(aButt, INPUT_PULLUP);
  pinMode(bButt, INPUT_PULLUP);
}

void loop() {
  boolean aState = !digitalRead(aButt);
  boolean bState = !digitalRead(bButt);
  XInput.setButton(BUTTON_A, aState);
  XInput.setButton(BUTTON_B, bState);
  delay(50);
}

Serial Monitor Output

image

Arduino DUE support

Not an issue but a request: could this project extend the compatibility to include arduino DUE board?

Thanks for the great piece of code!

Analog trigger not working

Hi. First of all great work. I have been making a custom controller and I am using a potentiometer to use as analog trigger for a throttle. The potentiometer has a spring that keeps it into a resting position at about half value.
First I have tried to use the demo code and just test 4 buttons + the trigger using https://gamepad-tester.com/. While the buttons are fine, the website does not receive any trigger input. I checked the debug mode and in the serial monitor the Right trigger has a value in between 70 and 150 when I move the variable resistance.

Since I want it instead to have a value in between +40 and -40 I tried to change the min-max value in the code
XInput.setTriggerRange(-40, +40);
and also biasing the analog value by 110:
int triggerLeft = analogRead(Pin_TriggerL) - 110;
This did not work and the serial monitor shows a constant 255 value.

Is there any way to archive this?

Using keyboard capability

Hi,
Did you think that it's possible to use Arduino keyboard default library with xinput on the same controller ?
Thank's

BUTTON_LOGO Does Not Result in Any Button Press

Using XInput.setButton() with BUTTON_LOGO as the first argument does not do anything.
To test, I first used known working code to confirm my hardware configuration was correct:
XInput.setButton(BUTTON_X, setX);
Then, without changing any other configuration, I replaced this call with the following:
XInput.setButton(BUTTON_LOGO, setX);
I would expect this to result in the same behavior as the Xbox button or home button being pressed on a standard controller, but I am unable to observe any button presses using online testers on PC or on Nintendo Switch via an XInput adapter.

Possibly related: #46

I'm getting double (ghost) presses sometimes.

Sometimes when using my arcade sticks have double presses on directions, which is kinda inconvenient.
I can notice it specially browsing through EmulationStation menus.
I'm using Arduino Pro Micro.

I'm aware of other libraries based on DInput that allow for a debounce, but this library doesn't seems to have that option.
Could it be implemented?
Thank you for this amazing library.

incompatible with platformio

Hi, while this library is listed as compatible with platformio it is impossible to actually setup the board profile to allow a board like the Pro Micro to be seen as a XInput controller using platformio (along with their only officially supported ide - Visual Studio Code). It seems like having a platform.json file in the https://github.com/dmadison/ArduinoXInput_SparkFun would fix this incompatibility.

XInput.h not found

Error message:

C:\Users\andre\Blink\Blink.ino:31:10: fatal error: XInput.h: No such file or directory
 #include <XInput.h>
          ^~~~~~~~~~
compilation terminated.

exit status 1

Compilation error: XInput.h: No such file or directory

Code (selected from examples):

#include <XInput.h>

void setup() {
	XInput.begin();
}

void loop() {
	XInput.press(BUTTON_A);
	delay(1000);

	XInput.release(BUTTON_A);
	delay(1000);
}

Installed https://github.com/dmadison/ArduinoXInput_AVR
installed 1.2.6
selected as board Arduino Micro w/ XInput

Stop emulation

Hello I’m a beginner at coding and I wanted to know if there is a command to stop emulation like Xinput.end() Ora way to do that

Raspberry Pi Pico support

Hello, not an issue but a feature request: would it be possibile to port this library to raspy Pi Pico?
Thanks :)

Is it possible to get a callback for when XInput samples the controller?

It's not clear to me from public docs how XInput works exactly, at the hardware level. It seems like it's either going to sample when the user samples input (it being a sampling based API), or sample at a fixed framerate and then pass the current state to the user when they request it from XInput .

Is it possible to get either of these as a callback?

It seems like this is necessary to reduce the lag of the controller and make it consistent. e.g. if XInput is sampling in 8 ms blocks of time, sending the last 8 ms of state means your lag is 0-8 ms.

If you were instead sampling every 8 ms and sending that with the current API, your input delay could be 0-16 ms. Even sampling at 1 ms and sending that means your lag is 0-9 ms which would be worse than if you could just get that sample callback time.

Adafruit ItsyBitsy/other boards?

Hey, I took a look at the API and really couldn't wrap my head around working it out for Adafruit boards (ItsyBitsy in my case). Is this board planned to be added anytime soon?

Multiple XInput Devices from a single dev board

First of all, thank you for this project. It has been immensely useful for me.

I was wondering, is there a way to have a single board (a Teensy 4 in my case) to act as more than one Xinput device with this library? If so, is there any documentation anywhere you could point me to?

Thank you.

Can XINPUT Receive Serial1 Command?

I'm using an Arduino Leonardo (ATMega32U4). My test code is designed to receive serial command from the HW Serial1 port and translate it to Xbox controller inputs. However when Serial1 commands are sent, no controller inputs is detected by the Gamepad Tester. With my troubleshooting right now, I'm looking at the possibility that the XINPUT library and board manager prevents Serial1 from working. Thus, it's not properly receiving and interpreting the Serial1 commands.

Would anyone be able confirm my theory or know more about it?

Question: USB serial read and xinput

Hello, I would like to have my leonardo receive serial messages from the USB port. Those messages should then trigger xinput button presses.
Can someone please confirm that with Xinput device emulation active is still possible to receive serial messages via Serial.read?
Thanks in advance!

Will there be support for ESP-32 ?

I have an Espressif ESP-32 that basically runs Arduino library and code.
Is there a way to make this library work for an ESP-32? I tried adding your library to my ESP-32 project but there was #preprocessor #error because my ESP-32 board isn't one of the boards you support.

Arduino Leonardo port not found under port tab, but seen as a controller on device page.

I wanted to test out the code, so I uploaded it to the device, and when I tried to open the serial monitor, it did not open. then I selected the port and it was not there. So I proceeded to reset the bard and unplug it, but it still did not work. I even tried burning the bootloader with a UNO as ISP. but no luck.

and as I said, I cant see it in ports, but I see it on the device manager page in settings as a controller.

I believe it is because of the library, because, there was another issue on the Arduino forums about the problem, with the Xinput. So please help.

Reprogramming

Hi,
Is there a way to reprogram the board via USB a second time in /w Xinput config or do I have to use an external programmer ?

not detected + reset not working?

so right now, my micro "successfully" flashes without pressing the reset twice
"avrdude done. Thank you."

but it isn't detected by windows, and when it's uploading it doesn't stop, i'd used to flash another board and on the uploading it stops and that's where you double click reset, now this one, it doesn't. if i do double click either it has an error or does nothing.

psv analog stick support

with this xinput driver, the X-axis and Y-axis of psv analog stick are always between 0 to 60, not 0-100. Is there anything I can do to make the stick working from 0 to 100?

2 key 1 function

I am making a arcade stick for all games(not only fighting games)
I am trying to put one function(like L3) to two different keys
but It does not work, If I write code like that, one key became disable...
Is there anyway to do this?

Joystick drift

I have a full set of buttons and 2 joysticks to emulate a full xbox controller for use with a raspberry pi. To test the buttons, I'm plugging it into my windows computer. Every button works but the right joystick does not. The right joystick has a constant drift, while the left works fine. Even with the right joystick unplugged from the Teensy LC board, the drift continues. Any ideas on what might be causing this drift?

Xbox One compatibility

I was wondering if this arduino library is compatible with xbox one console, so can I emulate a controller directly connecting it on the console or is it only compatible with pc?

Teensy 4.0 Support

Hi, is Teensy 4.0 support for this library possible? If so, is it planned to be implemented by anyone?

Toggle left/right analog stick

New to all this, greatly appreciate your code and all your hard work.

Is there a way to use a switch to toggle a single joystick between left or right stick.

USB Descriptors for Arduino Due and MKR family?

As of current, none of the MKR family (Due, Zero, etc.) are not supported by the XInput library. I am assuming that the main library does not need to be edited. But that USB descriptors for the Native USB port can exist to mimic an Xbox 360 controller.

I recently picked up Due thinking it was supported since it had a specific Native USB that can be used to mimic the Keyboard and Mouse but since there are no descriptors, I cannot use it as an XInput device.

Question Regarding the LIBRARY'S FUNCTIONALITY

Hello I have some past Arduino project experience but using others libraries, never written my own.

I am planning to build a personal arcade cabinet and the options on the market for USB encoders aren't as feature packed as it would be If I made my own.

I have no detailed knowledge about Xinput USB descriptors.

My question about the library is whether I could have the Arduino board function as Xinput using your Library and be able to switch modes in the code to be a keyboard HID. I'm hoping that you would know more about that side of usb drivers and all that black magic.

Basically even if I like .begin or .end the Xinput from your library, are there things in the background that would keep it from also functioning as a keyboard with another keyboard HID library installed to your knowledge?

Thanks for making this library also!

Window 10

My Teensy is not recognized on Window 10

In Xbox 360 Controller for Windows property,

"This device can not be started. (Code 10)

There is not enough system resources to complete the API."

Board : Teensy LC
USB Type : Xinput
CPU Speed : 48 MHz
Optimize : Smallest Code
Programmer : AVRISP mkll

Do not speak English well.. Thank you for your help

Please move the USB_XINPUT checks to the header file

I suggest you move the USB_XINPUT checks from XInput.cpp (line 29 to 55) to XInput.h, because I want to use it on an Arduino Uno R3, so I created a firmware for the atmega16u2 and a .h file that implements the XInputUSB api. I would like to use it like this:

#include "MyHeader.h" // define USB_XINPUT
#include <XInput.h>

But right now it doesn't work because XInput.cpp doesn't take the MyHeader.h file into account.

PlatformIO build_flags

It is in PlatformIO's list of libraries but the build flags seem a mystery. I've tried
build_flags = -D X_INPUT
USB_XINPUT
XINPUT
USB_APIXINPUT
XInputUSB_API
etc etc (the last 2 are what it offered for autocomplete so I rolled with it)

Either refuses to compile (USB_XINPUT, which seems to be the sensible option), or throws no errors but lsusb shows the teensy as a serial device.

Is this just a no-go or is there something I'm missing?

return XInputUSB::connected(); ^ .pio/libdeps/teensy31/XInput/src/XInput.cpp: In member function 'int XInputController::send()': .pio/libdeps/teensy31/XInput/src/XInput.cpp:444:9: error: 'XInputUSB' has not been declared return XInputUSB::send(tx, sizeof(tx)); ^ .pio/libdeps/teensy31/XInput/src/XInput.cpp: In member function 'int XInputController::receive()': .pio/libdeps/teensy31/XInput/src/XInput.cpp:453:6: error: 'XInputUSB' has not been declared if (XInputUSB::available() == 0) { ^ .pio/libdeps/teensy31/XInput/src/XInput.cpp:459:24: error: 'XInputUSB' has not been declared const int bytesRecv = XInputUSB::recv(rx, sizeof(rx)); ^ Compiling .pio/build/teensy31/FrameworkArduino/HardwareSerial1.cpp.o *** [.pio/build/teensy31/libe15/XInput/XInput.cpp.o] Error 1 ========================== [FAILED] Took 1.78 seconds ==========================

Compile on Arduino IDE 1.8.8 fails

Hi,

I'm trying to use your library with a Pro Micro but i get a compilation error:

cc1.exe: error: -fno-fat-lto-objects are supported only with linker plugin.

Any hints?

Thank you.

Question : Use this package without access to Arduino Reset Button?

Hello,

I'm using an LBX, a Leonardo Arduino based controller, I bought online. I was trying to use this package to get the controller to pretend it's an Xbox Controller; but I don't have access to the Arduino reset button.

I read in the ArduinoXInput_AVR repo that I can't upload INO files unless I have access to the reset button. But in this repo, the ArduinoXInput repo nothing implies that I do need to reset the Arduino during the upload process. Are there wrappers in this package that means I no longer have to reset the Arduino during the upload?

Using XInput.press within GamepadPins

I have been testing my home made joystick with your lib and it works great! Had no problems following your guide. The Blink example (XInput.press/release) works fine, and GamepadPins too.

I am trying to add a "Turbo" button within a sketch based from GamepadPins (even reverted to the original example and just try to add a press/release). It seems the press/release command that works fine alone (Blink) is not effective within GamepadPins. Probably because buttons were mapped differently but I cannot figure out how to do it.

Blink code:

XInput.press(BUTTON_A);
delay(1000);

XInput.release(BUTTON_A);
delay(1000);

Thank you!

Emulate multiple XInput controllers

Hey,

As far as I could see, the library only allows to emulate one controller at a time.
Is it techically possibile and how hard would it be to emulate more? Do you have any hints how to achieve it?

Thanks

esp32 support

Hello,would it be possible to support to esp32?
Thanks^O^

Where is XInputUSB?

Just trying to "reverse engineer" XInput for use with AVR in Atmel Studio, and I stumbled apon your library.

I'm looking over the code but I don't see where XInputUSB is defined(the class), its driving me nuts! Can you help me out man.

Reading XInputUSB_API.md, and it says something about this just being one part of it, the library part.
So where is The Backend, and The USB API, am I missing something?
Does that mean the Backend, and USB API would be something like LUFA?

Thanks

Edit: Are we supposed to create XInputUSB on our own?

Edit2: Nevermind, its included with board files in another repo. The link is in the bottom of XInputUSB_API.md for anyone else wondering.

Working on some android phones, but not for all

I have successfully built a gamepad for my android phones, I tested xiaomi, LG, razer phones. It works on LG and xiaomi 5, but not xiaomi 6 and razer phone 2. Is that because the android version?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.