Project tutorial
How to Create a Joystick Controller with Arduino

How to Create a Joystick Controller with Arduino © CERN-OHL

Hi everyone, in this article we're going to make and build a pedal board and a sequential gearbox with Arduino Uno, making it a joystick.

  • 3 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

3drag
3D Printer (generic)

Apps and online services

About this project

How to create a joystick pedal with Arduino Uno + Sequential gearbox (Library UnoJoy)

Hi everyone, in this article we're going to make and build a pedal board and a sequential gearbox with Arduino uno, making it a joystick.

The project of the sequential gearbox can be found on Patreon, this is a special content to thank all the people who support me

We are going to build a controller that can be used on Steam. Steam is a platform developed by Valve that deals with digital distribution, digital rights management, multi-player and communication game modes.

I decided to carry out this project because I am a racing fan.

Since playing with the keyboard or with a joystick became more and more boring, I looked for a driving simulator on amazon but the prices were a bit high. For a few days I thought about how to make a driving simulator with lower costs and wandering around the internet I got an idea.

Now I'm here to show you, I hope you like it.

If you have any suggestions on how to improve this project, do not hesitate to contact me

If you also want to carry out the project there is more information on my website:

https://www.ingeimaks.it/come-creare-una-pedaliera-joystick-con-arduino-uno/index.html

Code

CODEC/C++
/* Arduino USB Joystick HID demo */

/* Author: Darran Hunt
  Released into the public domain.
  Update by RICLAMER in 25/03/2014 to use Analog ports and digital ports
  This code is to be used with Arduino UNO (6 axis and 13 Button )
  This code is compatible with Arduino Mega.
*/

/* INSTALATION
 Just install POT in each analog port. Using the _Grnd _Analog _5V Arduino.
 Like this image: http://arduino.cc/en/uploads/Tutorial/joy_sch_480.jpg
 To setup the buttons, just install you prefered button switch under GND and Port Digital 02~13.
 Use Flip to erease and burn this firmware DFU: https://github.com/harlequin-tech/arduino-usb/blob/master/firmwares/Arduino-big-joystick.hex
 I used Arduino R3 with Atmega 16U2.
*/

#undef DEBUG

#define NUM_BUTTONS  40             // you don't need to change this value
#define NUM_AXES  8        // 6 axes to UNO, and 8 to MEGA. If you are using UNO, don't need to change this value.

typedef struct joyReport_t {
 int16_t axis[NUM_AXES];
 uint8_t button[(NUM_BUTTONS + 7) / 8]; // 8 buttons per byte
} joyReport_t;

joyReport_t joyReport;

uint8_t btn[12];
int fulloff = 0;
void setup(void);
void loop(void);
void setButton(joyReport_t *joy, uint8_t button);
void clearButton(joyReport_t *joy, uint8_t button);
void sendJoyReport(joyReport_t *report);


void setup()
{
 //set pin to input Button
 for ( int portId = 02; portId < 13; portId ++ )
 {
   pinMode( portId, INPUT_PULLUP);
 }
 Serial.begin(115200);
 delay(200);


 for (uint8_t ind = 0; ind < 8; ind++) {
   joyReport.axis[ind] = ind * 1000;
 }
 for (uint8_t ind = 0; ind < sizeof(joyReport.button); ind++) {
   joyReport.button[ind] = 0;
 }
}

// Send an HID report to the USB interface
void sendJoyReport(struct joyReport_t *report)
{
#ifndef DEBUG
 Serial.write((uint8_t *)report, sizeof(joyReport_t));
#else
 // dump human readable output for debugging
 for (uint8_t ind = 0; ind < NUM_AXES; ind++) {
   Serial.print("axis[");
   Serial.print(ind);
   Serial.print("]= ");
   Serial.print(report->axis[ind]);
   Serial.print(" ");
 }
 Serial.println();
 for (uint8_t ind = 0; ind < NUM_BUTTONS / 8; ind++) {
   Serial.print("button[");
   Serial.print(ind);
   Serial.print("]= ");
   Serial.print(report->button[ind], HEX);
   Serial.print(" ");
 }
 Serial.println();
#endif
}

// turn a button on
void setButton(joyReport_t *joy, uint8_t button)
{
 uint8_t index = button / 8;
 uint8_t bit = button - 8 * index;

 joy->button[index] |= 1 << bit;
}

// turn a button off
void clearButton(joyReport_t *joy, uint8_t button)
{
 uint8_t index = button / 8;
 uint8_t bit = button - 8 * index;

 joy->button[index] &= ~(1 << bit);
}

/*
  Read Digital port for Button
  Read Analog port for axis
*/
void loop()
{ 
 

 /* Move all of the Analogic axis */
 /* Arduino UNO have only 6 port. Will be necessary set to 0; the not used port */
 /* In this example, i will use just 3 axis. X, Y, Z */
 /* if you will use all 6 analog ports, set axis < 3, to axis < 5 */





 for (uint8_t axis = 1; axis < 3; axis++) // 2 - A1 = Gas Pedal  
 {

   joyReport.axis[axis] = map(analogRead(axis), -180, 180, -32768, 32767 );

 }
 

 //Set to 0; the not used analog port.
 //if you will use all 6 analog ports, exclude the lines, axis[3] at axis [5] */
 //Report.axis[3] = 0;

// You need to ground A1 pin, because its the Y axis and if you dont use it, need to ground.

 
 joyReport.axis[5] = A1;
 joyReport.axis[7] = 0;
 joyReport.axis[8] = 0;

 //Send Data to HID
 sendJoyReport(&joyReport);

 delay(35);
 fulloff = 0;
}

Schematics

Comments

Similar projects you might like

Joystick Controller for MeArm Robot - Recording Coordinates

Project tutorial by utilstudio

  • 8,070 views
  • 6 comments
  • 27 respects

Arduino Joystick

Project tutorial by Ingeimaks Ingeimaks

  • 6,881 views
  • 5 comments
  • 17 respects

BLE Haptic Dual Joystick Controller

Project showcase by Leon Chu

  • 2,123 views
  • 0 comments
  • 0 respects

Outboard Motor Throttle Controller

Project tutorial by Terry Towle

  • 7,389 views
  • 3 comments
  • 15 respects

Circuito Arduino Controller Pad

Project tutorial by AhmedAzouz

  • 3,790 views
  • 1 comment
  • 9 respects

Raise the Volume with Remote Controller

Project tutorial by Gabriele00111

  • 1,243 views
  • 1 comment
  • 2 respects
Add projectSign up / Login