Leostick Joystick? Yes, and here's how.

A shrunk down Leonardo-compatible board, thumb drive sized with native USB support. [Product info]
RamjetR
Posts: 5
Joined: Wed Jan 02, 2013 10:44 am

Re: Leostick Joystick? Yes, and here's how.

Post by RamjetR » Sun Nov 01, 2015 4:05 am

nimrod77 wrote:
nimrod77 wrote:
RamjetR wrote:Spent several days putting this together and since most of the knowledge I used came from here. It's good to give back to the community.

8 Axis, 10bits per axis
8 Buttons (active low)

Used to upgrade Logitech G25/G27 Pedals from 8bit to 10bit resolution. Works great. Please read the comments in the file if your unsure. And note that you need to put the USBAPI.h file in the correct place as it doesn't seem to override from within the IDE... also the HID.cpp file works fine from the sketch folder... odd..

Anywho... here is what I have been working on.

Enjoy :)
Ramjet.
Hi RamjetR I am building a set of diy rudder pedals and I want to use a Arduino micro for this. The 10bit code you have created is perfect for what I want. Would it be difficult to modify the code to only have Z axis? I plan on using a hall sensor as the input as shown here http://www.simpits.org/geneb/?p=299
Any info or help will be gratefully received!

Thanks for the reply Ramjet. All very clear and after playing with the sketch you provided. I can not see any inversion code however. Where would I put that code if I needed to?
Thanks for all your work.
How to invert the input to the output...

Code: Select all

        
        joySt.rudder = 512; // Defaults to centre value if it is not enabled.
        if(rudder_Enable) { // If enabled then update the value from the analog pin
          joySt.rudder = analogRead(A0); // Default A1 pin
          if(rudder_Invert) { // If Invert is enabled, then update the value inverted... ie swap max/min value
            joySt.rudder = (1023) - analogRead(A0); // Default A0 pin
          }
        }

piccolo456
Posts: 4
Joined: Mon Oct 26, 2015 7:40 pm

Re: Leostick Joystick? Yes, and here's how.

Post by piccolo456 » Tue Nov 03, 2015 1:51 pm

RamjetR wrote:
piccolo456 wrote:Thanks Ramjet.

I found your code really useful.

I am a beginner coder, so bear with me. I am building a Controller for my stationary bike, currently the brake leaver is the throttle.
I would like to use a hall effect sensor to measure the crank speed as a throttle (below 60rpm = stop 90rpm and up = max speed).
do you think the arduino will be able to handle all the instructions and watch the RPM. I have found some code to do the rpm measurement I just dont know where and how to add it to your code.
I'm glad you could follow it and it's helping people :)

Okay, check out where each axis does it's analogRead(A0)? Well that is where you would assign the value of your RPM...

Say for example, you have a piece of code which is taking an input from your sensor. I'm guessing a pulse of some sort? And you end up with a variable with the current value of the RPM in it?

Take a look at how I would integrate it below. Keep in mind I don't know the code your using to read an RPM value so I just made the assumption that you have some code and end up with a variable which has the value ready to put into the gamepad code.

Code: Select all

joySt.throttle = 512; // Presets this value i.e. Defaults to 512 value if it is not enabled.
        if(throttle_Enable) { // If enabled then update the value from the analog pin
          
          if(rpm < 90){ // if rpm is less than 90, set the throttle to zero.
          	joySt.throttle = 0;
          }
          if (rpm >= 90){ // if rpm is greater than 90rpm then we want to tell the PC we are moving ... and scale it nicely too :)
          	//normal output? 
          	int throttleVal = (map(rpm,minRPM,maxRPM,0,1023));
          	// Invert the output?
          	if(throttle_Invert) { // If Invert is enabled, then update the value inverted... ie swap max/min value
            	int throttleVal = (1023) - (map(rpm,minRPM,maxRPM,0,1023)); // scales the throttle value of rpm between the minRPM and maxRPM to to the scale needed by the throttle axis in game      
          	}
          joySt.throttle  = constrain(throttleVal,0,1023);// Final constrain to make sure the output to the game is correctly limited to 10bits. 
          }
        
        }
So from your spec, I figured anything less than 90rpm was essentially zero... and anything 90 or more is some kind of throttle. Also you can scale the minimum and maximum value of RPM to scale it nicely to 0-1023

Thanks, I will see if I can implement that part into my code.
Do you think I should use an interrupt for the RPM sensor so that I don't miss a pulse, or will that mess up the rest of the code.
I assume I can just try and see what happens.

RamjetR
Posts: 5
Joined: Wed Jan 02, 2013 10:44 am

Re: Leostick Joystick? Yes, and here's how.

Post by RamjetR » Wed Nov 04, 2015 12:14 pm

piccolo456 wrote: Thanks, I will see if I can implement that part into my code.
Do you think I should use an interrupt for the RPM sensor so that I don't miss a pulse, or will that mess up the rest of the code.
I assume I can just try and see what happens.
I'm assuming your not doing much in the interrupt other than incrementing your counter in your global variable keeping count of the RPMs? It should cause any problems. Just try not to use delays in your interrupts to make your that your in and out of the interrupt as fast as you can and can get back to the main loop.

Worst case scenario, if you're doing too much away from the main loop. You might see a small delay in getting the updates to the PC.

For a point of reference, the final version of my 10Bit pedal adaptor I made for a few of my OZNZSimRacing.com forum members Logitech pedals. I am able to update the PC at over 400fps whilst still sending data out of the serial port. So, it should be fine.

piccolo456
Posts: 4
Joined: Mon Oct 26, 2015 7:40 pm

Re: Leostick Joystick? Yes, and here's how.

Post by piccolo456 » Fri Nov 06, 2015 1:27 pm

thanks for all your help. That racing forum looks like fun.

auron-muc
Posts: 1
Joined: Sat Dec 19, 2015 1:48 pm

Re: Leostick Joystick? Yes, and here's how.

Post by auron-muc » Sat Dec 19, 2015 3:09 pm

I took the liberty and converted the code to a library working with the newest Arduino-IDE which includes the Pluggable HID classes.

See https://github.com/auron-muc/arduino-leonardo-joystick

I heavily modified the HID Descriptor- basically rewrote it from scratch - and allow a variabe (compile time defines) amount of axes, buttons and hats.

please let me know what you think.

Cheers,
Tobias

waveform
Posts: 1
Joined: Tue Apr 12, 2016 9:27 pm

Re: Leostick Joystick? Yes, and here's how.

Post by waveform » Tue Apr 12, 2016 9:36 pm

RamjetR wrote:Spent several days putting this together and since most of the knowledge I used came from here. It's good to give back to the community.

Used to upgrade Logitech G25/G27 Pedals from 8bit to 10bit resolution.
Thanks a lot for sharing this Ramjet, I also will be using this for my G27 plus a hydraulic handbrake when I have it built.

Have you got another .ino file with code that you specifcally use for your G25/G27 Pedals?

The reason I ask is because each pedal has a deadzone on both sides of the axis, and I was wondering if you eliminated this deadzone in your own code?

I would also like to invert each axis but I have no coding experience, just know how to edit values and such, as most games need to have the invert option enabled the way the code you shared is setup currently.

If anyone else reading this can help out too I would really appreciate it.

I will be making an instructable of my project just to help others out also.

Thanks for your time,
Waveform.

Post Reply