Replica of the Porsche 919 rim.

Status
Not open for further replies.

Artois

Member
I am starting a project of trying to make a replica of the Porsche 919 rim for Sim Racing. On the electronic side I would like to see if i can use a Teensy board. I have used teensy LC in the past for other SIM projects but I am not sure if the Teensy has the head room for the number of controls this project will need. I believe from my understanding the board can handle each of the needed control under the Joystick example but how do you get more controls.

Needed Controls for this Project

9 - Rotary encoders(which from my understanding are just two buttons, one for turning it left and one for turning it right. Making the needed available buttons 18)
17- Push Buttons
2 - Potentiometers


Reference Photo of what I am trying to replicate.

https://porschenewsroom.s3.amazonaw...a548-9339eff1d9c0_teaser_original_720x1_5.jpg

I appreciate any help with this. Thanks in advance.
 
This is my Code. I got it all working to the best of my knowledge. I tested it with the limited hardware(5 encoders, 3 buttons, 2 potentiometers) I have on hand by testing the controls in batches. I have set all the final pin assignments and control layout. I plan on ordering the rest of my controls and building a full size test board as soon as I can get all the components.


I still don't know how to make the usb joystick go above 32 buttons. I wrote the Sketch as if it can but I don't how to make the last three buttons actually work. Any help in this would be greatly appreciated.


Code:
#include <Encoder.h>

long oldPosition1  = -999;
long oldPosition2  = -999;
long oldPosition3  = -999;
long oldPosition4  = -999;
long oldPosition5  = -999;
long oldPosition6  = -999;
long oldPosition7  = -999;
long oldPosition8  = -999;
long oldPosition9  = -999;

//Encoder pin A and B Callouts
Encoder myEnc1(22, 23);
Encoder myEnc2(24, 25);
Encoder myEnc3(26, 27);
Encoder myEnc4(28, 29);
Encoder myEnc5(30, 31);
Encoder myEnc6(32, 33);
Encoder myEnc7(34, 35);
Encoder myEnc8(36, 37);
Encoder myEnc9(38, 39);


//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");

  // Initialize Joystick Library
  Joystick.begin();
  
//Button Pin Callouts
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
}

