Need help to create a sketch for my new racing wheel

Hello,

I’m creating my new sim racing steering wheel. My wheel is composed by:

  • 2 micro switches for shifters
  • 9 buttons composed by 3 button modules wired in 3X3 matrix.
  • 1 rotary switch 4 positions 2 stages
  • 1 separate 3 button module

My choice to limit the number of device is to have a rotary switch to select MAP, TC, ABS and Brake Balance and 2 buttons + and - to increase/decrease the value of the selected function. It is to avoid to have additionnal 4 encoders

I was unable to integer this wiring to a button matrix.

I have coded and loaded the matrix in my pro micro and it works fine.

As i’m new in Arduino coding, i need your help to add the additional code for the buttons which are not part of the matrix.

I precise that each button is corresponding to a joystick button.

I have attached the wiring of my wheel.

Regards,

Didier

Steering wheel wiring.pdf (190 KB)

Hello,

I have forgotten to add my code for the matrix 3x3

//BUTTON BOX
//USE w ProMicro
//Tested in WIN10 + Assetto Corsa
//AMSTUDIO
//20.8.17
// modified by Did 29.09.20
// Matrix 3X3 + 3 buttons + 2 rotary switch 4 positions

#include <Key.h>
#include <Keypad.h>
#include <Joystick.h>

#define ENABLE_PULLUPS
#define NUMBUTTONS 9
#define NUMROWS 3
#define NUMCOLS 3

byte buttons[NUMROWS][NUMCOLS] = {
{0, 1, 2},
{3, 4, 5},
{6, 7 ,8},
};

byte rowPins[NUMROWS] = {21, 20, 19};
byte colPins[NUMCOLS] = {18, 9, 10};

Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 20, 0,
false, false, false, false, false, false,
false, false, false, false, false);

void setup() {
Joystick.begin();
}
void loop() {
CheckAllButtons();
}

void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i = 0; i < LIST_MAX; i++)
{
if ( buttbx.key*.stateChanged )*

  • {*
    _ switch (buttbx.key*.kstate) {_
    _
    case PRESSED:_
    _
    case HOLD:_
    _ Joystick.setButton(buttbx.key.kchar, 1);
    break;
    case RELEASED:
    case IDLE:
    Joystick.setButton(buttbx.key.kchar, 0);
    break;
    }
    }
    }
    }
    }*_

I looked into your schematic and I have some questions:

If I understand right you choose with the rotary-switch one of the following functions TC, ABS, MAP, BB (Whatever the abbreviations might mean)
and then want to increase with a "+"-Button and decrease with a "-" button

Is this right? If so
you just need to wire the centercontact of your rotary-switch to GND and the chooseable contacts to for IO-pins

Same thing for the "+"-Button and the "-"-Button one contact to GND other contact to an IO-pin.
Just like to shift + shift- "-" switches.

Is there a special reason for doing this more complicated wiring?

Do you have a digital-multimeter to measure how your triple-buttons are wired?
If not this is the right time to buy one.
If you don't have any knowledge about electronics I recommend learning the basics.
the microcontroller-word is not super-standardised like USB-devices for Computers
you the "developper" have to take care about staying withing voltage- and current-limits to avoid damaging your microcontroller.

For example if your matrix has just mechanical switches with a low resistance and you make a wrong wiring which could lead to having one IO-pin to be configured as output and set to 0,0V and another accidently configured as output too and set to 3.3V the current that will flow is much to high and will destroy minimum this IO-pin more likely frying the whole chip.

So it is a good idea to measure the resistance of your matrixswitches. If it is as low as 0,5 to 50 Ohms this is too low and current-limiting resistors should be inserted in serial to limit the current to safe values.

These current-limiting resistors are rarely seen in any schematics. As long as you configure the IO-pins right you don't need them. In case of a wrong wiring these resistors protect your IO-pins while the switches will work just the same as without these resistors. This applies to digital used IO-pins. It is different with IO-pins that are used to measure analog voltages.

best regards Stefan

Hi Stephan38
Yes i agree that i can simplify the wiring so the code will be somthing like that
check which encoder pin is grounded and wait for a +/_ button acitvation then send correspondant joystcik button state pressed
I have a multimeter at home and i always check my wiring before powering my arduino
I will modify my wiring with your idea but now can you explain me how to add the code to my sketch?
Thank you for your support
Didier

You should edit your first post in that way that your code is shown as a code-section.

If you put the Arduino-IDE-window in the forground cursor beeing active inside
then do a right-click and choose copy for forum and then paste the clipboard into the texteditor of the forum-website
it will appear as codesection.

For further help more information must be provided by you: how does your steering-wheel interact with what?
a play-station? a PC? or anything else. Will your steering-wheel be connected via USB or via a special kind of plug to the car-simulating device?

I have a multimeter at home and i always check my wiring before powering my arduino

sounds like you have done 3 to 5 other projects with Arduinos.

The code you have posted in the TO-post is just a rudimentary framework which reads out the keys of your keymatrix but does nothing at all with this "keypress-information". So me personal I insist on that you write a first attempt how you think it might could work detecting button-presses.

If you are completely new to programming yourself I recommend
Of course you can ask here in the forum. But then you have to wait for the answers. If you start to learn how coding works you become more and more independent of waiting for answers.

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

I'm a somehow advanced programmer and this has the effect of beeing partially blind about beginners difficulties. But I would like to become an "expert" about beginners difficulties and therefore I appreciate feedback about that and to receive questions what is still hard to understand.

best regards Stefan

Thank you Stephan
Yes it is my 3rd project but each time i used exisitng code i found and adapt it to my need
I have no enough time to learn how to create my own code i try to understand what the code is doing only
I confirm that my little matrix sketch is working Windows recognize the arduino as a 20 buttons joystick and the 1st 9 buttons work
What i don t know is how to create a new funtion in the Void loop and setup part of the code without interracting with my actual matrix code
BR
Didier

if (KnowledgeLevel < 3) {
  AskForAlmostEveryDetail(HowToChangeIt)
  Delay(UntilNextAnswerIsPosted);
  Break;
}
if (KnowledgeLevel > 3) {
  proceduralWrite(OnYourOwn)
   setSpeed(ContiniouslyDeveloping);
}

void setup() {
  LearningTheBasics();
}

void loop() {
    HaveMoreFunThan(WaitingForAnswers);
    ByWritingAndTestingCodeYourself();
}

that’s my code that I suggest
best regards Stefan