Leostick Joystick? Yes, and here's how.

A shrunk down Leonardo-compatible board, thumb drive sized with native USB support. [Product info]
angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

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

Post by angusgr » Thu Apr 30, 2015 6:20 am

Awesome, thanks for sharing that Ashley!

tabpol95
Posts: 1
Joined: Mon Aug 10, 2015 12:48 pm

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

Post by tabpol95 » Mon Aug 10, 2015 12:53 pm

Hay drake250 is it possible to emulate 2 joysticks, 20+ buttons and a 8way hat switch at the same time? cos i really would like to..... plez tell me. if you want more info just ask.

edit: it seems that some thing went wrong and my code throws errors whenever i use any of the keyboard or mouse commands.
see the code here: https://drive.google.com/open?id=0B6rm4 ... 0lUaU5OSzA
reference pic:
Capture.PNG

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

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

Post by RamjetR » Tue Sep 22, 2015 12:39 am

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.
Attachments
leoJoy10bit_RamjetX.zip
(10.51 KiB) Downloaded 217 times

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

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

Post by angusgr » Thu Sep 24, 2015 4:51 am

Excellent, thanks for sharing that Ramjet!

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

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

Post by piccolo456 » Mon Oct 26, 2015 7:48 pm

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.

nimrod77
Posts: 2
Joined: Thu Oct 29, 2015 7:49 am

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

Post by nimrod77 » Thu Oct 29, 2015 7:54 am

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!

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

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

Post by piccolo456 » Fri Oct 30, 2015 6:15 pm

Hi,

Since I'm not a professional coder I will try to answer :roll:

In the original code (leoJoy10bit_RamjetX.ino) in line 49-59 you can set all the Axis to false except the zAxis. as shown below.

Code: Select all

  */
    bool xAxis_Enable = false;
    bool yAxis_Enable = false;
    bool zAxis_Enable = true;
    bool xRotAxis_Enable = false;
    bool yRotAxis_Enable = false;
    bool zRotAxis_Enable = false;
    bool throttle_Enable = false;
    bool rudder_Enable = false;
    bool hatSw1_Enable = false;
    bool hatSw2_Enable = false;
    bool buttons_Enable = false;

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

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

Post by RamjetR » Sat Oct 31, 2015 9:27 am

nimrod77 wrote: 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!
Yeah just as Piccolo said, just make true or false which axis you want to use..

Also, I think I left in there a Invert option to swap the input depending on how you wire up your rudder pedals. Sometimes it's just easier to invert it in software than to rewire something.

I haven't used any hall effect sensors in years... last time I did it was a Allegro 3144 Hall effect switch (schmitt triggered). It worked great as a switch but you want an analogue output from a hall effect sensor.

So take a look in the code and you'll see where each axis does a analogRead(A0). Just change the A0 to match the pin your putting your hall effect sensor on. It's an analog pin so as long as your sensor is giving out a range of 0V to 5V you are good to go. You may just want to take out the PULLUP declaration in the pin setup. What the PULLUP does is enable the internal pull up resistor... I think from memory it's about 22Kohm and shouldn't effect your external sensor voltage input. But if it is, just make that an INPUT, not INPUT_PULLUP.

I'll look at the link as it's something I could also use to with my racing sim stuff so definitely interested to read up and have a go myself.

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

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

Post by RamjetR » Sat Oct 31, 2015 9:45 am

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

nimrod77
Posts: 2
Joined: Thu Oct 29, 2015 7:49 am

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

Post by nimrod77 » Sat Oct 31, 2015 1:04 pm

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.

Post Reply