2

I'm planning to make a handbrake for my racing simulator (Assetto Corsa) and I wanted to know how can I transform arduino into a joystick so the game can read the analog input?

Thanks in advance, and sorry for my bad english.

ItsaMeTuni
  • 123
  • 3
  • You would need some sort of Human Interface working on your computer. A Leonardo should work but you would have to reprogram the HID interface so that it gets recognised by the PC as a Joystick. See [this page](http://www.arduino.cc/en/Tutorial/JoyStick) for some info on how to use the potentiometer joystick. – Stefa168 May 17 '15 at 21:05

2 Answers2

3

I made this video and github just for this about a year ago.

Breadboard

And here is the code:

/*
2-axis joystick connected to an Arduino Micro
to output 4 pins, up, down, left & right

If you are using pull down resistors, change all the HIGHs to LOWs and LOWs to HIGH.
This skectch is using pull up resistors.

*/

int UD = 0;
int LR = 0;
/* Arduino Micro output pins*/
int DWN = 13;
int UP = 12;
int LEFT = 11;
int RT = 10;
/* Arduino Micro Input Pins */
int IUP=A0;
int ILR=A1;

int MID = 10; // 10 mid point delta arduino, use 4 for attiny
int LRMID = 0;
int UPMID = 0;
void setup(){

  pinMode(DWN, OUTPUT);
  pinMode(UP, OUTPUT);  
  pinMode(LEFT, OUTPUT); 
  pinMode(RT, OUTPUT);

  digitalWrite(DWN, HIGH);
  digitalWrite(UP, HIGH);
  digitalWrite(LEFT, HIGH);
  digitalWrite(RT, HIGH);

  //calabrate center
  LRMID = analogRead(ILR);
  UPMID = analogRead(IUP);
}

void loop(){

  UD = analogRead(IUP);
  LR = analogRead(ILR);
  // UP-DOWN
  if(UD < UPMID - MID){
   digitalWrite(DWN, LOW);
  }else{
   digitalWrite(DWN, HIGH);
  }

  if(UD > UPMID + MID){
   digitalWrite(UP, LOW);
  }else{
   digitalWrite(UP, HIGH);
  }
  // LEFT-RIGHT
  if(LR < LRMID - MID){
   digitalWrite(LEFT, LOW);
  }else{
   digitalWrite(LEFT, HIGH);
  }

  if(LR > LRMID + MID){
   digitalWrite(RT, LOW);
  }else{
   digitalWrite(RT, HIGH);
  }

  delay(400);


}
PhillyNJ
  • 1,128
  • 3
  • 10
  • 20
  • This is not what I meant. I want to connect the arduino to my computer and use it to control the handbrake in my game. I want to make my computer recognize the arduino as a controller. But thanks for replying =D – ItsaMeTuni Aug 02 '15 at 23:53
  • You can use my example as a starting point. However I would assume you will need to create a customer driver for "Assetto Corsa". – PhillyNJ Aug 02 '15 at 23:57
  • Everything was just handed to you except for the PC side. Now you need to ask yourself: What does the game need for input: text? a logic signal? How can it receive input - through a serial port? The kbd only? Bluetooth? How can I provide that from what the Arduino and @PhillyNJ's code and diagram already make available - text messages to the serial port? Logic signals to RTS and DTR of 2 serial ports? Patch into the keyboard cable? (If your difficulty is on the PC side, this is probably not the right place to get help). – JRobert Oct 31 '15 at 18:40
0

Never tried it with the Arduino, but it's quite easy to do with Teensy (which is mostly compatible with Arduino).

Teensyduino actually includes several examples.

Melllvar
  • 101
  • 1