void loop() {
  
  //Joystick Analog Pin Callout for Clutch Paddles
  Joystick.sliderRight(analogRead(A22));
  Joystick.sliderLeft(analogRead(A21));

//Digital Inputs to Button setup

  //Button 1
   if(digitalRead(0) == LOW)
{ 
 Joystick.button(1,1);
}
  else
  {
    Joystick.button(1,0);
  }
    //Button 2
   if(digitalRead(1) == LOW)
{ 
 Joystick.button(2,1);
}
  else
  {
    Joystick.button(2,0);
  }
    //Button 3
   if(digitalRead(2) == LOW)
{ 
 Joystick.button(3,1);
}
  else
  {
    Joystick.button(3,0);
  }
    //Button 4
   if(digitalRead(3) == LOW)
{ 
 Joystick.button(4,1);
}
  else
  {
    Joystick.button(4,0);
  }
    //Button 5
   if(digitalRead(4) == LOW)
{ 
 Joystick.button(5,1);
}
  else
  {
    Joystick.button(5,0);
  }
    //Button 6
   if(digitalRead(5) == LOW)
{ 
 Joystick.button(6,1);
}
  else
  {
    Joystick.button(6,0);
  }
    //Button 7
   if(digitalRead(6) == LOW)
{ 
 Joystick.button(7,1);
}
  else
  {
    Joystick.button(7,0);
  }
    //Button 8
   if(digitalRead(7) == LOW)
{ 
 Joystick.button(8,1);
}
  else
  {
    Joystick.button(8,0);
  }
    //Button 9
   if(digitalRead(8) == LOW)
{ 
 Joystick.button(9,1);
}
  else
  {
    Joystick.button(9,0);
  }
    //Button 10
   if(digitalRead(9) == LOW)
{ 
 Joystick.button(10,1);
}
  else
  {
    Joystick.button(10,0);
  }
    //Button 11
   if(digitalRead(10) == LOW)
{ 
 Joystick.button(11,1);
}
  else
  {
    Joystick.button(11,0);
  }
    //Button 12
   if(digitalRead(11) == LOW)
{ 
 Joystick.button(12,1);
}
  else
  {
    Joystick.button(12,0);
  }
    //Button 13
   if(digitalRead(12) == LOW)
{ 
 Joystick.button(13,1);
}
  else
  {
    Joystick.button(13,0);
  }
    //Button 14
   if(digitalRead(13) == LOW)
{ 
 Joystick.button(14,1);
}
  else
  {
    Joystick.button(14,0);
  }
    //Button ? 15/33
   if(digitalRead(14) == LOW)
{ 
 Joystick.button(33,1);
}
  else
  {
    Joystick.button(33,0);
  }
   //Button ? 16/34
   if(digitalRead(15) == LOW)
{ 
 Joystick.button(34,1);
}
  else
  {
    Joystick.button(34,0);
  }
   //Button ? 17/35
   if(digitalRead(16) == LOW)
{ 
 Joystick.button(35,1);
}
  else
  {
    Joystick.button(35,0);
  }
   
  /////////////////////////////////////

//Encoder 1  
long newPosition1 = myEnc1.read();
  if (newPosition1 > oldPosition1) {
    oldPosition1 = newPosition1;
    Serial.println(newPosition1);
    Joystick.button(15,1);
    Joystick.button(16,0);
  }
   if (newPosition1 < oldPosition1) {
    oldPosition1 = newPosition1;
    Serial.println(newPosition1);
    Joystick.button(15,0);
    Joystick.button(16,1);
  }
else
    Joystick.button(15,0);
    Joystick.button(16,0);
 
  delay(5);

//Encoder 2
  long newPosition2 = myEnc2.read();
  if (newPosition2 > oldPosition2) {
    oldPosition2 = newPosition2;
    Serial.println(newPosition2);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition2 < oldPosition2) {
    oldPosition2 = newPosition2;
    Serial.println(newPosition2);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);

 //Encoder 3
  long newPosition3 = myEnc3.read();
  if (newPosition3 > oldPosition3) {
    oldPosition3 = newPosition3;
    Serial.println(newPosition3);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition3 < oldPosition3) {
    oldPosition3 = newPosition3;
    Serial.println(newPosition3);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 4
  long newPosition4 = myEnc4.read();
  if (newPosition4 > oldPosition4) {
    oldPosition4 = newPosition4;
    Serial.println(newPosition4);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition4 < oldPosition4) {
    oldPosition4 = newPosition4;
    Serial.println(newPosition4);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 5
  long newPosition5 = myEnc5.read();
  if (newPosition5 > oldPosition5) {
    oldPosition5 = newPosition5;
    Serial.println(newPosition5);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition5 < oldPosition5) {
    oldPosition5 = newPosition5;
    Serial.println(newPosition5);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 6
  long newPosition6 = myEnc6.read();
  if (newPosition6 > oldPosition6) {
    oldPosition6 = newPosition6;
    Serial.println(newPosition6);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition6 < oldPosition6) {
    oldPosition6 = newPosition6;
    Serial.println(newPosition6);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 7
  long newPosition7 = myEnc7.read();
  if (newPosition7 > oldPosition7) {
    oldPosition7 = newPosition7;
    Serial.println(newPosition7);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition7 < oldPosition7) {
    oldPosition7 = newPosition7;
    Serial.println(newPosition7);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 8
  long newPosition8 = myEnc8.read();
  if (newPosition8 > oldPosition8) {
    oldPosition8 = newPosition8;
    Serial.println(newPosition8);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition8 < oldPosition8) {
    oldPosition8 = newPosition8;
    Serial.println(newPosition8);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 9
  long newPosition9 = myEnc9.read();
  if (newPosition9 > oldPosition9) {
    oldPosition9 = newPosition9;
    Serial.println(newPosition9);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition9 < oldPosition9) {
    oldPosition9 = newPosition9;
    Serial.println(newPosition9);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5); 
}
 
Hi,
Did you ever worked on RDM? If yes then please give the sample code to discover and Identify the device

Thanks in Advance
 
A member Chevelle gave me a solution that I think for my use will work just fine. He suggested that I use keyboard buttons to cover the extra buttons I need. Since I am making this for gaming use it should work just fine seeing as keyboard buttons map just as well in game. So, my last 3 buttons that I need to code I will do so just using keyboard buttons.

I will share the updated sketch when I have the changes made.

Again Thank you Chevelle for your help. I was definitely making my project harder than it needed to be.
 
Finalized sketch.

17 Buttons
9 Encoders
2 Potentiometers


Code:
#include <Encoder.h>

long oldPosition1  = -999;
long oldPosition2  = -999;
long oldPosition3  = -999;
long oldPosition4  = -999;
long oldPosition5  = -999;
long oldPosition6  = -999;
long oldPosition7  = -999;
long oldPosition8  = -999;
long oldPosition9  = -999;

//Encoder pin A and B Callouts
Encoder myEnc1(22, 23);
Encoder myEnc2(24, 25);
Encoder myEnc3(26, 27);
Encoder myEnc4(28, 29);
Encoder myEnc5(30, 31);
Encoder myEnc6(32, 33);
Encoder myEnc7(34, 35);
Encoder myEnc8(36, 37);
Encoder myEnc9(38, 39);


//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");

  // Initialize Joystick Library
  Joystick.begin();
  
//Button Pin Callouts
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
}

void loop() {
  
  //Joystick Analog Pin Callout for Clutch Paddles
  Joystick.sliderRight(analogRead(A22));
  Joystick.sliderLeft(analogRead(A21));

//Digital Inputs to Button setup

  //Button 1
   if(digitalRead(0) == LOW)
{ 
 Joystick.button(1,1);
}
  else
  {
    Joystick.button(1,0);
  }
    //Button 2
   if(digitalRead(1) == LOW)
{ 
 Joystick.button(2,1);
}
  else
  {
    Joystick.button(2,0);
  }
    //Button 3
   if(digitalRead(2) == LOW)
{ 
 Joystick.button(3,1);
}
  else
  {
    Joystick.button(3,0);
  }
    //Button 4
   if(digitalRead(3) == LOW)
{ 
 Joystick.button(4,1);
}
  else
  {
    Joystick.button(4,0);
  }
    //Button 5
   if(digitalRead(4) == LOW)
{ 
 Joystick.button(5,1);
}
  else
  {
    Joystick.button(5,0);
  }
    //Button 6
   if(digitalRead(5) == LOW)
{ 
 Joystick.button(6,1);
}
  else
  {
    Joystick.button(6,0);
  }
    //Button 7
   if(digitalRead(6) == LOW)
{ 
 Joystick.button(7,1);
}
  else
  {
    Joystick.button(7,0);
  }
    //Button 8
   if(digitalRead(7) == LOW)
{ 
 Joystick.button(8,1);
}
  else
  {
    Joystick.button(8,0);
  }
    //Button 9
   if(digitalRead(8) == LOW)
{ 
 Joystick.button(9,1);
}
  else
  {
    Joystick.button(9,0);
  }
    //Button 10
   if(digitalRead(9) == LOW)
{ 
 Joystick.button(10,1);
}
  else
  {
    Joystick.button(10,0);
  }
    //Button 11
   if(digitalRead(10) == LOW)
{ 
 Joystick.button(11,1);
}
  else
  {
    Joystick.button(11,0);
  }
    //Button 12
   if(digitalRead(11) == LOW)
{ 
 Joystick.button(12,1);
}
  else
  {
    Joystick.button(12,0);
  }
    //Button 13
   if(digitalRead(12) == LOW)
{ 
 Joystick.button(13,1);
}
  else
  {
    Joystick.button(13,0);
  }
    //Button 14
   if(digitalRead(13) == LOW)
{ 
 Joystick.button(14,1);
}
  else
  {
    Joystick.button(14,0);
  }
    //Button 15
   if(digitalRead(14) == LOW)
{ 
 Keyboard.press(KEY_M);
}
  else
  {
    Keyboard.release(KEY_M);
  }
   //Button 16
   if(digitalRead(15) == LOW)
{ 
 Keyboard.press(KEY_N);
}
  else
  {
    Keyboard.release(KEY_N);
  }
   //Button 17
   if(digitalRead(16) == LOW)
{ 
 Keyboard.press(KEY_B);
}
  else
  {
    Keyboard.release(KEY_B);
  }
   
  /////////////////////////////////////

//Encoder 1  
long newPosition1 = myEnc1.read();
  if (newPosition1 > oldPosition1) {
    oldPosition1 = newPosition1;
    Serial.println(newPosition1);
    Joystick.button(15,1);
    Joystick.button(16,0);
  }
   if (newPosition1 < oldPosition1) {
    oldPosition1 = newPosition1;
    Serial.println(newPosition1);
    Joystick.button(15,0);
    Joystick.button(16,1);
  }
else
    Joystick.button(15,0);
    Joystick.button(16,0);
 
  delay(5);

//Encoder 2
  long newPosition2 = myEnc2.read();
  if (newPosition2 > oldPosition2) {
    oldPosition2 = newPosition2;
    Serial.println(newPosition2);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition2 < oldPosition2) {
    oldPosition2 = newPosition2;
    Serial.println(newPosition2);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);

 //Encoder 3
  long newPosition3 = myEnc3.read();
  if (newPosition3 > oldPosition3) {
    oldPosition3 = newPosition3;
    Serial.println(newPosition3);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition3 < oldPosition3) {
    oldPosition3 = newPosition3;
    Serial.println(newPosition3);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 4
  long newPosition4 = myEnc4.read();
  if (newPosition4 > oldPosition4) {
    oldPosition4 = newPosition4;
    Serial.println(newPosition4);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition4 < oldPosition4) {
    oldPosition4 = newPosition4;
    Serial.println(newPosition4);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 5
  long newPosition5 = myEnc5.read();
  if (newPosition5 > oldPosition5) {
    oldPosition5 = newPosition5;
    Serial.println(newPosition5);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition5 < oldPosition5) {
    oldPosition5 = newPosition5;
    Serial.println(newPosition5);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 6
  long newPosition6 = myEnc6.read();
  if (newPosition6 > oldPosition6) {
    oldPosition6 = newPosition6;
    Serial.println(newPosition6);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition6 < oldPosition6) {
    oldPosition6 = newPosition6;
    Serial.println(newPosition6);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 7
  long newPosition7 = myEnc7.read();
  if (newPosition7 > oldPosition7) {
    oldPosition7 = newPosition7;
    Serial.println(newPosition7);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition7 < oldPosition7) {
    oldPosition7 = newPosition7;
    Serial.println(newPosition7);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 8
  long newPosition8 = myEnc8.read();
  if (newPosition8 > oldPosition8) {
    oldPosition8 = newPosition8;
    Serial.println(newPosition8);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition8 < oldPosition8) {
    oldPosition8 = newPosition8;
    Serial.println(newPosition8);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5);
  
  //Encoder 9
  long newPosition9 = myEnc9.read();
  if (newPosition9 > oldPosition9) {
    oldPosition9 = newPosition9;
    Serial.println(newPosition9);
    Joystick.button(17,1);
    Joystick.button(18,0);
  }
   if (newPosition9 < oldPosition9) {
    oldPosition9 = newPosition9;
    Serial.println(newPosition9);
    Joystick.button(17,0);
    Joystick.button(18,1);
  }
else
    Joystick.button(17,0);
    Joystick.button(18,0);
 
  delay(5); 
}
 
No define for:
Code:
  // Initialize Joystick Library
  Joystick.begin();

Arrays could clean the multiple items up for more compact code.
 
Defragster. Are you saying the "Joystick.begin();" is unneeded in my code? I spent a few days teaching myself this coding and the way I did that was wrote a separate sketches for each of the different controls I am using and then once I had something that I thought worked I began writing this all inclusive sketch. However, in the process of learning how to write the code I found out that there are multiple ways to code each of the controls. I think with buttons for example I found maybe 8-10 different ways to code them. That line may have been part of one of the other codes that I tried at some point but I didn't realize I didn't need anymore because it doesn't throw an error when I compile the sketch.

Also with Arrays do I get any performance gain over the digital read method? I had only gone this way because it seems as this will make for the easiest wiring diagram. Simple that every button and encoder goes ground and the assigned pin.
 
Arrays will not give you direct performance gains over digtial read, but would make the code shorter though quite possibly harder to read - idea is you have a for loop that cycles through all your buttons, with an array listing all your physical inputs and an array listing all your outputs. So you might have:

byte inButtons[10] ={9,3,2,4,3,12,7,8,9,11};
byte outButtons[10]={1,4,2,5,3,11,7,8,9,12};

Or get really clever and tie it all into a two dimensional array.

If what you have works stay with it but if doing complex IO like this it can improve things to have code that places all your configuration stuff in one place that you can see in one go and make it easy to check for duplicates or misses. With your if/else structure should you need to swap buttons around you will probably be chasing around for a while getting everything working again- with an array you swap two numbers and compile.

With some projects I have even been known to write PC side programs in something like processing that produce Arduino C to simplify no duplicates/no misses type problems.

If for some reason absolute performance was the goal you could read the IO ports directly, which would give you every button on that port in one read. That is something you do if you are reading shaft sensors in a CNC or something - here the choke point is the USB anyway so there is no gain in getting elaborate with the button reads.
 
Defragster. Are you saying the "Joystick.begin();" is unneeded in my code? I spent a few days teaching myself this coding and the way I did that was wrote a separate sketches for each of the different controls I am using and then once I had something that I thought worked I began writing this all inclusive sketch. However, in the process of learning how to write the code I found out that there are multiple ways to code each of the controls. I think with buttons for example I found maybe 8-10 different ways to code them. That line may have been part of one of the other codes that I tried at some point but I didn't realize I didn't need anymore because it doesn't throw an error when I compile the sketch.

Also with Arrays do I get any performance gain over the digital read method? I had only gone this way because it seems as this will make for the easiest wiring diagram. Simple that every button and encoder goes ground and the assigned pin.

I'm saying for some reason I could not compile the posted code - .begin() is often required for setup when it isn't an object. Not sure if I just don't have a library you have that isn't listed with an explicit #include?

The arrays won't do much your linear code does to do it faster - but will compile to smaller less repetitive code that might happen to execute faster if it fits in processor cache. Also it seemed the same read/update steps were taken so doing them right in one spot can be easier than a long chain of 14 of the same thing then 3 others for the keys.
 
Status
Not open for further replies.
Back
Top