Page 1 of 5

Arduino Pro (Leonardo Micro)

Posted: Thu Jun 16, 2016 7:46 am
by IAmOrion
I've started building my GBZ now :) - Big thanks to [mention=dominator]Dominator[/mention] for sending me the GBZ PCB and some stickers and buttons.

Anyway, I opted to use the Leonardo Micro instead of a teensy, pretty much same size.

http://www.ebay.co.uk/itm/201310315804

I wanted to share my arduino code that I used. I've used this same code on a Retro Arcade Machine Coffee Table I built

Code: Select all

#include <Keyboard.h>

#define BUTTONS 15
int pin_arr[]={2,4,3,5,14,16,9,8,A0,A1,6,7,A2,A3,15};
int keycode_arr[]={218,217,216,215,128,130,32,129,122,176,53,49,112,177,179}; 
// UP,DOWN,LEFT,RIGHT,LEFT-CTRL (Button 1), LEFT-ALT (Button 2),SPACEBAR (Button 3), LEFT-SHIFT (Button 4), Z (Button 5), ENTER (Button 6) (Enter instead of X so can use with other RPi things like raspi-config), Coin/Credit, 1P Start, P (Pause), ESC, TAB
int key_state[BUTTONS];

void setup() {
  Keyboard.begin();
  for (int i=0;i<BUTTONS;i++)
  {
    pinMode(pin_arr[i], INPUT_PULLUP);
    key_state[i] = digitalRead(pin_arr[i]);
  }
}

void loop() {
  for (int i=0;i<BUTTONS;i++)
  {
    key_state[i]=digitalRead(pin_arr[i]);
    if (key_state[i]==LOW) {
      Keyboard.press(keycode_arr[i]); if (keycode_arr[i] == 49) { delay(100); }
    } else {
      Keyboard.release(keycode_arr[i]);
    }
  }  
}
Download link:
https://www.dropbox.com/s/hvwi92295z8qs ... o.zip?dl=1

the download also includes an additional header (not included in the compilation as it's for reference only) That lists all the Key Codes.

I hope this is of use to others

Re: Arduino Pro (Leonardo Micro)

Posted: Thu Jun 16, 2016 11:31 am
by wermy
Thanks for this! Adding it to the wiki as an alternate part. Also moving this to the Hardware Guides section. :)

Re: Arduino Pro (Leonardo Micro)

Posted: Fri Jun 17, 2016 1:23 am
by Fleder
Oh damn, you beat me to it. Just finished my sketch for the Leonardo Clones... :)

Good job!

Re: Arduino Pro (Leonardo Micro)

Posted: Fri Jun 24, 2016 4:19 am
by zpnq
Thanks for this. Works well.

Re: Arduino Pro (Leonardo Micro)

Posted: Fri Aug 05, 2016 1:15 pm
by thomastallaksen
Hi!

Please excuse my noob question, this is my first project and my first arduino, so bear with me.

I don't seem to get the order of my pins right. I know you list it in the beginning of your code, but can you (or someone else) be even more specific? What button is going where? Up is 2, down is 4?.. and so on.

And why are there only keyboard commands? Because of the board? Or should I rewrite the code to match the controller buttons A, B, X, Y, etc. instead of space, shift etc.?

Re: Arduino Pro (Leonardo Micro)

Posted: Fri Aug 05, 2016 6:58 pm
by RxBrad
Big thing to note at the moment is that the current 1.6.10 Arduino software release fails every time you try to program the Leonardo Micro.

After I uninstalled the current version, I installed v1.6.5 and it worked perfectly.

https://www.arduino.cc/en/Main/OldSoftw ... s#previous

Re: Arduino Pro (Leonardo Micro)

Posted: Fri Aug 05, 2016 7:05 pm
by RxBrad
thomastallaksen wrote:Hi!

Please excuse my noob question, this is my first project and my first arduino, so bear with me.

I don't seem to get the order of my pins right. I know you list it in the beginning of your code, but can you (or someone else) be even more specific? What button is going where? Up is 2, down is 4?.. and so on.

And why are there only keyboard commands? Because of the board? Or should I rewrite the code to match the controller buttons A, B, X, Y, etc. instead of space, shift etc.?
The emulators use keyboard input, so this should work okay.

Below is the part of the code that tells you what the buttons do.

Pin 2 = keycode 218 = UP,
Pin 4 = keycode 217 = DOWN,
Pin 3 = keycode 216 = LEFT,
etc, etc, etc...

Code: Select all

int pin_arr[]={2,4,3,5,14,16,9,8,A0,A1,6,7,A2,A3,15};
int keycode_arr[]={218,217,216,215,128,130,32,129,122,176,53,49,112,177,179}; 
// UP,DOWN,LEFT,RIGHT,LEFT-CTRL (Button 1), LEFT-ALT (Button 2),SPACEBAR (Button 3), LEFT-SHIFT (Button 4), Z (Button 5), ENTER (Button 6) (Enter instead of X so can use with other RPi things like raspi-config), Coin/Credit, 1P Start, P (Pause), ESC, TAB

Re: Arduino Pro (Leonardo Micro)

Posted: Sat Aug 06, 2016 3:07 am
by Raizan
Hey, can someone tell me where shoud i connect the usb pads from the pi zero (from the usb hub) to the arduino pro board?
On the teensy lc you connect it to VCC D- D+ GND but the pro micro uses other...
Thank you

Re: Arduino Pro (Leonardo Micro)

Posted: Sun Aug 21, 2016 5:23 am
by voldemortvdk
Raizan wrote:Hey, can someone tell me where shoud i connect the usb pads from the pi zero (from the usb hub) to the arduino pro board?
On the teensy lc you connect it to VCC D- D+ GND but the pro micro uses other...
Thank you
Please help, I have the same question.

I want to use Arduino Pro Micro, instead of Teensy.
On Teensy board, there are D+ / D- pins for connecting or soldering RPi's USB port.
But, Arduino Pro Micro, they are Tx/Rx,... pins, please tell me how to use those of pins, or any idea else. :|

Thank you :D

Re: Arduino Pro (Leonardo Micro)

Posted: Sun Aug 21, 2016 7:23 am
by Raizan
voldemortvdk wrote: Please help, I have the same question.

I want to use Arduino Pro Micro, instead of Teensy.
On Teensy board's got D+ / D- for connecting or soldering RPi's USB port.
But, Arduino Pro Micro's got Tx/Rx pin, please tell me how to use those of pins, or got any idea else. :|

Thank you :D
What i ended up doing was i stipped a micro usb to usb cable and connected the micro usb to the arduino pro micro's micro usb port and the wires of that micro usb cable to the usb hub...