English Amiga Board


Go Back   English Amiga Board > Support > New to Emulation or Amiga scene

 
 
Thread Tools
Old 19 February 2018, 21:06   #1
Martijn
Registered User
 
Join Date: Jan 2018
Location: Utrecht, NL
Posts: 15
Using 9 pin joysticks on Amiga emulator - Arduino to the rescue

Hi,

Didn't really know which subforum to put this in, something emulation related or rather a hardware mod maybe, but since I'm also rather new to the forum, it's going here for now. Feel free to move...

I've recently dug out my A500 again for a work party, and then after I didn't put it back in its box. ;-) So I started playing some games again (yay, Sensible Soccer!), then bought an ACA500plus. Then installed FS-UAE on my macbook to do some changes to the workbench on my CF card lazily on the couch. And then I thought: wouldn't it be nice to also run Sensible Soccer on my macbook, but hey, that's no fun without my Arcade joysticks. I did a bit of googling, found out that Retronic Design sells adapters, but, well, expensive, other side of the world, nevermind. I must be able to do that myself. And so I did.

The ingredients:
- an old DB25 male connector I found somewhere in a box with old cables (I found several, one of them big enough to fit the arduino board inside)
- a Pro Micro Arduino board (can present itself as USB HID device, thus appears as keyboard without further drivers)
- a couple of wires
- a soldering iron, patience and steady hands
- and a few (really just a few) lines of code

So, some soldering:
Click image for larger version

Name:	IMG_0915.jpeg
Views:	387
Size:	250.0 KB
ID:	56883

Kill a few pins:
Click image for larger version

Name:	IMG_0917.jpeg
Views:	247
Size:	136.6 KB
ID:	56886

Gate to the modern world:
Click image for larger version

Name:	IMG_0918.jpeg
Views:	236
Size:	118.8 KB
ID:	56885

Arduino showing signs of life:
Click image for larger version

Name:	IMG_0916.jpeg
Views:	268
Size:	210.4 KB
ID:	56887

Playing Sensible Soccer the way it's supposed to be:
Click image for larger version

Name:	IMG_0914.jpeg
Views:	265
Size:	236.3 KB
ID:	56884

This is all the code needed:
Code:
#include "Keyboard.h"

void setup() {
  for (int i = 5; i<=9; i++) {
    pinMode(i, INPUT_PULLUP);
  }
  pinMode(10, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
}

void loop() {
  // joystick 1, default FS-UAE keyboard assignment
  handle(6, 0xDA); //arrow up
  handle(7, 0xD9); //arrow down
  handle(8, 0xD8); //arrow left
  handle(9, 0xD7); //arrow right
  handle(5, 0x86); //right alt

  // joystick 2, configured with numpad keys in FS-UAE advanced settings
  handle(14, '\350'); //numpad 8
  handle(16, '\342'); //numpad 2
  handle(15, '\344'); //numpad 4
  handle(18, '\346'); //numpad 6
  handle(10, '\352'); //numpad 0
}

void handle(int pin, byte key) {
  if (digitalRead(pin) == 0) {
    Keyboard.press(key);
  } else {
    Keyboard.release(key);
  }
}
Martijn is offline  
Old 19 February 2018, 23:10   #2
kgc210
Registered User
 
Join Date: Jun 2016
Location: Stoke-On-Trent, England
Posts: 450
Good work.
Only thought is do you have enough spare pins to add the second fire button?
kgc210 is offline  
Old 19 February 2018, 23:17   #3
Martijn
Registered User
 
Join Date: Jan 2018
Location: Utrecht, NL
Posts: 15
Certainly, there are around 20 pins on the Pro Micro board. I didn't care since I made it just for myself and I only care about one button Arcades, but there are enough pins (also some that can do analog) to fully cover two DB9 connections
Martijn is offline  
Old 20 February 2018, 19:36   #4
nogginthenog
Amigan
 
Join Date: Feb 2012
Location: London
Posts: 1,309
Quote:
Originally Posted by Martijn View Post
Certainly, there are around 20 pins on the Pro Micro board. I didn't care since I made it just for myself and I only care about one button Arcades, but there are enough pins (also some that can do analog) to fully cover two DB9 connections
Wow, that's pretty nice. Never played with Pro Micros, only Pro Minis and Nanos (and 8-pin ATTiny's in the Arduino IDE).

The DB25 case is a perfect fit. You know there are a few arcade games that support the 2nd button? In R-Type you can use it to call back your pod.

Then again looks like you only have 1 button sticks
nogginthenog is offline  
Old 20 February 2018, 22:20   #5
Martijn
Registered User
 
Join Date: Jan 2018
Location: Utrecht, NL
Posts: 15
Quote:
Originally Posted by nogginthenog View Post
You know there are a few arcade games that support the 2nd button? In R-Type you can use it to call back your pod.

Then again looks like you only have 1 button sticks
Yeah I always had 1 button joysticks, don't care for anything else. :-) Never been a gamer since my amiga days, also never got used to 'modern' controllers with many buttons, thumbsticks etc... But yes, supporting a second button is just adding one wire and two lines of code.
Martijn is offline  
Old 06 March 2018, 14:04   #6
LuMan
Amigan - an' lovin' it!!
 
LuMan's Avatar
 
