Custom Handheld Arcade console with Raspberry Pi3

Got an idea for a project? Found a cool project you want to share? Post it here!
steelnation248
Posts: 18
Joined: Fri Jun 10, 2016 7:21 am
Has thanked: 2 times
Been thanked: 1 time

Re: Custom Handheld Arcade console with Raspberry Pi3

Post by steelnation248 » Fri Jun 10, 2016 7:27 am

The project looks great! I was wondering how you were able to code the PSP analog stick?

User avatar
tronicgr
Posts: 143
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 95 times
Been thanked: 67 times
Contact:

Re: Custom Handheld Arcade console with Raspberry Pi3

Post by tronicgr » Fri Jun 10, 2016 7:50 am

steelnation248 wrote:The project looks great! I was wondering how you were able to code the PSP analog stick?
Using the Teensy. Its emulating joystick and keyboard. See code below:

Code: Select all

/* Complete USB Joystick /keyboard Example
   Teensy becomes a USB joystick with 11 buttons and 2 axis input
   Button 12 is ESC keyboard, and button 13 is ENTER keyboard.
   You must select Joystick and Keyboard from the "Tools > USB Type" menu

   Pushbuttons should be connected between the digital pins and ground.
   Potentiometers should be connected to analog inputs 0 to 5.

   Analog joystick was PSP micro 2-axis
*/
#include <Bounce.h>

Bounce button9 = Bounce(12, 10);
Bounce button10 = Bounce(13, 10);

// Configure the number of buttons.  Be careful not
// to use a pin for both a digital button and analog
// axis.  The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 12;  // 16 for Teensy, 32 for Teensy++

void setup() {
  // you can print to the serial monitor while the joystick is active!
  Serial.begin(9600);

  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  
  // configure the joystick to manual send mode.  This gives precise
  // control over when the computer receives updates, but it does
  // require you to manually call Joystick.send_now().
  Joystick.useManualSend(true);
  for (int i=0; i<numButtons; i++) {
    pinMode(i, INPUT_PULLUP);
  }
 // Serial.println("Begin Complete Joystick Test");
}

byte allButtons[numButtons];
byte prevButtons[numButtons];

void loop() {

    button9.update();
    button10.update();

    if (button9.fallingEdge()) {
    Keyboard.set_key1(KEY_ENTER);
    Keyboard.send_now();  // send the button press
    Keyboard.set_key1(0);
    Keyboard.send_now();  // send the button release
  }
  if (button10.fallingEdge()) {
    Keyboard.set_key1(KEY_ESC);
    Keyboard.send_now();  // send the button press
    Keyboard.set_key1(0);
    Keyboard.send_now();  // send the button release
  }
  
  // read 6 analog inputs and use them for the joystick axis
  Joystick.X(map(analogRead(0),170, 853, 1023, 0));
  Joystick.Y(map(analogRead(1),170, 853, 0, 1023));
 
  
  // read digital pins and use them for the buttons
  for (int i=0; i<numButtons; i++) {
    if (digitalRead(i)) {
      // when a pin reads high, the button is not pressed
      // the pullup resistor creates the "on" signal
      allButtons[i] = 0;
    } else {
      // when a pin reads low, the button is connecting to ground.
      allButtons[i] = 1;
    }
    Joystick.button(i + 1, allButtons[i]);
  }

  
  Joystick.send_now();
  
}

Thanks
Thanos

Robvp
Posts: 81
Joined: Mon May 09, 2016 10:53 am
Has thanked: 1 time
Been thanked: 2 times

Re: Custom Handheld Arcade console with Raspberry Pi3

Post by Robvp » Fri Jun 10, 2016 10:23 am

Thanks for sharing your build, I was thinking of an arcade build later on and now I know what I'll use as a psu, the SMAKN looks great, wish I had seen it sooner for my gameboy

steelnation248
Posts: 18
Joined: Fri Jun 10, 2016 7:21 am
Has thanked: 2 times
Been thanked: 1 time

Re: Custom Handheld Arcade console with Raspberry Pi3

Post by steelnation248 » Fri Jun 10, 2016 11:42 am

tronicgr wrote:
steelnation248 wrote:The project looks great! I was wondering how you were able to code the PSP analog stick?
Using the Teensy. Its emulating joystick and keyboard. See code below:

Code: Select all

/* Complete USB Joystick /keyboard Example
   Teensy becomes a USB joystick with 11 buttons and 2 axis input
   Button 12 is ESC keyboard, and button 13 is ENTER keyboard.
   You must select Joystick and Keyboard from the "Tools > USB Type" menu

   Pushbuttons should be connected between the digital pins and ground.
   Potentiometers should be connected to analog inputs 0 to 5.

   Analog joystick was PSP micro 2-axis
*/
#include <Bounce.h>

Bounce button9 = Bounce(12, 10);
Bounce button10 = Bounce(13, 10);

// Configure the number of buttons.  Be careful not
// to use a pin for both a digital button and analog
// axis.  The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 12;  // 16 for Teensy, 32 for Teensy++

void setup() {
  // you can print to the serial monitor while the joystick is active!
  Serial.begin(9600);

  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  
  // configure the joystick to manual send mode.  This gives precise
  // control over when the computer receives updates, but it does
  // require you to manually call Joystick.send_now().
  Joystick.useManualSend(true);
  for (int i=0; i<numButtons; i++) {
    pinMode(i, INPUT_PULLUP);
  }
 // Serial.println("Begin Complete Joystick Test");
}

byte allButtons[numButtons];
byte prevButtons[numButtons];

void loop() {

    button9.update();
    button10.update();

    if (button9.fallingEdge()) {
    Keyboard.set_key1(KEY_ENTER);
    Keyboard.send_now();  // send the button press
    Keyboard.set_key1(0);
    Keyboard.send_now();  // send the button release
  }
  if (button10.fallingEdge()) {
    Keyboard.set_key1(KEY_ESC);
    Keyboard.send_now();  // send the button press
    Keyboard.set_key1(0);
    Keyboard.send_now();  // send the button release
  }
  
  // read 6 analog inputs and use them for the joystick axis
  Joystick.X(map(analogRead(0),170, 853, 1023, 0));
  Joystick.Y(map(analogRead(1),170, 853, 0, 1023));
 
  
  // read digital pins and use them for the buttons
  for (int i=0; i<numButtons; i++) {
    if (digitalRead(i)) {
      // when a pin reads high, the button is not pressed
      // the pullup resistor creates the "on" signal
      allButtons[i] = 0;
    } else {
      // when a pin reads low, the button is connecting to ground.
      allButtons[i] = 1;
    }
    Joystick.button(i + 1, allButtons[i]);
  }

  
  Joystick.send_now();
  
}

Thanks
Thanos
Awesome! Do you happen to also have a picture or diagram of how you wired the PSP to the Teensy?

Thanks man!

User avatar
tronicgr
Posts: 143
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 95 times
Been thanked: 67 times
Contact:

Re: Custom Handheld Arcade console with Raspberry Pi3

Post by tronicgr » Fri Jun 10, 2016 4:26 pm

steelnation248 wrote:
tronicgr wrote:
steelnation248 wrote:The project looks great! I was wondering how you were able to code the PSP analog stick?
Using the Teensy. Its emulating joystick and keyboard. See code below:

Code: Select all

/* Complete USB Joystick /keyboard Example
   Teensy becomes a USB joystick with 11 buttons and 2 axis input
   Button 12 is ESC keyboard, and button 13 is ENTER keyboard.
   You must select Joystick and Keyboard from the "Tools > USB Type" menu

   Pushbuttons should be connected between the digital pins and ground.
   Potentiometers should be connected to analog inputs 0 to 5.

   Analog joystick was PSP micro 2-axis
*/
#include <Bounce.h>

Bounce button9 = Bounce(12, 10);
Bounce button10 = Bounce(13, 10);

// Configure the number of buttons.  Be careful not
// to use a pin for both a digital button and analog
// axis.  The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 12;  // 16 for Teensy, 32 for Teensy++

void setup() {
  // you can print to the serial monitor while the joystick is active!
  Serial.begin(9600);

  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  
  // configure the joystick to manual send mode.  This gives precise
  // control over when the computer receives updates, but it does
  // require you to manually call Joystick.send_now().
  Joystick.useManualSend(true);
  for (int i=0; i<numButtons; i++) {
    pinMode(i, INPUT_PULLUP);
  }
 // Serial.println("Begin Complete Joystick Test");
}

byte allButtons[numButtons];
byte prevButtons[numButtons];

void loop() {

    button9.update();
    button10.update();

    if (button9.fallingEdge()) {
    Keyboard.set_key1(KEY_ENTER);
    Keyboard.send_now();  // send the button press
    Keyboard.set_key1(0);
    Keyboard.send_now();  // send the button release
  }
  if (button10.fallingEdge()) {
    Keyboard.set_key1(KEY_ESC);
    Keyboard.send_now();  // send the button press
    Keyboard.set_key1(0);
    Keyboard.send_now();  // send the button release
  }
  
  // read 6 analog inputs and use them for the joystick axis
  Joystick.X(map(analogRead(0),170, 853, 1023, 0));
  Joystick.Y(map(analogRead(1),170, 853, 0, 1023));
 
  
  // read digital pins and use them for the buttons
  for (int i=0; i<numButtons; i++) {
    if (digitalRead(i)) {
      // when a pin reads high, the button is not pressed
      // the pullup resistor creates the "on" signal
      allButtons[i] = 0;
    } else {
      // when a pin reads low, the button is connecting to ground.
      allButtons[i] = 1;
    }
    Joystick.button(i + 1, allButtons[i]);
  }

  
  Joystick.send_now();
  
}

Thanks
Thanos
Awesome! Do you happen to also have a picture or diagram of how you wired the PSP to the Teensy?

Thanks man!
I don't have diagram, but I'll try to find a photo of the connections.

I used the recommended connection method mentioned on the teensy official page for teensyduino.

*Edit: found a photo: red is 5v black is ground.
IMG_20160610_152753.jpg
IMG_20160610_152753.jpg (330.05 KiB) Viewed 8660 times


Thanks
Thanos

steelnation248
Posts: 18
Joined: Fri Jun 10, 2016 7:21 am
Has thanked: 2 times
Been thanked: 1 time

Re: Custom Handheld Arcade console with Raspberry Pi3

Post by steelnation248 » Sat Jun 11, 2016 6:53 pm

tronicgr wrote:
I don't have diagram, but I'll try to find a photo of the connections.

I used the recommended connection method mentioned on the teensy official page for teensyduino.

*Edit: found a photo: red is 5v black is ground.

IMG_20160610_152753.jpg



Thanks
Thanos
Awesome! Thank you again.


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest