Issue reading optical encoder from N64 Analog Stick

Status
Not open for further replies.

Kainev

New member
Hi,

I'm trying to read the position of an Nintendo 64 controller's analog stick. It uses two optical encoders, one for the X and one for the Y direction.

For testing purposes, I am just attempting to read the X value for now and I've connected the analog sticks pin 1 and 4 which are the encoder outputs for the X axis on the N64 stick to pin 0 and pin 1 on the teensy.
192px-Analogstick-pinout-diagram.png

I have the N64 controller plugged into the Nintendo so it is receiving power, and I have my Teensy 3.5 plugged in via USB.
wiring.jpg

My sketch (via arduino):
Code:
static int Ix = 0;
static int Qx = 1;

volatile int count_x = 0;

void setup() {
  Serial.begin(9600);

  pinMode(Ix, INPUT);
  pinMode(Qx, INPUT);

  attachInterrupt(0, detectX, CHANGE);
}

void loop() {
  Serial.print("X: ");
  Serial.println(count_x);
    
  delay(10);
}

void detectX()
{
  if(digitalRead(Ix) == digitalRead(Qx))
  {
    count_x++;
  }
  else
  {
    count_x--;
  }
}

While running, if I move the analog stick in a direction count_x will generally change to a value of 1, and when I release it it goes back to 0, so something is being detected but it's not tracking the position correctly. This code is basically from a youtube video, and there is a blog of someone else using this code specifically for an N64 analog stick so I believe the issue is most likely elsewhere. I've very little electronics experience, coming from a programming background.

Kind regards,
Kaine
 
I just tried powering the teensy by connecting to the controller and unplugging the USB, and put an if condition to turn the LED off if count_x goes over 10 and that doesn't solve it either
256731679_424908749170479_1022046270141160542_n.jpg

EDIT:
I just downloaded a controller test rom, and it actually is only outputting a value of 0 or 1! I tested the stick with another controller board, and it worked fine, and I tested another stick I know to be working with the controller board hooked up to the teensy and it had the 0-1 problem too. So I'll try connecting to a new controller and see what happens.
 
Last edited:
Update
Okay so I've wired up to a different controller board and am now getting some values. The code in my first post will print values in a range of roughly -35 to +40, so it's definitely on the right track, however I know this stick in the N64 is outputting values from -70 to +80, it appears as though I'm not able to detect all the changes. What could potentially cause this?
 
Status
Not open for further replies.
Back
Top