Joy stick addon as well?

General GBZ-related chat goes here. Share ideas, tips and tricks, or ask questions that don't fit into the hardware/software help forums.
User avatar
Ganreizu
Posts: 552
Joined: Thu May 05, 2016 8:20 am
Has thanked: 168 times
Been thanked: 97 times

Re: Joy stick addon as well?

Post by Ganreizu » Mon May 23, 2016 10:44 am

wermy wrote:Yep. There are 4 pins to wire up, and then some simple Arduino code to add to the Teensy sketch. You'd want to change it from doing keyboard events to doing gamepad events for the buttons too.
Isn't gamepad events a better idea anyway since then we'll be able to have multiple button presses at once?

I would want a joystick eventually because a D pad isn't ideal for the awesome N64 titles we can play with as long as it can be done right. If we can get a joystick that fits the shell and isn't awkward then i would fit a joystick immediately. Joysticks aren't better than Dpad for old systems but it's workable compared to a Dpad on N64.

Maybe we can find one that's as small as the new 3DS joystick and put it to the side of the Dpad even and then we would have both to use?

petran1420
Posts: 96
Joined: Sun May 08, 2016 8:59 pm
Has thanked: 1 time
Been thanked: 18 times

Re: Joy stick addon as well?

Post by petran1420 » Mon May 23, 2016 10:53 am

Here is a video of an analog joystick being used, placed below the dpad, and to the left:

https://www.youtube.com/watch?v=_MpcG3BE19U

In the comments, the author writes:
It's a 3DS slider with a PSP cap. I chose the 3DS analog stick over the PSP one because it is slimmer.

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Joy stick addon as well?

Post by wermy » Mon May 23, 2016 10:57 am

Ganreizu wrote:
wermy wrote:Yep. There are 4 pins to wire up, and then some simple Arduino code to add to the Teensy sketch. You'd want to change it from doing keyboard events to doing gamepad events for the buttons too.
Isn't gamepad events a better idea anyway since then we'll be able to have multiple button presses at once?

I would want a joystick eventually because a D pad isn't ideal for the awesome N64 titles we can play with as long as it can be done right. If we can get a joystick that fits the shell and isn't awkward then i would fit a joystick immediately. Joysticks aren't better than Dpad for old systems but it's workable compared to a Dpad on N64.

Maybe we can find one that's as small as the new 3DS joystick and put it to the side of the Dpad even and then we would have both to use?
Multiple button-presses do work, though. I did have someone else ask the same question a while back, are you testing on a text editor or something? If so then yes it will look like only one key is being held down at a time. But when you load up a game in an emulator it works fine. :)
ImageImageImageImage

petran1420
Posts: 96
Joined: Sun May 08, 2016 8:59 pm
Has thanked: 1 time
Been thanked: 18 times

Re: Joy stick addon as well?

Post by petran1420 » Thu May 26, 2016 4:47 pm


I'll try to remember to post some sample code when I get home (as well as how I had it wired).
Hi @wermy

By any chance did you come across your sample code/4 pins to us for wiring this up?

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Joy stick addon as well?

Post by wermy » Fri May 27, 2016 6:32 pm

petran1420 wrote: Hi @wermy

By any chance did you come across your sample code/4 pins to us for wiring this up?
Hey sorry for the delay. This was a work-in-progress (basically a couple chunks of sample code with some sort of auto-calibration stuff I was adding):

Code: Select all

const bool DEBUG = true;  // set to true to debug the raw values

int xPin = A0;
int yPin = A1;
int xZero, yZero;
int xValue, yValue;
int deadzone = 5;  // smaller values will be set to 0
int xPosMax = 0;
int xNegMax = 0;
int yPosMax = 0;
int yNegMax = 0;

void setup() {
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);

  if (DEBUG) {
    Serial.begin(9600);
  }

  // calculate neutral position
  xZero = analogRead(xPin);
  yZero = analogRead(yPin);

  //thumbSt.xAxis = 0;
  //thumbSt.yAxis = 0;

  xPosMax = 0;
  xNegMax = 0;

  yPosMax = 0;
  yNegMax = 0;
}

void loop() {
  xValue = analogRead(xPin) - xZero;
  yValue = analogRead(yPin) - yZero;

  if (abs(xValue) < deadzone) {
    xValue = 0;
  }
  if (abs(yValue) < deadzone) {
    yValue = 0;
  }

  if (xValue > 0 && xValue > xPosMax) {
    xPosMax = xValue;
  } else if (xValue < 0 && xValue < xNegMax) {
    xNegMax = xValue;
  }

  if (yValue > 0 && yValue > yPosMax) {
    yPosMax = yValue;
  } else if (yValue < 0 && yValue < yNegMax) {
    yNegMax = yValue;
  }

  float xMax = abs(xPosMax);
  if (xValue < 0) {
    xMax = abs(xNegMax);
  }

  float yMax = abs(yPosMax);
  if (yValue < 0) {
    yMax = abs(yNegMax);
  }
  if (DEBUG && (xValue != 0 || yValue != 0)) {
    Serial.print("X: ");
    Serial.print((float)((float)xValue / xMax));
    Serial.print(", Y: ");
    Serial.print((float)((float)yValue / yMax));
    Serial.print(", Raw X: ");
    Serial.print(xValue);
    Serial.print(", xPosMax: ");
    Serial.print(xPosMax);
    Serial.print(", xNegMax: ");
    Serial.print(xNegMax);
    Serial.print(", Raw Y: ");
    Serial.print(yValue);
    Serial.print(", yPosMax: ");
    Serial.print(yPosMax);
    Serial.print(", yNegMax: ");
    Serial.println(yNegMax);
  }

}
Again, this was something I whipped up in like half an hour so I don't think I'd just plop it into a GBZ or something just yet. :) But what I did add seems to work fairly well: when it starts running you can make a full circle a few times with the joystick and it should sort of calibrate itself with regards to max values in x/y. You can use xValue/xMax and yValue/yMax to get a value between 0 and 1, which I *think* is what you need for an HID joystick. If not then it is easy enough to go from that to whatever range of values you need.

I used this as a reference (and I think I took some chunks of code from here too): http://www.instructables.com/id/Add-a-l ... /?ALLSTEPS

Pins A0 and A1 will vary depending on what you're using. If it's a Teensy then you can look here to see which ones they are:
https://www.pjrc.com/teensy/pinout.html

Have fun!
ImageImageImageImage

petran1420
Posts: 96
Joined: Sun May 08, 2016 8:59 pm
Has thanked: 1 time
Been thanked: 18 times

Re: Joy stick addon as well?

Post by petran1420 » Mon May 30, 2016 6:38 pm

@wermy ,

I'm usually only capable of showing gratitude through .gif s, but since I can't do that here I'll have to settle for this: :D :D :D :D :D :D :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest