viernes, 30 de marzo de 2012

Arduino - Sega Genesis controller imput library

Rule: Spanish / English

Esta librería es para utilizar un control de Sega Genesis / Megadrive en tu Arduino.
Los controles de sega tienen un control tipo DB9 (Estándar serie) y tienen mucha información en la webb (http://pinouts.ru/Game/genesiscontroller_pinout.shtml y http://www.cs.cmu.edu/~chuck/infopg/segasix.txt).
Lo que hice fue simplemente programar las librerías para que sea mas cómodo implementarlo, y ahora las comparto.
This library is a way to control your Sega genesis / Megadrive controller quickly.
This controller is the best (I think) for prototyping, its connector is a standard DB9 (serial connector), and we have all the info regarding pinouts and functioning in the web (http://pinouts.ru/Game/genesiscontroller_pinout.shtml and http://www.cs.cmu.edu/~chuck/infopg/segasix.txt).
So I simply programmed this into a library for later use, and now I share it.

Simplemente hay que agregar estas librerías a tu entorno y luego agregar la correspondiente en tu proyecto  (#include o #include ), copiar y pegar este código, conectar tu joystick y abrir el monitor serie.
Simply add these libraries to your Arduino enviroment, and then add them to your proyect (#include or #include ), copy and paste this code, upload, connect your joystick and open your serial monitor.


La conección física entre el Arduino y el control es simple, mirando el conector de tu control lo que se ve es:
The actual connection between Arduino and the controller is simple, looking at you controller connector the pin numbers are: 

El pin 5 debe ser conectado a 5v y el 8 a masa, el resto al arduino de la siguiente manera:
Pin 5 must be connected to 5v and pin 8 to ground. The rest to arduino like this:



1     Up                                                ->          boton_UP              (A0)
2     Down                                          ->          boton_DOWN      (A1)
3    Left                                              ->          boton_IZQ             (A2)
4     Right                                          ->          boton_DER            (8)
6     Button A / Button B                 ->         boton_AB                (7)
7     Select                                         ->         select                       (5)

9     Start / Button C                       ->          boton_StartC         (6)

3 botones codigo de muestra:

Three button sample code:
#include <Sega3button.h>

#define select          5
#define boton_AB        7
#define boton_StartC    6
#define boton_UP        A0
#define boton_DOWN     A1
#define boton_IZQ      A2
#define boton_DER      8


Sega3b control = Sega3b(select,boton_AB,boton_StartC,boton_UP,boton_DOWN,boton_IZQ,boton_DER);

char aux;

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


void loop()
{
  aux = control.getSega3();
  
  switch(aux)
  {
    case 'A': Serial.write("A"); break; 
    case 'B': Serial.write("B"); break; 
    case 'C': Serial.write("C"); break; 
    case 'D': Serial.write("Down"); break; 
    case 'U': Serial.write("Up"); break;  
    case 'I': Serial.write("Left"); break; 
    case 'R': Serial.write("Right"); break; 
    case 'S': Serial.write("Start"); break; 
  }
  delay(10);
}
 

6 botones codigo de muestra:
Six Button Sample code:
 
#include <Sega6button.h>

#define select          5
#define boton_AB        7
#define boton_StartC    6
#define boton_UP        A0
#define boton_DOWN     A1
#define boton_IZQ      A2
#define boton_DER      8


Sega6b control = Sega6b(select,boton_AB,boton_StartC,boton_UP,boton_DOWN,boton_IZQ,boton_DER);

char aux;

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


void loop()
{
  aux = control.getSega6();
  
  switch(aux)
  {
    case 'A': Serial.write("A"); break; 
    case 'B': Serial.write("B"); break; 
    case 'C': Serial.write("C"); break; 
    case 'D': Serial.write("Down"); break; 
    case 'U': Serial.write("Up"); break;  
    case 'I': Serial.write("Left"); break; 
    case 'R': Serial.write("Right"); break; 
    case 'X': Serial.write("X"); break; 
    case 'Y': Serial.write("Y"); break; 
    case 'Z': Serial.write("Z"); break; 
    case 'S': Serial.write("Start"); break; 
  }
  delay(10);
}
 
Downloads: 
Sega 3 button library
Sega 6 button library 
 

2 comentarios:

  1. Tuve un problema con la libreria, el import WProgram.h. Esa libreria ha sido renombrada a Arduino.h .
    Saludos y gracias por publicar esta libreria

    ResponderEliminar
    Respuestas
    1. Ya modifique las librerias, gracias por hacerme acordar.

      Espero que te sea útil!

      Eliminar