Join Date: Nov 2010
Location: Nottingham, UK
Age: 55
Posts: 557
Hi Martijn. I really like that. It's odd that we spend so much time trying to get new stuff to work on our old stuff, then you make a way of getting old stuff working on new stuff!! Cracking work!

Any chance of a list of DB25 pins to Arduino Pro Micro connections?
LuMan is offline  
Old 13 March 2018, 15:38   #7
Martijn
Registered User
 
Join Date: Jan 2018
Location: Utrecht, NL
Posts: 15
Well, my pin mapping is mostly based on "where can I best fit this tiny wire?".

So if you want to replicate this, you'd best just solder some wires to the 2xDB9 connectors (I'd rather not call it DB25 anymore after removing some pins, better to just number them as it's 2x DB9 next to each other), then get everything together and see which wire goes where on the Pro Micro naturally. Almost all pins on the non-USB side can be used as input.

What you would need to do is:
- Connect pin 8 of both DB9 connectors to GND on the Pro Micro
- Connect pins 1/2/3/4 (up/down/left/right) to any pin on the Pro Micro
- Connect pin 6 (button) to any pin on the Pro Micro
- Update the Arduino program to use the pins you connected the wires to

The pins I used are quite visible in the first picture.

By the way, I've since tried to hook this up to my new Raspberry Pi with Amiberry on it too. Amiberry doesn't seem to keen on mapping keyboard input to joystick movements, so I've rewritten the program to act as an HID game controller using an Arduino HID joystick library I found at https://github.com/MHeironimus/Ardui...e/version-1.0:

Code:
#include <Joystick2.h>

void setup() {
  for (int i = 5; i<=9; i++) {
    pinMode(i, INPUT_PULLUP);
  }
  pinMode(10, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  Joystick[0].begin(true);
  Joystick[1].begin(true);
}

void loop() {
  // joystick 1 as HID joystick

  if (digitalRead(6) == 0) {
    // up
    Joystick[0].setYAxis(-127);
  } else if (digitalRead(7) == 0) {
    // down
    Joystick[0].setYAxis(127);
  } else {
    Joystick[0].setYAxis(0);
  }
  
  if (digitalRead(8) == 0) {
    // left
    Joystick[0].setXAxis(-127);
  } else if (digitalRead(9) == 0) {
    // right
    Joystick[0].setXAxis(127);
  } else {
    Joystick[0].setXAxis(0);
  }
  
  if (digitalRead(5) == 0) {
    Joystick[0].pressButton(0);
  } else {
    Joystick[0].releaseButton(0);
  }


  // joystick 2 as HID joystick
  if (digitalRead(14) == 0) {
    // up
    Joystick[1].setYAxis(-127);
  } else if (digitalRead(16) == 0) {
    // down
    Joystick[1].setYAxis(127);
  } else {
    Joystick[1].setYAxis(0);
  }
  
  if (digitalRead(15) == 0) {
    // left
    Joystick[1].setXAxis(-127);
  } else if (digitalRead(18) == 0) {
    // right
    Joystick[1].setXAxis(127);
  } else {
    Joystick[1].setXAxis(0);
  }
  
  if (digitalRead(10) == 0) {
    Joystick[1].pressButton(0);
  } else {
    Joystick[1].releaseButton(0);
  }
}
Martijn is offline  
Old 27 March 2018, 08:09   #8
Heywood
Registered User
 
Join Date: Mar 2018
Location: Brisbane/Australia
Posts: 72
Hey Martjin,

Have you seen this project? It may have some ideas that you may want to borrow for yours. It's not mine but it's something that I've been considering using it for my emulation setup. Besides joysticks, it does an Amiga mouse too. Actually there's a mode that seems to autodetect a mouse or joystick is plugged in which seems pretty nifty if it actually works (haven't looked into the code enough to see if it automatically changes reporting as a HID Mouse/Joystick to the host though)

BTW I hope you don't think I'm knocking your work at all - unlike your project, the one I've mentioned only implements one input - I love the pro micros, good form factor, a good number of 5V capable I/O pins and built in USB (and the clones are dirt cheap so if you destroy one, you don't feel too bad - not that I would admit to mistreating these things )
Heywood is offline  
Old 27 March 2018, 09:56   #9
Martijn
Registered User
 
Join Date: Jan 2018
Location: Utrecht, NL
Posts: 15
Hey, yes I saw that (after I built mine), looks cool. It doesn't do USB game controller emulation though, which I need to connect two joysticks to Amiberry simultaneously (it only allows one "keyboard as joystick", might be solved in a future release). But it's definitely more mature than my "solves only my own specific needs"-project. :-)

I don't think it automatically changes the reporting as mouse/keyboard; it just identifies itself as both and sends keyboard or mouse signals depending on the mode.

I might look into the mouse emulation one day, ie. the day I want to play Cannon Fodder on the Pi. ;-)
Martijn is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Normal 34-pin floppy drive on external 26-pin roctec SilverZguru Hardware mods 45 20 December 2020 12:05
Arduino Powered Floppy Disk Reader and Writer RobSmithDev support.Hardware 5 23 September 2017 17:11
Smurf Rescue Released! (New Amiga game) hipoonios News 63 15 November 2016 21:58
The Holy Grail of 9-pin Joysticks Swevicus Retrogaming General Discussion 2 22 August 2016 10:03
Joysticks with two 9-pin connectors prowler support.Hardware 15 22 April 2013 22:19

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:47.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08743 seconds with 14 queries