• HomeBoards
  • RulesRules
  • HelpHelp
  • WikiWiki
  • Donate

Author Topic: Dingoo A320 vs Arduino  (Read 9834 times)

a320.emulate.su (OP)

  • Posts: 13
Dingoo A320 vs Arduino
« on: January 23, 2011, 10:31:17 am »
Hello, everyone!
I've made some research on connecting Arduino to our beloved Dingoo A320, and would like to share some "knowledge".
Firstly, I'm pretty much inspired by all those arcade cabinets, and I have a spare dingoo with broken powerswitch lying around. The second thing - sure, the arcade stick and arcade buttons are cool, you need definately a spare LCD screen (quite big in comparison to a320 screen), and all this leads another investment  ;) .
Ok. Let's start. So, we got an Arduino and spare SNES controller. What's next ?

The idea is - connect a SNES controller to Dingoo A320 without destroying both of them. Sure, you can get rid of IC inside snes pad and solder buttons directly to Dingoo button inputs, connect common grounds, and voila - you have an external joystick. But working SNES pads do not grow on trees and we like to CREATE something, not destroy.
This is already known, that we have a NESPAD library for Arduino, which will help us connecting SNES pad to the controller.
But there is the catch - just a common Arduino model (not this MEGA clones) do not have enough pins to connect. We need 3 pins from SNES and 12 (at least, without reset-power-hold). Arduino does not have 15 suitable pins.
So, we will go through using 74HC595 (actually 2 pieces). There is an incredible tutorial from mk90.blogspot.com, that shows the idea. Here is the picture, nicely illustrating, how to create 16 pins from 3.



This is solved. Final problem. In common, Arduino operates with 5 volt signals, Dingoo operates with 3 volts. I don't want to have my A320 exploded, or something like this. Here goes the protection circuit. Arduino/AVR pin can be substituted with 595 output pin, it's only for giving you an idea.

The diode is 1N4148 and resistor is 100 Ohms (I actually used 150 Ohms - I think, it's a not a big deal). All, that we need to do is pull Dingoo pins to "low" and this is enough. Actually the idea is from ZXKit site guys, so respect and thanks to them.


Final point - the "sketch" for Arduino, that will to the job. Note, that only SNES buttons are processed - extra ones -power, hold and reset can be added later to spare arduino pins.

Quote

#include <SNESpad.h>

#define DS   11
#define SHCP 12
#define STCP 8

//"Near" 7hc595 is one connected directly to Arduino. The "Far" one is
//"cascaded" to it.

//The signals are like this:
// Q7-Q1,Q15 are from high bit to lowest. (128-64-32-16-4-2-1)
// firstly "far" 7hc595 is stuffed, then the near one
// see "send2out"

//state definitions for out1 - "near" 7hc595

#define SELECT 0b01111111
#define START  0b10111111
#define A      0b11011111
#define B      0b11101111
#define X      0b11110111
#define Y      0b11111011
#define LSHIFT 0b11111101
#define RSHIFT 0b11111110

//state definitions for out0 - "far" 7hc595

#define UP     0b01111111
#define DOWN   0b10111111
#define LEFT   0b11011111
#define RIGHT  0b11101111
#define RESET  0b11110111
#define POWER  0b11111011
#define HOLD   0b11111101
#define UNUSED 0b11111110

byte decodeNear(int state)
{
  byte res=0b11111111;
  if ( state & SNES_SELECT )
    res = res & SELECT;

  if ( state & SNES_START )
    res = res & START;

  if ( state & SNES_A )
    res = res & A;

  if ( state & SNES_B )
    res = res & B;

  if ( state & SNES_X )
    res = res & X;

  if ( state & SNES_Y )
    res = res & Y;

  if ( state & SNES_L )
    res = res & LSHIFT;

  if ( state & SNES_R )
    res = res & RSHIFT;

  return res;

}

byte decodeFar(int state)
{
  byte res=0xff;
  if ( state & SNES_UP )
    res = res & UP;

  if ( state & SNES_DOWN )
    res = res & DOWN;

  if ( state & SNES_LEFT )
    res = res & LEFT;

  if ( state & SNES_RIGHT )
    res = res & RIGHT;

  // the rest shoud be processed in other place - because snes have only 12 buttons 
  return res;
}


void send2out(byte out0, byte out1)
{

  shiftOut(DS,SHCP,MSBFIRST,out0); //far one
  shiftOut(DS,SHCP,MSBFIRST,out1); //near one
  digitalWrite(STCP,HIGH);
  delay(1);
  digitalWrite(STCP,LOW);


}

// setting up arduino pins for connection - as in snespad example
//strobe/clock/data
SNESpad nintendo = SNESpad(2,3,4);

int state = 0;
int currentstate = 0;
byte out0 = 0xff;
byte out1 = 0xff;
void setup() {
  pinMode(13, OUTPUT);

  pinMode(DS,OUTPUT);
  pinMode(SHCP,OUTPUT);
  pinMode(STCP,OUTPUT);
  digitalWrite(SHCP,LOW); 
  digitalWrite(STCP,LOW); 
  digitalWrite(13,HIGH);

  send2out(0xff,0xff); //pull all high


}

void loop() {



  currentstate = nintendo.buttons();
  if(state != currentstate)
  {
    out0=decodeFar(currentstate);   
    out1=decodeNear(currentstate);

    //power,reset,hold are processed here (tbd)
    send2out(out0,out1);

  }
  state = currentstate;



}



And it works! Interested ? Here is the video with english subtitles :-)


http://www.youtube.com/watch?v=J4Dqlst6Xro


Final notes - this is a proof of concept. My Dingoo survived. I'm not sure about yours  ;D .
Next steps - create a dedicated PCB with Atmega, diodes, 595s and resistors.
I'd like to make it on Atmega8 with internal oscillator on 8 mhz (minimal arduino without bootlader to speed-up start), but I'm not sure about timings and how it will work.
Well, I can always add a place for external oscillator on 16mhz and couple of capacitors, but it will make board a little bit more expensive.
Also in plans is an "battery emulator" - 3.7 volts powersource, with protection from "charging" by usb.
And finally, the design of new housing - something "like an arcade".


BTW, anyone knows, can screen of A320 be detached and work "near" the PCB ? I mean, connected only with flat cable, not attached to PCB ? This would be nice for creating tiny arcade cab, with dingoo screen, and TV-out for any tv.


And thanks a lot for your attention.


P.S. Don't know, when I get back to the project again, so may be someone can "pickup the flag" and have some inspirations.





pcercuei

  • Posts: 1707
    • My devblog
Re: Dingoo A320 vs Arduino
« Reply #1 on: January 23, 2011, 11:51:50 am »
You don't like switch/case, do you?  :)
I'm joking. Your project is incredible  :o

a320.emulate.su (OP)

  • Posts: 13
Re: Dingoo A320 vs Arduino
« Reply #2 on: January 23, 2011, 12:18:37 pm »
You don't like switch/case, do you?  :)
No, I don't  ;) I use them everyday at work  ;D

abstauber

  • Guest
Re: Dingoo A320 vs Arduino
« Reply #3 on: January 24, 2011, 09:25:25 am »
Wow, very impressive. I suppose an IPAC to miniUSB handheld converter would even be commercially successful. If I ever build a new cab, I'll consider your Arduino solution - of course at first, I need to understand what you did ;)

Also it would be very interesting to see if you can detach the LCD, as this would end in a very cute form factor :) The smallest working cabs I've seen so far are a pocket PC based (more a dock than a cab) and GBA SP based one. The gameboy cab was really cool though.

a320.emulate.su (OP)

  • Posts: 13
Re: Dingoo A320 vs Arduino
« Reply #4 on: January 24, 2011, 03:31:29 pm »
Wow, very impressive. I suppose an IPAC to miniUSB handheld converter would even be commercially successful. If I ever build a new cab, I'll consider your Arduino solution - of course at first, I need to understand what you did ;)

Also it would be very interesting to see if you can detach the LCD, as this would end in a very cute form factor :) The smallest working cabs I've seen so far are a pocket PC based (more a dock than a cab) and GBA SP based one. The gameboy cab was really cool though.

=) What I did - just connected SNES pad to dingoo without destroying snes pad internals. Again, you can connect 13 wires from snes joystick to dingoo button contacts directly, but in most cases you'll have to destroy the internal chip and make snes pad non-functional. Like a "one-way-ticket".
The goal of experiment were:
  • Interface arduino to Dingoo
  • Attach snes controller without destroying internal chip
  • ...
  • PROFIT!!!  ;)
And regarding small cabs - will you be so kind to drop links to "small cabs" here ?

abstauber

  • Guest
Re: Dingoo A320 vs Arduino
« Reply #5 on: January 25, 2011, 07:53:41 am »
I still wonder, why the Dingoo accepts input signals via USB  ;)

Anyway here's the GBA cab:
http://www.youtube.com/watch?v=F-XXcI0euAw

This is Pocket Lucho's youtube channel, lots of awesome mini cabs
http://www.youtube.com/user/pocketlucho

I can't currently find the pocket PC version, but it's basically a pad-hack and an unmodified ipaq.

a320.emulate.su (OP)

  • Posts: 13
Re: Dingoo A320 vs Arduino
« Reply #6 on: January 25, 2011, 08:26:35 am »
I still wonder, why the Dingoo accepts input signals via USB  ;)
Well, It doesn't.
Pins from 74hc595 are connected to buttons directly through protection diodes and resistors. USB is used only for powering up, because on this dingoo I do have battery desoldered and broken powerswitch.
« Last Edit: January 25, 2011, 08:30:01 am by a320.emulate.su »

Ozone Sama

  • Guest
Re: Dingoo A320 vs Arduino
« Reply #7 on: February 04, 2011, 10:55:32 pm »
Aaargh ! You beat me to it !
I was planning a Shift-Register interface mod myself !

But I was considering using only one Fairchild's 74F675A (powered by the Dingoo's board or battery) instead of two 74HC595, because I'd like to fit most of the interface in the original Dingoo A320 case (is there enough room for a flat DIL chip with pins layered flat ?).
I was planning to add more I/O ports to the A320 by using only one speaker (converting stereo to mono with 2 diodes) and using the room of the removed speaker for a port (haven't decided yet if it will be a 4 points mini-Jack, a 6 points mini-DIN, or something else ...).
Aaahhh ... Well, I'm glad you made it work, now, if I could only have more spare time ...

Keep up the good job !

 

Post a new topic