Saturday, April 8, 2017

Funduino Joystick shield

Funduino Joystick shield

From Aliexpress i got a Arduino Gamepads JoyStick KeypadShield PS2  (I recently found it at another seller for 2,33 Euro ) 


Using Google i found out there are some different versions.
My shield  (V1.A ) uses the following connections

D2 Key A UP
D3 Key B RIGHT
D4 Key C DOWN
D5 Key D LEFT

D6 Key E Start
D7 Key F Select

D8 Analog button
A0 AnalogX Joystick
A1 AnalogY Joystick

There are some headers to get to the other Arduino pins.

Some headers are pre arranged for special interfaces (On my board I2C, Bluetooth, Nokia5110 display, nRF24L01)
A slide switch to select between 3V3 and 5V mode.
A red power led

TestScript

/*
JoystickArduinoBasicExample

A basic sketch to demonstrate reading values from the joystick shield

How to use:
* Connect joystick shield to your Arduino
* Upload this sketch to your Arduino
* Open the Arduino IDE Serial Monitor (set to 9600 baud)
* Waggle joystick, push buttons

Requires:
* Arduino
* Joystick Shield

April 2017 by JJ adapted version of a version
written for SparkFun Arduino Inventor's Kit CIRC-JOY
Based on original example by Ryan Owens
*/

// Store the Arduino pin associated with each input

const byte PIN_BUTTON_UP = 2;
const byte PIN_BUTTON_RIGHT = 3;
const byte PIN_BUTTON_DOWN = 4;
const byte PIN_BUTTON_LEFT = 5;

const byte PIN_BUTTON_START = 6;
const byte PIN_BUTTON_SELECT = 7;

const byte PIN_BUTTON_JOY = 8; // Select button is triggered when joystick is pressed
const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;

void setup() {
Serial.begin(9600);
// Specify each pin connected to a pushbutton as an input.
// Also enable the Arduino's internal "pull-up" resistors
// for each pushbutton we want to read--this means the shield
// doesn't need to have resistors on it.
// Note that when a pull-up resistor is used on a pin the
// meaning of the values read are reversed compared to their
// usual meanings:

// * HIGH = the button is not pressed
// * LOW = the button is pressed

pinMode(PIN_BUTTON_RIGHT, INPUT);
digitalWrite(PIN_BUTTON_RIGHT, HIGH);

pinMode(PIN_BUTTON_LEFT, INPUT);
digitalWrite(PIN_BUTTON_LEFT, HIGH);

pinMode(PIN_BUTTON_UP, INPUT);
digitalWrite(PIN_BUTTON_UP, HIGH);

pinMode(PIN_BUTTON_DOWN, INPUT);
digitalWrite(PIN_BUTTON_DOWN, HIGH);

pinMode(PIN_BUTTON_START, INPUT);
digitalWrite(PIN_BUTTON_START, HIGH);

pinMode(PIN_BUTTON_SELECT, INPUT);
digitalWrite(PIN_BUTTON_SELECT, HIGH);

pinMode(PIN_BUTTON_JOY, INPUT);
digitalWrite(PIN_BUTTON_JOY, HIGH);
}

void loop() {
// Print the current values of the inputs (joystick and
// buttons) to the console.
Serial.print("l:");
Serial.print(digitalRead(PIN_BUTTON_LEFT));
Serial.print(" ");
Serial.print("r:");
Serial.print(digitalRead(PIN_BUTTON_RIGHT));
Serial.print(" ");

Serial.print("u:");
Serial.print(digitalRead(PIN_BUTTON_UP));
Serial.print(" ");

Serial.print("d:");
Serial.print(digitalRead(PIN_BUTTON_DOWN));
Serial.print(" / ");

Serial.print("g:");
Serial.print(digitalRead(PIN_BUTTON_START));
Serial.print(" ");

Serial.print("s:");
Serial.print(digitalRead(PIN_BUTTON_SELECT));
Serial.print(" / ");

Serial.print("j:");
Serial.print(digitalRead(PIN_BUTTON_JOY));
Serial.print(" ");

Serial.print("x:");
Serial.print(analogRead(PIN_ANALOG_X));
Serial.print(" ");
Serial.print("y:");
Serial.print(analogRead(PIN_ANALOG_Y));
Serial.print(" ");

Serial.println();
}

Links

No comments: