Struggling with Digital Joystick Readouts

Hello,

I'm playing around with a Sanwa digital arcade joystick that I scavenged up from a work project. I'm just barely an electrician by any real standard, and as far as I understand this is essentially just four buttons that you are pressing (completing a circuit) by moving the joystick in whichever direction. I confirmed this (and that the joystick works seemingly) by hooking it up to a multimeter and testing the connection between the "direction" cables and the "ground" cable while pressing a direction. As far as I can tell, it works fine.

I just barely understand digital inputs on the Arduino Uno (Have programmed some simple outputs to servos but that's pretty much it) but I wrote this simple program to spew out some info to let me know that I'm getting a reading from the joystick.

int inRight = 8;
int inLeft = 9;
int inDown = 10;
int inUp = 11;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  pinMode(inRight, INPUT);
  pinMode(inLeft, INPUT);
  pinMode(inDown, INPUT);
  pinMode(inUp, INPUT);
}
 String p1 = "x";
void loop() {
  // put your main code here, to run repeatedly:
  int outOne = digitalRead(inRight);
  int outTwo = digitalRead(inLeft);
  int outThree = digitalRead(inDown);
  int outFour = digitalRead(inUp);

  Serial.println(outOne + p1 + outTwo + p1 + outThree + p1 + outFour);

  delay(200);
}

Now when I directly connect the input to voltage, it seems to read just fine and I'll get my ugly stream of ones for that pin telling me something is happening. But when I plug the joystick in (and I've made sure I know which pin is the ground many many times) I get only ones from the digital reading, suddenly everything lights up. I've tried PULLUP i've tried PULLDOWN. I know there isn't a short in the joystick.

Could there really be that much noise coming from the joystick output? Or am I missing something more obvious? My understanding of circuitry is bad and my code it worse but this feels like it should be simple.

Thanks.

Hi, @theesweettea
Welcome to the forum.

Have you got the joystick switches, switching to gnd?
If so then INPUT_PULLUP should give you highs and lows.

Connect you DMM to gnd and one of the UNO inputs that is connected to a joystick switch and see if you can measure approx 5V with switch open and 0V with it closed.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you post some images of your project?
So we can see your component layout.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

Make sure that the system is unpowered when you plug anything into a processor, unless that thing has been designed to be "hot pluggable". Most devices are not designed for this, and you can cause damage and malfunction to both the processor and device if you do so.

Good advice, good habit.

The device in question appears to be nothing more electrically than four microswitches, so unless a person did something srsly dumb it shouldn’t damage anything.

I would consider it to be as hot-pluggable as it gets.

What means this?

You can use INPUT_PULLUP for the pin mode all inputs, with the common on the joystick going to the ground on the Arduino and the four signals wired to the inputs.

If that doesn’t work, we can’t help until you post a schematic. I know, I know, simple circuit. But maybe drawing it will help you see the error you may have made.

A picture or two would be worth uploading, and the code when you’ve changed the pin mode. Again, simple enough, but maybe posting it will help you see the error you may have made.

Both will def help us help.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.