I know this is a subject that has been done to death, But! I'm adding some(sorta) details/guide and this is not another gamepad/mouse/ductape rip apart/mashup, my mod uses an Arduino Leo and I'm including the code I hammered together, by no means am I a programmer or coder, I'm just a construction worker who loves his trucking sim and wanted to share my work in that it may help others who also want a better and more comfortable sim experience. Research and build only took me a weekend to do, so any one with some/little soldering/electronics/computer/reading-comprehension skillz should be able to do this as well with out too much frustration or need of hand holding, I'm no expert and even an old dog like me could do it and in the end I feel this something one can pat them selfs on the back for a good effort and experience. One thing to note is the way the code works every button is read as single press, so no press and hold .i.e when filling up at a petro station you will have to hold down the enter key on your keyboard but that is the only time reach for the keyboard well playing every thing else I can work from my custom dash.
[ external image ] [ external image ]
Parts needed are momentary normally open buttons/switches, I have 22 plus one momentary three-way switch which is used for parking and trailer brakes. Hot glue and cardboard is what I used to put together the "dashboard" and used a cheap black plastic filefolder as covering/finish and a cheap ipad stand to help support the back of the dashboard so there is no flex or movement when pressing the buttons. Lots of wire to connect things up of course. For the custom shifter knob I replaced the original G27 knob with one I made my self from an old golf ball, I used a drill bit and exacto knife to carve out the profile of the G27's shifter shaft shape(half-round) till it snugly friction fit on top, then carved out notches for where my shift button and switch would sit and hot glued into place, a trick to shaping hot glue is have a cup of ice water on hand and dip your fingers in and you can smooth out the glue with your hands like that polymorph stuff( I think it may just be hot sticks in pellet form) then to finish things off I used some fabric glue and some black fabric to cover the knob to make it less fugly. When running the shifter wire though the G27, the plastic collar on the leather shift boot needed a little bit of shaving with a nail file to make space for the wires to come down nicely and hidden inside the controller base for clean finish.
[ external image ] [ external image ] [ external image ]
Now for wiring and programming, the Arduino Leonardo is fairly cheap(ebay $9) and easy to use and learn plus the Leo can be a USB device like a joystick, mouse or in our case a simple keyboard so it makes this mod compatible with both ETS2 and ATS or other driving/racing sims, best of all no drivers really needed so it work with any OS.
[ external image ] [ external image ]
In my setup I have used all inputs on the Arduino (FYI the analogue ports can be digital inputs too, pin numbers change in code) The two shifter buttons have their own input pins and the rest is wired up in a matrix, the code and wiring info mostly all came from a blog post I found by some one named Kevin Peat, so credit goes to him and here is the link http://www.kevinpeat.com/arduino_button_box.html. There is a ton info online about arduino so I'm not going to go into any details about installing, flashing wiring all the pins, if a dumb old contractor like myself can figure it out any one else should be able too.
Here is the code that is uploaded to the arduino, its mostly strait forward, there is an array with the keyboard codes that match up to the button matrix, I'll point the code segments.
Code: Select all
#include <Wire.h>
#include <HID.h>
#include <Keyboard.h>
/*
* -------------------------------------------------------------------------
* Arduino Button Box
* -------------------------------------------------------------------------
* Copyright Kevin Peat 2014
* kevin@kevinpeat.com
* This sketch is licensed public domain
* -------------------------------------------------------------------------
* Original code provided by Dan Nixon on his blog
* Multiplexing Switches on Arduino without additional ICs
* http://www.dan-nixon.com/2012/04/multiplexing-switches-on-arduino.html
* -------------------------------------------------------------------------
* Requires an Arduino Leonardo or other similar device that is able to
* emulate a USB HID Keyboard
* -------------------------------------------------------------------------
* Hardware to be used with iRacing and other racing sims. The simple
* hardware design means that only one button can be pressed at a time
* which is not a problem for this type of hardware. Also there is no need
* for key modifiers so only simple key presses can be sent.
* -------------------------------------------------------------------------
*/
/*
* -------------------------------------------------------------------------
* Arduino Leonardo key codes
* -------------------------------------------------------------------------
0 = 0x30
1 = 0x31
2 = 0x32
3 = 0x33
4 = 0x34
5 = 0x35
6 = 0x36
7 = 0x37
8 = 0x38
9 = 0x39
a = 0x61
b = 0x62
c = 0x63
d = 0x64
e = 0x65
f = 0x66
g = 0x67
h = 0x68
i = 0x69
j = 0x6A
k = 0x6B
l = 0x6C
m = 0x6D
n = 0x6E
o = 0x6F
p = 0x70
q = 0x71
r = 0x72
s = 0x73
t = 0x74
u = 0x75
v = 0x76
v = 0x76
w = 0x77
x = 0x78
y = 0x79
z = 0x7A
' = 0x27
, = 0x2C
- = 0x2D
. = 0x2E
/ = 0x2F
; = 0x3B
= = 0x3D
[ = 0x5B
] = 0x5D
~ = 0x7E
# = 0xE0
F1 = 0xC2
F2 = 0xC3
F3 = 0xC4
F4 = 0xC5
F5 = 0xC6
F6 = 0xC7
F7 = 0xC8
F8 = 0xC9
F9 = 0xCA
F10 = 0xCB
F11 = 0xCC
F12 = 0xCD
BACKSPACE = 0xB2
DELETE = 0xD4
ESC = 0xB1
HOME = 0xD2
INSERT = 0xD1
RETURN = 0xB0
SPACE = 0x20
TAB = 0xB3
LEFT_ARROW = 0xD8
RIGHT_ARROW = 0xD7
UP_ARROW = 0xDA
DOWN_ARROW = 0xD9
* -------------------------------------------------------------------------
*/
// Array of pins for the columns
int cPins[] = {2, 3, 4, 5};
// Number of pins in the column array
int cPinsNo = 4;
// Array of pins for the rows
int rPins[] = {8, 9, 10, 11};
// Number of pins in the row array
int rPinsNo = 4;
// Array for the last known switch states [cPinsNo][rPinsNo]
int colPrev[4][4] = {0};
// Key codes to be used for each button
// (see table above for codes to use)
// (columns and rows are transposed on device)
uint8_t buttonCodes[4][4] = {
{0xC4, 0xC3, 0x67, 0xC7},
{0x69, 0x72, 0x74, 0xC6},
{0x20, 0xCC, 0x75, 0xC2},
{0x65, 0x6D, 0xB0, 0xB1}
};
void setup()
{
//Shifter buttons internal pull up for pins 6 & 7
pinMode(7, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
//Start Serial
Serial.begin(9600);
//Serial.println("Multiplexed Buttons Test");
//Set the Column Pin Mode
//Serial.println("Setting Column Pins...");
for(int cPin = 0; cPin < cPinsNo; cPin++)
{
pinMode(cPins[cPin], OUTPUT);
digitalWrite(cPins[cPin], HIGH);
}
//Set the Row Pin Mode
//Serial.println("Setting Row Pins...");
for(int rPin = 0; rPin < rPinsNo; rPin++)
{
pinMode(rPins[rPin], INPUT);
digitalWrite(rPins[rPin], HIGH);
}
//Serial.println("Ready!");
}
void loop()
{
// Check shifter switches
if (digitalRead(7) == LOW) {
//Button one is pressed!
Keyboard.press(0x78);// Xx = 0x78
delay(150);
Keyboard.release(0x78);
delay(150);
}
if (digitalRead(6) == LOW) {
//Button two is pressed!
Keyboard.press(0x7A); // z = 0x7A
delay(150);
Keyboard.release(0x7A);
delay(150);
}
// Loop through the columns
for(int cPin = 0; cPin < cPinsNo; cPin++)
{
digitalWrite(cPins[cPin], LOW);
// Loop through the rows
for(int rPin = 0; rPin < rPinsNo; rPin++)
{
//Check if each switch is pressed
if(digitalRead(rPins[rPin]) == LOW)
{
// Check to see if the state has changed since last time
if(colPrev[cPin][rPin] == 0)
{
// Do action here, switch is on
//Serial.print(cPins[cPin]);
//Serial.print(", ");
//Serial.print(rPins[rPin]);
//Serial.println(" ON");
Keyboard.press(buttonCodes[cPin][rPin]);
delay(150);
Keyboard.release(buttonCodes[cPin][rPin]);
// Update last known state of this switch
colPrev[cPin][rPin] = 1;
}
}
else {
// Check to see if the state has changed since last time
if(colPrev[cPin][rPin] == 1)
{
// Do action here, switch is off
//Serial.print(cPins[cPin]);
//Serial.print(", ");
//Serial.print(rPins[rPin]);
//Serial.println(" OFF");
// Update last known state of this switch
colPrev[cPin][rPin] = 0;
}
}
}
digitalWrite(cPins[cPin], HIGH);
}
}
Code: Select all
uint8_t buttonCodes[4][4] = {
{0xC4, 0xC3, 0x67, 0xC7},
{0x69, 0x72, 0x74, 0xC6},
{0x20, 0xCC, 0x75, 0xC2},
{0x65, 0x6D, 0xB0, 0xB1}
Code: Select all
//Shifter buttons internal pull up for pins 6 & 7
pinMode(7, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
// Check shifter switches
if (digitalRead(7) == LOW) {
//Button one is pressed!
Keyboard.press(0x78); // Xx = 0x78 edit the part in brackets
delay(150);
Keyboard.release(0x78); // Xx = 0x78 edit the part in brackets
delay(150);
}
if (digitalRead(6) == LOW) {
//Button two is pressed!
Keyboard.press(0x7A); // Zz = 0x7A, edit the part in brackets
delay(150);
Keyboard.release(0x7A); // Zz = 0x7A, edit the part in brackets
delay(150);
Here is the lines that needs edit just change the "z" and "x" to what keycode you use in the arduino code
Code: Select all
config_lines[270]: "mix gearsel1tgl `keyboard.z?0`"
config_lines[273]: "mix gearsel2tgl `keyboard.x?0`"
[ external image ]
Cheers!