pascalh 34 Report post Posted April 8, 2017 (edited) 37 minutes ago, Traction said: In H-pattern gears 1-6 use buttons 1-6, no reverse or any other buttons. In seq fwd gives button3 and rev button 4, as you said just using analogue x,y axis. I will check + and gnd , also data, clock. btw this G25 shifter had been previously modified to use with a G27 wheel. It worked perfectly. Thx for your help. regards mal If gears 1-6 generate button 1-6 presses then GND and +5V are correctly wired. Button 3 and 4 in sequential mode is normal as the digital signal for H-pattern/sequential is not generated. If the shifter is working the problem most likely lies in the wiring of the 3 digital signals. Edited April 8, 2017 by pascalh Share this post Link to post Share on other sites
Traction 0 Report post Posted April 10, 2017 Thx very much Pascalh for all your help, I have decided to buy a new Teeny 2.0 (instead of ++2.0) because I have tried re-soldering and shorting of the wires, to no avail, the cheapest option is to try again with another teensy. It will be a while b4 I report back due to postage and work commitments, Thx again , regards Mal Share this post Link to post Share on other sites
Traction 0 Report post Posted May 8, 2017 (edited) Update, Got a Teensy2 board followed your instructions Pascalh, it works perfectly., many thx from me ..keep up the work Mal never found out why my teensy ++2 failed .. no matter now Edited May 8, 2017 by Traction Share this post Link to post Share on other sites
pascalh 34 Report post Posted May 9, 2017 6 hours ago, Traction said: Update, Got a Teensy2 board followed your instructions Pascalh, it works perfectly., many thx from me ..keep up the work Mal never found out why my teensy ++2 failed .. no matter now Glad to see Share this post Link to post Share on other sites
hetfieldickinson 0 Report post Posted July 4, 2017 Hey guys, anyone knows how to disable shifter on the code of Spotchier? I trying to configure demul controls, but the shifter is sending a phantom input in the neutral position, the emu reads something on x axis. My idea is to disable shifter, or at least the x axis of shifter, only to do the configuration... Share this post Link to post Share on other sites
IntenseM9 0 Report post Posted October 3, 2017 (edited) Hi to all, I'm noob at this and I never programmed any teensy++ 2.0, can someone tell me what pins 2, 3 and 4 are on this pic? I'll use the code from @xxValiumxx user. Thanks in advance and sorry for my bad english! Edited October 3, 2017 by IntenseM9 Share this post Link to post Share on other sites
Stealthblackbird 1 Report post Posted October 5, 2017 On 10/2/2017 at 5:03 PM, IntenseM9 said: Hi to all, I'm noob at this and I never programmed any teensy++ 2.0, can someone tell me what pins 2, 3 and 4 are on this pic? I'll use the code from @xxValiumxx user. Thanks in advance and sorry for my bad english! Those are the digital Input pins. What shifter are you using? Share this post Link to post Share on other sites
IntenseM9 0 Report post Posted October 5, 2017 (edited) 15 hours ago, Stealthblackbird said: Those are the digital Input pins. What shifter are you using? Hi Stealthblackbird thanks for the response. Im using a G27 shifter. Then I have to solder the wires 1,2,3 on pins 2,3,4 of the teensy? // G27 shifter pinout // // DB9 Color Shifter Description Teensy// 1 Purple 1 Button Clock pin 2 // 2 Grey 7 Button Data pin 3 // 3 Yellow 5 Button !CS & !PL pin 4 // 4 Orange 3 Shifter X axis pin 38 (A0) // 5 White 2 SPI input // 6 Black 8 GND GND // 7 Red 6 +5V VCC // 8 Green 4 Shifter Y axis pin 39 (A1) // 9 Red 1 +5V Edited October 5, 2017 by IntenseM9 Share this post Link to post Share on other sites
Stealthblackbird 1 Report post Posted October 5, 2017 23 minutes ago, IntenseM9 said: Hi Stealthblackbird thanks for the response. Im using a G27 shifter. Then I have to solder the wires 1,2,3 on pins 2,3,4 of the teensy? // G27 shifter pinout // // DB9 Color Shifter Description Teensy// 1 Purple 1 Button Clock pin 2 // 2 Grey 7 Button Data pin 3 // 3 Yellow 5 Button !CS & !PL pin 4 // 4 Orange 3 Shifter X axis pin 38 (A0) // 5 White 2 SPI input // 6 Black 8 GND GND // 7 Red 6 +5V VCC // 8 Green 4 Shifter Y axis pin 39 (A1) // 9 Red 1 +5V Yes, that's correct. The pins 1, 2, 3, on the DB9 Plug should be soldered to pins 2, 3, 4. Other wires should be connected to their spots accordingly, omitting SPI input on DB9 pin 5 and the +5V on DB9 pin 9. Share this post Link to post Share on other sites
Nick 0 Report post Posted October 17, 2017 (edited) Hi Pascalh & xxValiumxx your program works great! It allowed an extra button too hehe Extra info, i got the power led working: For those who want the powerled to light up, connect the SPI Input wire to the ground. Keep up the good work. Edited October 18, 2017 by Nick Share this post Link to post Share on other sites
pascalh 34 Report post Posted October 17, 2017 2 hours ago, Nick said: Hi Pascalh & xxValiumxx your program works great! It allowed an extra button too hehe Extra info, i got the power led working: For those who want the powerled to light up, connect the white wire (SPI Input) to the ground. Keep up the good work. Nice find Share this post Link to post Share on other sites
darrydu 0 Report post Posted December 3, 2017 On Fri Apr 25 2014 at 4:36 PM, xxValiumxx said: Actually, no, they are not. the +5v (DSUB 1) and Clock (DSUB 7) pins are swapped. I have the code completed, but I did have to remove the sequential and handbrake sections of code, as the G27 shifter has no sequential feature (meaning no handbrake either). I just have to wait for the mail to get here tomorrow and then I will be able to verify my code. I plan on ordering a set of G27 pedals as well and adding code for those. I'm using the Teensy++ 2.0 so I have 128k of program and 8 K of ram to play with, and currently I'm using 5,174 Bytes (5k) of program and a mere 131 bytes of ram. Plenty of room left to play. Good job on knowing how to use defines, many people still don't use them for pin definitions. Why my G27 shifter did not work correctly,I had swap +5v (DSUB 1) and Clock (DSUB 7) pins,and upload your code G27_shifter_en.ino.I also using the Teensy++ 2.0.On my G27 shifter ,just 1 2 3 4 5gears are working ,6 gear and R gear was on the button 8 ,but all botton did not work.Other,I upload G25_shifter_en.ino by Pascalh ,just 1 2 3 4 5 gears are working.I down kown where was error .Or had you wiring diagram, Thank you! sorry for my bad english,I am chinese.This is the problem.could help me Share this post Link to post Share on other sites
darrydu 0 Report post Posted December 3, 2017 On Sun Dec 20 2015 at 7:40 PM, flaviu said: Hi guys, Pascalh, thank you very much for this topic. I found exactly what I was needed. The G27 shifter works perfect, with some little modification. I have a teensy 2.0 board and my file it is attached bellow. I'm not a programmer person so I need some help to make my pedals work with the shifter. I try to use: #define Z_AXIS_PIN 1 // gas Z axis #define BR_AXIS_PIN 2 // brake left sliders #define CL_AXIS_PIN 3 // clutch right sliders // G27 pedals analog inputs configuration pinMode(Z_AXIS_PIN, INPUT_PULLUP); // Z axix gas pinMode(BR_AXIS_PIN, INPUT_PULLUP); // Slider left brake pinMode(CL_AXIS_PIN, INPUT_PULLUP); // Slider right clutch but couldn't make pedals to work. If anyone have a little time, please give me some help. Thank you. G27_shifter_en1.ino Did you have the wiring diagram for DSUB9 and teensy 2.0,I upload your file,but my G27 shifter did not work correctly,just 1 2 3 4 5 6 gears working.Thank you! Share this post Link to post Share on other sites
darrydu 0 Report post Posted December 3, 2017 On Sun Aug 21 2016 at 8:10 AM, fishware said: I fixed it by myself // // G27 shifter to USB interface // based on a Teensy++ 2.0 // Original by pascalh from insidesimracing.tv // http://insidesimracing.tv/forums/topic/13189-diy-g25-shifter-interface-with-h-pattern-sequential-and-handbrake-modes/ // 1 operating mode // - H-pattern shifter // // // G27 shifter pinout // // DB9 Color Shifter Description Teensy // 1 Purple 1 Button Clock pin 2 // 2 Grey 7 Button Data pin 3 // 3 Yellow 5 Button !CS & !PL pin 4 // 4 Orange 3 Shifter X axis pin 38 (A0) // 5 White 2 SPI input // 6 Black 8 GND GND // 7 Red 6 +5V VCC // 8 Green 4 Shifter Y axis pin 39 (A1) // 9 Red 1 +5V // Teensy pin definitions #define LED_PIN 11 #define DATA_IN_PIN 44 #define MODE_PIN 43 #define CLOCK_PIN 42 #define X_AXIS_PIN 39 #define Y_AXIS_PIN 38 // H-shifter mode analog axis thresholds #define HS_XAXIS_12 400 //Gears 1,2 #define HS_XAXIS_56 600 //Gears 5,6, R #define HS_YAXIS_135 750 //Gears 1,3,5 #define HS_YAXIS_246 300 //Gears 2,4,6, R // Digital inputs definitions #define DI_REVERSE 1 byte NESButtonData; // Called at startup // Must initialize hardware and software modules void setup() { // G27 shifter analog inputs configuration pinMode(X_AXIS_PIN, INPUT_PULLUP); // X axis pinMode(Y_AXIS_PIN, INPUT_PULLUP); // Y axis // G27 shift register interface configuration pinMode(DATA_IN_PIN, INPUT); // Data in pinMode(MODE_PIN, OUTPUT); // Parallel/serial mode pinMode(CLOCK_PIN, OUTPUT); // Clock // Virtual joystick configuration Joystick.useManualSend(true); // Joystick output is synchronized } // Called in a loop after initialization void loop() { // Reading of button states from G27 shift register int b[2]; digitalWrite(MODE_PIN, LOW); // Switch to parallel mode: digital inputs are read into shift register delayMicroseconds(10); // Wait for signal to settle digitalWrite(MODE_PIN, HIGH); // Switch to serial mode: one data bit is output on each clock falling edge for(int i=0; i<2; i++) // Reading registers { digitalWrite(CLOCK_PIN, LOW); // Generate clock falling edge delayMicroseconds(10); // Wait for signal to settle b[i]=digitalRead(DATA_IN_PIN); // Read data bit and store it into bit array digitalWrite(CLOCK_PIN, HIGH); // Generate clock rising edge delayMicroseconds(10); // Wait for signal to settle } // Reading of shifter position int x=analogRead(0); // X axis int y=analogRead(1); // Y axis // Current gear calculation int gear=0; // Default value is neutral if(x<HS_XAXIS_12) // Shifter on the left? { if(y>HS_YAXIS_135) gear=1; // 1st gear if(y<HS_YAXIS_246) gear=2; // 2nd gear } else if(x>HS_XAXIS_56) // Shifter on the right? { if(y>HS_YAXIS_135) gear=5; // 5th gear if(y<HS_YAXIS_246) gear=6; // 6th gear } else // Shifter is in the middle { if(y>HS_YAXIS_135) gear=3; // 3rd gear if(y<HS_YAXIS_246) gear=4; // 4th gear } if(gear!=6) b[DI_REVERSE]=0; // Reverse gear is allowed only on 6th gear position if(b[DI_REVERSE]==1) gear=0; // 6th gear is deactivated if reverse gear is engaged // Release virtual buttons for all gears Joystick.button(1, LOW); Joystick.button(2, LOW); Joystick.button(3, LOW); Joystick.button(4, LOW); Joystick.button(5, LOW); Joystick.button(6, LOW); Joystick.button(7, b[DI_REVERSE]); // Depress virtual button for current gear if(gear>0) Joystick.button(gear, HIGH); // Write new virtual joystick state Joystick.send_now(); // Write inputs and outputs (remove comments to debug) /* Serial.print(" X axis: "); Serial.print(x); Serial.print(" Y axis: "); Serial.print(y); Serial.print(" Digital inputs: "); for(int i=0; i<2; i++)Serial.print(b[i]); Serial.print(" "); Serial.print(" Gear: "); Serial.print(gear); */ delay(10); // Wait for 10ms } Kind regards Chris Could you fix a G27 file,this code just 1 2 3 4 5 6and R is work ,else black and red button did not work,also dipad.Thanks! Share this post Link to post Share on other sites
dabneyd 0 Report post Posted December 10, 2017 (edited) On 3/26/2017 at 8:31 AM, pascalh said: It is not very difficult: Hardware: from what I read the sensor needs GND, VCC and signal connection (3 wires). The signal output needs to be connected to an analog input of the Teensy board. The first unused pin is A5 (pin 16). Software: // // G25 shifter to USB interface // based on a Teensy 2.0 // // 3 operating modes // - H-pattern shifter // - Sequential shifter // - Analog handrake // // // G25 shifter pinout // // DB9 Color Shifter Description Teensy // 1 Black 1 +5V +5V // 2 Grey 7 Button Data pin 17 // 3 Yellow 5 Button !CS & !PL pin 18 // 4 Orange 3 Shifter X axis pin 21 (A0) // 5 Red 2 SPI input // 6 White 8 GND GND // 7 Purple 6 Button Clock pin 19 // 8 Green 4 Shifter Y axis pin 20 (A1) // 9 Black 1 +5V // Teensy pin definitions #define LED_PIN 11 #define DATA_IN_PIN 17 #define MODE_PIN 18 #define CLOCK_PIN 19 #define X_AXIS_PIN 20 #define Y_AXIS_PIN 21 #define HANDBRAKE_PIN 16 // H-shifter mode analog axis thresholds #define HS_XAXIS_12 400 #define HS_XAXIS_56 600 #define HS_YAXIS_135 800 #define HS_YAXIS_246 300 // Sequential shifter mode analog axis thresholds #define SS_UPSHIFT_BEGIN 670 #define SS_UPSHIFT_END 600 #define SS_DOWNSHIFT_BEGIN 430 #define SS_DOWNSHIFT_END 500 // Handbrake mode analog axis limits #define HB_MAXIMUM 530 #define HB_MINIMUM 400 #define HB_RANGE (HB_MAXIMUM-HB_MINIMUM) // Digital inputs definitions #define DI_REVERSE 1 #define DI_MODE 3 #define DI_RED_CENTERRIGHT 4 #define DI_RED_CENTERLEFT 5 #define DI_RED_RIGHT 6 #define DI_RED_LEFT 7 #define DI_BLACK_TOP 8 #define DI_BLACK_RIGHT 9 #define DI_BLACK_LEFT 10 #define DI_BLACK_BOTTOM 11 #define DI_DPAD_RIGHT 12 #define DI_DPAD_LEFT 13 #define DI_DPAD_BOTTOM 14 #define DI_DPAD_TOP 15 // Shifter state #define DOWN_SHIFT -1 #define NO_SHIFT 0 #define UP_SHIFT 1 // Shifter mode #define SHIFTER_MODE 0 #define HANDBRAKE_MODE 1 // LED blink counter int led=0; // Shifter state int shift=NO_SHIFT; // Handbrake mode int mode=SHIFTER_MODE; // Called at startup // Must initialize hardware and software modules void setup() { // G25 shifter analog inputs configuration pinMode(X_AXIS_PIN, INPUT_PULLUP); // X axis pinMode(Y_AXIS_PIN, INPUT_PULLUP); // Y axis // Handbrake analog input pinMode(HANDBRAKE_PIN, INPUT_PULLUP); // Handbrake // G25 shift register interface configuration pinMode(DATA_IN_PIN, INPUT); // Data in pinMode(MODE_PIN, OUTPUT); // Parallel/serial mode pinMode(CLOCK_PIN, OUTPUT); // Clock // LED output mode configuration pinMode(LED_PIN, OUTPUT); // LED // Virtual joystick configuration Joystick.useManualSend(true); // Joystick output is synchronized // Virtual serial interface configuration Serial.begin(38400); // Virtual joystick initialization Joystick.X(0); Joystick.Y(0); Joystick.Z(0); Joystick.Zrotate(0); Joystick.sliderLeft(0); Joystick.sliderRight(0); // Digital outputs initialization digitalWrite(LED_PIN, LOW); digitalWrite(MODE_PIN, HIGH); digitalWrite(CLOCK_PIN, HIGH); } // Called in a loop after initialization void loop() { // Reading of button states from G25 shift register int b[16]; digitalWrite(MODE_PIN, LOW); // Parallel mode: inputs are read into shift register delayMicroseconds(10); // Wait for signal to settle digitalWrite(MODE_PIN, HIGH); // Serial mode: data bits are output on clock falling edge for(int i=0; i<16; i++) // Iteration over both 8 bit registers { digitalWrite(CLOCK_PIN, LOW); // Generate clock falling edge delayMicroseconds(10); // Wait for signal to settle b[i]=digitalRead(DATA_IN_PIN); // Read data bit and store it into bit array digitalWrite(CLOCK_PIN, HIGH); // Generate clock rising edge delayMicroseconds(10); // Wait for signal to settle } // Reading of shifter position int x=analogRead(0); // X axis int y=analogRead(1); // Y axis // Reading of handbrake pressure int z=analogRead(5); // Handbrake // Handbrake output Joystick.Y(z*4); // Coefficient must be adjusted // Handbrake mode logic if(b[DI_RED_CENTERLEFT]!=0) // Is left center red button depressed? { if(b[DI_RED_CENTERRIGHT]!=0) // Is right center red button also depressed? { if(b[DI_RED_RIGHT]!=0) // Is rightmost red button also depressed? { mode=HANDBRAKE_MODE; // Handbrake mode is activated if the 3 rightmost } // red buttons are depressed if(b[DI_RED_LEFT]!=0) // Is leftmost red button also depressed? { mode=SHIFTER_MODE; // Handbrake mode is deactivated if the 3 leftmost } // red buttons are depressed } } // Current gear calculation int gear=0; // Default value is neutral if(b[DI_MODE]==0) // H-shifter mode? { if(x<HS_XAXIS_12) // Shifter on the left? { if(y>HS_YAXIS_135) gear=1; // 1st gear if(y<HS_YAXIS_246) gear=2; // 2nd gear } else if(x>HS_XAXIS_56) // Shifter on the right? { if(y>HS_YAXIS_135) gear=5; // 5th gear if(y<HS_YAXIS_246) gear=6; // 6th gear } else // Shifter is in the middle { if(y>HS_YAXIS_135) gear=3; // 3rd gear if(y<HS_YAXIS_246) gear=4; // 4th gear } } else // Sequential mode { if(mode==SHIFTER_MODE) // Shifter mode? { Joystick.X(0); if(shift==NO_SHIFT) // Current state: no shift { if(y>SS_UPSHIFT_BEGIN) // Shifter to the front? { gear=1; // Shift-up shift=UP_SHIFT; // New state: up-shift } if(y<SS_DOWNSHIFT_BEGIN) // Shifter to the rear? { gear=2; // Shift-down shift=DOWN_SHIFT; // New state: down-shift } } if(shift==UP_SHIFT) // Current state: up-shift? { if(y>SS_UPSHIFT_END) gear=1; // Beyond lower up-shift threshold: up-shift else shift=NO_SHIFT; // Else new state: no shift } if(shift==DOWN_SHIFT) // Current state: down-shift { if(y<SS_DOWNSHIFT_END) gear=2; // Below higher down-shift threshold: down-shift else shift=0; // Else new state: no shift } } else // Handbrake mode { if(y<HB_MINIMUM) y=HB_MINIMUM; // Clip minimum position if(y>HB_MAXIMUM) y=HB_MAXIMUM; // Clip maximum position long offset=(long)y-HB_MINIMUM; y=(int)(offset*1023/HB_RANGE); // Scale input between minimum and maximum clip position Joystick.X(y); // Set handbrake analog output gear=0; // No gear engaged: neutral } } if(gear!=6) b[DI_REVERSE]=0; // Reverse gear is allowed only on 6th gear position if(b[DI_REVERSE]==1) gear=0; // 6th gear is deactivated if reverse gear is engaged // Release virtual buttons for all gears Joystick.button(1, LOW); Joystick.button(2, LOW); Joystick.button(3, LOW); Joystick.button(4, LOW); Joystick.button(5, LOW); Joystick.button(6, LOW); // Depress virtual button for current gear if(gear>0) Joystick.button(gear, HIGH); // Set state of virtual buttons for all the physical buttons (including reverse) for(int i=0; i<16; i++) Joystick.button(7+i, b[i]); // Write new virtual joystick state Joystick.send_now(); // Write inputs and outputs (remove comments to debug) /* Serial.print(" X axis: "); Serial.print(x); Serial.print(" Y axis: "); Serial.print(y); Serial.print(" Digital inputs: "); for(int i=0; i<16; i++)Serial.print(b[i]); Serial.print(" "); Serial.print(" Gear: "); Serial.print(gear); Serial.print(" Mode: "); Serial.print(mode); Serial.print(" Shift: "); Serial.println(shift); */ // Blink the on-board LED if(++led==100) led=0; // Period is 100 cycles * 10ms = 1s if(led==0) digitalWrite(LED_PIN, LOW); // LED is off for 50 cycles if(led==50) digitalWrite(LED_PIN, HIGH); // LED is on for 50 cycles // Wait delay(10); // Wait for 10ms } Haven't tested the code but it should work. Please let us know I'm trying to do the same thing, but with a G25 brake pedal set up as a handbrake. I have it wired the same way. When I test the handbrake it only moves a little bit when I monitor it in the joystick settings panel, and only at the maximum of the pedal's movement. Do I need to adjust the variable in the "handbrake output" section? Edit: The answer is yes. I changed it from "Joystick.Y(z*4);" to "Joystick.Y(z*1);". Edited December 10, 2017 by dabneyd Share this post Link to post Share on other sites
Bucketsmith 0 Report post Posted February 7, 2018 Came across this site recently looking into running my newly bought (second hand) G25 set's pedals and shifter as standalone for some games where I want those, but not the wheel. The idea of using a micro-controller is superb 'cause I can make the project non-destructive to the original pedal and shifter and thus still use it with the wheel if I would desire to do so. I started out with planning to do this to my old Logitech MOMO Racing Force pedals, then ran across that second hand G25 for a normal price. (Oh my god, the prices for all those decent sets are really inflated. You'd think they were being used by cryptominers!) Anyways, I've got an Arduino Leonardo and an Uno that I can use. Right now, I used someone elses project to get the Leonardo to work with the pedals. It doesn't include support for the shifter. The other project I found does offer support for both pedals and shifter, but requires the Uno and UnoJoy library and some third party drivers to install on Windows, and I'm trying to avoid that. I prefer the device to be plug-and-play and use drivers Windows can find on its own. I hope someone will still read this thread. My questions are; What's the latest version of this project? The thread is confusing me a little bit, I'm unsure if the first post has been edited with the latest version or if there was some improved edit that someone made later? Will it be easy to convert to G25 usage? To simply make sure, can anyone tell me if this requires a third party Windows driver or if it's plug-and-play? Share this post Link to post Share on other sites
Stealthblackbird 1 Report post Posted February 7, 2018 Plug and play support is not possible with the Arduino because it does not support HID without UnoJoy. You will have to by a teensy 2.0, they aren't terribly expensive, especially if you buy a chinese one. Question about the MOMO racing force pedals, what exactly did you do with them? I have a MOMO racing force wheel and I've been trying to mod it to 900 degrees of rotation. Share this post Link to post Share on other sites
Bucketsmith 0 Report post Posted February 7, 2018 Plug and play support IS possible on Arduino, because I've already got the Arduino Leonardo working as a plug and play joystick controller. (With just the pedals, at the moment.) I take it you meant to talk about this project specifically and not Arduinos in general? The question is whether or not this project can natively run on a Leonardo, or if it can be adapted to run on it. In that case, it should be able to achieve plug and play capability. I've got the MOMO stored in my storage. Share this post Link to post Share on other sites
Stealthblackbird 1 Report post Posted February 7, 2018 Sorry, I'm not familiar with the Leonardo. I assumed you were talking about an Uno (and I may still be wrong with the Uno). It may be possible for the code to be adapted for the Leonardo. I agree with you that the code is a little confusing on which one is the latest version. There isn't really a version because each code in the comments is for someones specific purpose. Share this post Link to post Share on other sites
Bucketsmith 0 Report post Posted February 7, 2018 That's all right, I figured there was some miscommunication or misunderstanding somewhere. The Leonardo uses the Atmega32u4 as well, and it has onboard USB shizzle. With the pedal sketch I have now, it comes with an "arduino joystick" library that in turn depends on "dynamicHID" library. With this, you do not need any drivers on Windows, because it will see the arduino as an "adruino joystick". I do not know how limited that code is, though. For instance, I do not know if there are a maximum amount of axis and buttons that makes it inferior to UnoJoy. The Teensy 2.0 uses the same processor chip and it also has inbuild USB shizzle, so I'm guessing apart from having a different PINOUT, the code should be compatible. What you write about every version being for a very specific purpose makes sense, I understand why there are so many versions now. Maybe someone else already has one tailored to the G25 pedals and shifter combination, I'll have to check. I tried the G27 one by Jason Duncan at https://github.com/functionreturnfunction/G27_Pedals_and_Shifter. In the IDE it gives me errors that it references "G27" which is not defined. Share this post Link to post Share on other sites
rich239 0 Report post Posted March 24, 2018 I tried that repository too, and it gave me the same error, however, I used the following code, and it worked like a charm. I even got the onboard Power LED working on the shifter. You just need to ground the SPI input to get it to work. // // G25 shifter to USB interface // based on a Teensy 2.0 // // Modifications by Per Mejdal Rasmussen // * Adapted to Leonado / Pro Micro by using NicoHood HID // * Dpad uses "Point of View Hat" if dpad_mode is enabled (default) // * AnalogRead now uses [XY]_AXIS_PIN constant (bug fix) // // 3 operating modes // - H-pattern shifter // - Sequential shifter // - Analog handrake // // http://www.isrtv.com/forums/topic/13189-diy-g25-shifter-interface-with-h-pattern-sequential-and-handbrake-modes/ // // G25 shifter pinout (for G27: swap pin 1 and 7) // // DB9 Color Shifter Description Teensy // 1 Black 1 +5V +5V // 2 Grey 7 Button Data pin 17 // 3 Yellow 5 Button !CS & !PL pin 18 // 4 Orange 3 Shifter X axis pin 21 (A0) // 5 Red 2 SPI input GND -->> Needs to be grounded for the LED of the shifter to work!! // 6 White 8 GND GND // 7 Purple 6 Button Clock pin 19 // 8 Green 4 Shifter Y axis pin 20 (A1) // 9 Black 1 +5V // Download NicoHood HID from https://github.com/NicoHood/HID #include "HID.h" #include "HID-Project.h" // Pro Micro pin definitions #define LED_PIN 17 //Pro micro has no Led on pin 11 #define DATA_IN_PIN 14 //2 Button Data #define MODE_PIN 16 //3 Button !CS & !PL #define CLOCK_PIN 15 //7 Button Clock #define X_AXIS_PIN A0 //4 Shifter X axis #define Y_AXIS_PIN A1 //8 Shifter Y axis // H-shifter mode analog axis thresholds #define HS_XAXIS_12 400 #define HS_XAXIS_56 600 #define HS_YAXIS_135 800 #define HS_YAXIS_246 300 // Sequential shifter mode analog axis thresholds #define SS_UPSHIFT_BEGIN 670 #define SS_UPSHIFT_END 600 #define SS_DOWNSHIFT_BEGIN 430 #define SS_DOWNSHIFT_END 500 // Handbrake mode analog axis limits #define HB_MAXIMUM 530 #define HB_MINIMUM 400 #define HB_RANGE (HB_MAXIMUM-HB_MINIMUM) // Digital inputs definitions #define DI_REVERSE 1 #define DI_MODE 3 #define DI_RED_CENTERRIGHT 4 #define DI_RED_CENTERLEFT 5 #define DI_RED_RIGHT 6 #define DI_RED_LEFT 7 #define DI_BLACK_TOP 8 #define DI_BLACK_RIGHT 9 #define DI_BLACK_LEFT 10 #define DI_BLACK_BOTTOM 11 #define DI_DPAD_RIGHT 12 #define DI_DPAD_LEFT 13 #define DI_DPAD_BOTTOM 14 #define DI_DPAD_TOP 15 // Shifter state #define DOWN_SHIFT -1 #define NO_SHIFT 0 #define UP_SHIFT 1 // Shifter mode #define SHIFTER_MODE 0 #define HANDBRAKE_MODE 1 // LED blink counter int led=0; // Shifter state int shift=NO_SHIFT; // Handbrake mode int mode=SHIFTER_MODE; //Dpad mode int dpad_mode=1; // Called at startup // Must initialize hardware and software modules void setup() { // G25 shifter analog inputs configuration pinMode(X_AXIS_PIN, INPUT_PULLUP); // X axis pinMode(Y_AXIS_PIN, INPUT_PULLUP); // Y axis // G25 shift register interface configuration pinMode(DATA_IN_PIN, INPUT); // Data in pinMode(MODE_PIN, OUTPUT); // Parallel/serial mode pinMode(CLOCK_PIN, OUTPUT); // Clock // LED output mode configuration pinMode(LED_PIN, OUTPUT); // LED // Virtual joystick configuration Gamepad.begin(); // Virtual serial interface configuration Serial.begin(38400); // Digital outputs initialization digitalWrite(LED_PIN, LOW); digitalWrite(MODE_PIN, HIGH); digitalWrite(CLOCK_PIN, HIGH); } // Called in a loop after initialization void loop() { // Reading of button states from G25 shift register int b[16]; digitalWrite(MODE_PIN, LOW); // Parallel mode: inputs are read into shift register delayMicroseconds(10); // Wait for signal to settle digitalWrite(MODE_PIN, HIGH); // Serial mode: data bits are output on clock falling edge for(int i=0; i<16; i++) // Iteration over both 8 bit registers { digitalWrite(CLOCK_PIN, LOW); // Generate clock falling edge delayMicroseconds(10); // Wait for signal to settle b[i]=digitalRead(DATA_IN_PIN); // Read data bit and store it into bit array digitalWrite(CLOCK_PIN, HIGH); // Generate clock rising edge delayMicroseconds(10); // Wait for signal to settle } // Reading of shifter position int x=analogRead(X_AXIS_PIN); // X axis int y=analogRead(Y_AXIS_PIN); // Y axis // Handbrake mode logic if(b[DI_RED_CENTERLEFT]!=0) // Is left center red button depressed? { if(b[DI_RED_CENTERRIGHT]!=0) // Is right center red button also depressed? { if(b[DI_RED_RIGHT]!=0) // Is rightmost red button also depressed? { mode=HANDBRAKE_MODE; // Handbrake mode is activated if the 3 rightmost } // red buttons are depressed if(b[DI_RED_LEFT]!=0) // Is leftmost red button also depressed? { mode=SHIFTER_MODE; // Handbrake mode is deactivated if the 3 leftmost } // red buttons are depressed } } // Current gear calculation int gear=0; // Default value is neutral if(b[DI_MODE]==0) // H-shifter mode? { if(x<HS_XAXIS_12) // Shifter on the left? { if(y>HS_YAXIS_135) gear=1; // 1st gear if(y<HS_YAXIS_246) gear=2; // 2nd gear } else if(x>HS_XAXIS_56) // Shifter on the right? { if(y>HS_YAXIS_135) gear=5; // 5th gear if(y<HS_YAXIS_246) gear=6; // 6th gear } else // Shifter is in the middle { if(y>HS_YAXIS_135) gear=3; // 3rd gear if(y<HS_YAXIS_246) gear=4; // 4th gear } } else // Sequential mode { if(mode==SHIFTER_MODE) // Shifter mode? { Gamepad.zAxis(0); if(shift==NO_SHIFT) // Current state: no shift { if(y>SS_UPSHIFT_BEGIN) // Shifter to the front? { gear=1; // Shift-up shift=UP_SHIFT; // New state: up-shift } if(y<SS_DOWNSHIFT_BEGIN) // Shifter to the rear? { gear=2; // Shift-down shift=DOWN_SHIFT; // New state: down-shift } } if(shift==UP_SHIFT) // Current state: up-shift? { if(y>SS_UPSHIFT_END) gear=1; // Beyond lower up-shift threshold: up-shift else shift=NO_SHIFT; // Else new state: no shift } if(shift==DOWN_SHIFT) // Current state: down-shift { if(y<SS_DOWNSHIFT_END) gear=2; // Below higher down-shift threshold: down-shift else shift=0; // Else new state: no shift } } else // Handbrake mode { if(y<HB_MINIMUM) y=HB_MINIMUM; // Clip minimum position if(y>HB_MAXIMUM) y=HB_MAXIMUM; // Clip maximum position long offset=(long)y-HB_MINIMUM; y=(int)(offset*1023/HB_RANGE); // Scale input between minimum and maximum clip position Gamepad.zAxis(y/4+0x80); // Set handbrake analog output gear=0; // No gear engaged: neutral } } if(gear!=6) b[DI_REVERSE]=0; // Reverse gear is allowed only on 6th gear position if(b[DI_REVERSE]==1) gear=0; // 6th gear is deactivated if reverse gear is engaged // Release virtual buttons for all gears Gamepad.release(1); Gamepad.release(2); Gamepad.release(3); Gamepad.release(4); Gamepad.release(5); Gamepad.release(6); // Depress virtual button for current gear if(gear>0) Gamepad.press(gear); // Dpad positions // 812 // 703 // 654 int number_of_buttons = 16; if (dpad_mode) { number_of_buttons = 12; int dpad = 0; if(b[DI_DPAD_TOP]) { if (b[DI_DPAD_LEFT]) dpad = 8; else if (b[DI_DPAD_RIGHT]) dpad = 2; else dpad = 1; } else if (b[DI_DPAD_BOTTOM]) { if (b[DI_DPAD_LEFT]) dpad = 6; else if (b[DI_DPAD_RIGHT]) dpad = 4; else dpad = 5; } else { if (b[DI_DPAD_LEFT]) dpad = 7; if (b[DI_DPAD_RIGHT]) dpad = 3; } Gamepad.dPad1(dpad); } // Set state of virtual buttons for all the physical buttons (including reverse) for(int i=0; i<number_of_buttons; i++) { if (b[i]) { Gamepad.press(7+i); } else { Gamepad.release(7+i); } } // Write new virtual joystick state Gamepad.write(); // Write inputs and outputs (remove comments to debug) /* Serial.print(" X axis: "); Serial.print(x); Serial.print(" Y axis: "); Serial.print(y); Serial.print(" Digital inputs: "); for(int i=0; i<16; i++)Serial.print(b[i]); Serial.print(" "); Serial.print(" Gear: "); Serial.print(gear); Serial.print(" Mode: "); Serial.print(mode); Serial.print(" Shift: "); Serial.println(shift); */ // Blink the on-board LED if(++led==100) led=0; // Period is 100 cycles * 10ms = 1s if(led==0) digitalWrite(LED_PIN, LOW); // LED is off for 50 cycles if(led==50) digitalWrite(LED_PIN, HIGH); // LED is on for 50 cycles // Wait delay(10); // Wait for 10ms } Share this post Link to post Share on other sites
vazz3rt 0 Report post Posted October 6, 2018 Code for G27 shifter with 3 operating modes, switched using red buttons (h shifter 1+2, sequential shifter 1+3, handbrake 1+4) on Teensy 2.0++. Fixed critical error with X_AXIS_PIN & Y_AXIS_PIN defines not being used during analogRead, making remapping pins correctly impossible. This code should also work P&P for Teensy 2.0, as PIN_XX defines are used, instead of pin numbers. // // G27 shifter to USB interface // based on a Teensy++ 2.0 // Original by pascalh from insidesimracing.tv // http://insidesimracing.tv/forums/topic/13189-diy-g25-shifter-interface-with-h-pattern-sequential-and-handbrake-modes/ // Three operating modes: // 1. H-pattern shifter (press first + second red button) // 2. Sequential shifter (press first + third red button) // 3. Handbrake (press first + fourth red button) // G27 shifter pinout // DB9 female pinout as seen from G27 shifter connector - pin numbers match etched ones on G27 connector! // DB9 Color Description Teensy 2.0++ // 1 Purple Button Clock PIN_F1 // 2 Grey Button Data PIN_F0 // 3 Yellow Button !CS & !PL PIN_F5 // 4 Orange Shifter X axis PIN_F6 // 5 // 6 Black GND GND // 7 Red +5V VCC // 8 Green Shifter Y axis PIN_F4 // 9 // Teensy pin definitions #define LED_PIN 6 #define DATA_IN_PIN PIN_F0 #define MODE_PIN PIN_F5 #define CLOCK_PIN PIN_F1 #define X_AXIS_PIN PIN_F6 #define Y_AXIS_PIN PIN_F4 // H-shifter mode analog axis thresholds #define HS_XAXIS_12 400 #define HS_XAXIS_56 600 #define HS_YAXIS_135 800 #define HS_YAXIS_246 300 // Sequential shifter mode analog axis thresholds #define SS_UPSHIFT_BEGIN 670 #define SS_UPSHIFT_END 600 #define SS_DOWNSHIFT_BEGIN 430 #define SS_DOWNSHIFT_END 500 // Handbrake mode analog axis limits #define HB_MAXIMUM 530 #define HB_MINIMUM 400 #define HB_RANGE (HB_MAXIMUM-HB_MINIMUM) // Digital inputs definitions #define DI_REVERSE 1 #define DI_MODE 3 #define DI_RED_CENTERRIGHT 4 #define DI_RED_CENTERLEFT 5 #define DI_RED_RIGHT 6 #define DI_RED_LEFT 7 #define DI_BLACK_TOP 8 #define DI_BLACK_RIGHT 9 #define DI_BLACK_LEFT 10 #define DI_BLACK_BOTTOM 11 #define DI_DPAD_RIGHT 12 #define DI_DPAD_LEFT 13 #define DI_DPAD_BOTTOM 14 #define DI_DPAD_TOP 15 // Shifter state #define DOWN_SHIFT -1 #define NO_SHIFT 0 #define UP_SHIFT 1 // Shifter mode #define SHIFTER_MODE 1 #define SEQUENTIAL_SHIFTER_MODE 2 #define HANDBRAKE_MODE 3 // LED blink counter int led=0; // Shifter state int shift=NO_SHIFT; // Handbrake mode int mode=SHIFTER_MODE; // Called at startup // Must initialize hardware and software modules void setup() { // G25 shifter analog inputs configuration pinMode(X_AXIS_PIN, INPUT_PULLUP); // X axis pinMode(Y_AXIS_PIN, INPUT_PULLUP); // Y axis // G25 shift register interface configuration pinMode(DATA_IN_PIN, INPUT); // Data in pinMode(MODE_PIN, OUTPUT); // Parallel/serial mode pinMode(CLOCK_PIN, OUTPUT); // Clock // LED output mode configuration pinMode(LED_PIN, OUTPUT); // LED // Virtual joystick configuration Joystick.useManualSend(true); // Joystick output is synchronized // Virtual serial interface configuration Serial.begin(38400); // Virtual joystick initialization Joystick.X(0); Joystick.Y(0); Joystick.Z(0); Joystick.Zrotate(0); Joystick.sliderLeft(0); Joystick.sliderRight(0); // Digital outputs initialization digitalWrite(LED_PIN, LOW); digitalWrite(MODE_PIN, HIGH); digitalWrite(CLOCK_PIN, HIGH); } // Called in a loop after initialization void loop() { // Reading of button states from G25 shift register int b[16]; digitalWrite(MODE_PIN, LOW); // Parallel mode: inputs are read into shift register delayMicroseconds(10); // Wait for signal to settle digitalWrite(MODE_PIN, HIGH); // Serial mode: data bits are output on clock falling edge for(int i=0; i<16; i++) // Iteration over both 8 bit registers { digitalWrite(CLOCK_PIN, LOW); // Generate clock falling edge delayMicroseconds(10); // Wait for signal to settle b[i]=digitalRead(DATA_IN_PIN); // Read data bit and store it into bit array digitalWrite(CLOCK_PIN, HIGH); // Generate clock rising edge delayMicroseconds(10); // Wait for signal to settle } // Reading of shifter position int x=analogRead(X_AXIS_PIN); // X axis int y=analogRead(Y_AXIS_PIN); // Y axis // Handbrake mode logic if(b[DI_RED_LEFT]!=0) // Is left red button depressed? { if(b[DI_RED_CENTERLEFT]!=0) { mode=SHIFTER_MODE; Joystick.X(0); } if(b[DI_RED_CENTERRIGHT]!=0) { mode=SEQUENTIAL_SHIFTER_MODE; Joystick.X(0); } if(b[DI_RED_RIGHT]!=0) { mode=HANDBRAKE_MODE; } } // Current gear calculation int gear=0; // Default value is neutral if(mode==SHIFTER_MODE) // H-shifter mode? { if(x<HS_XAXIS_12) // Shifter on the left? { if(y>HS_YAXIS_135) gear=1; // 1st gear if(y<HS_YAXIS_246) gear=2; // 2nd gear } else if(x>HS_XAXIS_56) // Shifter on the right? { if(y>HS_YAXIS_135) gear=5; // 5th gear if(y<HS_YAXIS_246) gear=6; // 6th gear } else // Shifter is in the middle { if(y>HS_YAXIS_135) gear=3; // 3rd gear if(y<HS_YAXIS_246) gear=4; // 4th gear } } else if(mode==SEQUENTIAL_SHIFTER_MODE) // Sequential mode { Joystick.X(0); if(shift==NO_SHIFT) // Current state: no shift { if(y>SS_UPSHIFT_BEGIN) // Shifter to the front? { gear=1; // Shift-up shift=UP_SHIFT; // New state: up-shift } if(y<SS_DOWNSHIFT_BEGIN) // Shifter to the rear? { gear=2; // Shift-down shift=DOWN_SHIFT; // New state: down-shift } } if(shift==UP_SHIFT) // Current state: up-shift? { if(y>SS_UPSHIFT_END) gear=1; // Beyond lower up-shift threshold: up-shift else shift=NO_SHIFT; // Else new state: no shift } if(shift==DOWN_SHIFT) // Current state: down-shift { if(y<SS_DOWNSHIFT_END) gear=2; // Below higher down-shift threshold: down-shift else shift=0; // Else new state: no shift } } else if(mode==HANDBRAKE_MODE) { if(y<HB_MINIMUM) y=HB_MINIMUM; // Clip minimum position if(y>HB_MAXIMUM) y=HB_MAXIMUM; // Clip maximum position long offset=(long)y-HB_MINIMUM; y=(int)(offset*1023/HB_RANGE); // Scale input between minimum and maximum clip position Joystick.X(y); // Set handbrake analog output gear=0; // No gear engaged: neutral } if(gear!=6) b[DI_REVERSE]=0; // Reverse gear is allowed only on 6th gear position if(b[DI_REVERSE]==1) gear=0; // 6th gear is deactivated if reverse gear is engaged // Release virtual buttons for all gears Joystick.button(1, LOW); Joystick.button(2, LOW); Joystick.button(3, LOW); Joystick.button(4, LOW); Joystick.button(5, LOW); Joystick.button(6, LOW); // Depress virtual button for current gear if(gear>0) Joystick.button(gear, HIGH); // Set state of virtual buttons for all the physical buttons (including reverse) for(int i=0; i<16; i++) Joystick.button(7+i, b[i]); // Write new virtual joystick state Joystick.send_now(); // Write inputs and outputs (remove comments to debug) // Serial.print(" X axis: "); // Serial.print(x); // Serial.print(" Y axis: "); // Serial.print(y); // Serial.print(" Digital inputs: "); // for(int i=0; i<16; i++)Serial.print(b[i]); // Serial.print(" "); // Serial.print(" Gear: "); // Serial.print(gear); // Serial.print(" Mode: "); // Serial.print(mode); // Serial.print(" Shift: "); // Serial.println(shift); // Blink the on-board LED if(++led==100) led=0; // Period is 100 cycles * 10ms = 1s if(mode==SHIFTER_MODE) { if(led==0) digitalWrite(LED_PIN, HIGH); // LED is on } else if(mode==SEQUENTIAL_SHIFTER_MODE) { if(led==0) digitalWrite(LED_PIN, LOW); // LED is off for 50 cycles if(led==50) digitalWrite(LED_PIN, HIGH); // LED is on for 50 cycles } else if(mode==HANDBRAKE_MODE) { if(led==0) digitalWrite(LED_PIN, LOW); if(led==25) digitalWrite(LED_PIN, HIGH); if(led==50) digitalWrite(LED_PIN, LOW); if(led==75) digitalWrite(LED_PIN, HIGH); } // Wait delay(10); // Wait for 10ms } Share this post Link to post Share on other sites
pascalh 34 Report post Posted October 6, 2018 (edited) I am really amazed to see that this thread is still alive after 4 years with new and interesting ideas ? Edited October 6, 2018 by pascalh Share this post Link to post Share on other sites
Maartijmm 0 Report post Posted October 25, 2018 Greetings. By the way, you could describe how to attach the arduino board to the box (project enclosure). I can not find a way that looks good and safe! If you have photos / tutorial I would be very grateful. Thank you! Share this post Link to post Share on other sites
pascalh 34 Report post Posted October 25, 2018 2 hours ago, Maartijmm said: Greetings. By the way, you could describe how to attach the arduino board to the box (project enclosure). I can not find a way that looks good and safe! If you have photos / tutorial I would be very grateful. Thank you! I simply used thick double sided tape. You could also use a wire going through 2 holes on the back of the box and soldered to 2 unused through holes of the Teensy Share this post Link to post Share on other sites