Arduino Pro (Leonardo Micro)

Various user-contributed guides for hardware-related things
User avatar
IAmOrion
Posts: 20
Joined: Wed Jun 08, 2016 4:00 am
Has thanked: 12 times
Been thanked: 9 times

Arduino Pro (Leonardo Micro)

Post by IAmOrion » Thu Jun 16, 2016 7:46 am

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

User avatar
wermy
Site Admin
Posts: 1344
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 618 times
Been thanked: 1319 times
Contact:

Re: Arduino Pro (Leonardo Micro)

Post by wermy » Thu Jun 16, 2016 11:31 am

Thanks for this! Adding it to the wiki as an alternate part. Also moving this to the Hardware Guides section. :)
ImageImageImageImage

User avatar
Fleder
Posts: 848
Joined: Thu May 05, 2016 9:04 am
Location: Germany
Has thanked: 182 times
Been thanked: 257 times

Re: Arduino Pro (Leonardo Micro)

Post by Fleder » Fri Jun 17, 2016 1:23 am

Oh damn, you beat me to it. Just finished my sketch for the Leonardo Clones... :)

Good job!

zpnq
Posts: 4
Joined: Fri Jun 17, 2016 7:07 am
Has thanked: 2 times
Been thanked: 1 time

Re: Arduino Pro (Leonardo Micro)

Post by zpnq » Fri Jun 24, 2016 4:19 am

Thanks for this. Works well.

thomastallaksen
Posts: 2
Joined: Fri Aug 05, 2016 1:02 pm

Re: Arduino Pro (Leonardo Micro)

Post by thomastallaksen » Fri Aug 05, 2016 1:15 pm

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.?

User avatar
RxBrad
Posts: 267
Joined: Fri Jul 22, 2016 9:10 am
Has thanked: 121 times
Been thanked: 149 times
Contact:

Re: Arduino Pro (Leonardo Micro)

Post by RxBrad » Fri Aug 05, 2016 6:58 pm

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

User avatar
RxBrad
Posts: 267
Joined: Fri Jul 22, 2016 9:10 am
Has thanked: 121 times
Been thanked: 149 times
Contact:

Re: Arduino Pro (Leonardo Micro)

Post by RxBrad » Fri Aug 05, 2016 7:05 pm

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

Raizan
Posts: 9
Joined: Thu Jul 21, 2016 7:10 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Arduino Pro (Leonardo Micro)

Post by Raizan » Sat Aug 06, 2016 3:07 am

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

User avatar
voldemortvdk
Posts: 2
Joined: Tue Jun 07, 2016 5:00 am
Has thanked: 50 times

Re: Arduino Pro (Leonardo Micro)

Post by voldemortvdk » Sun Aug 21, 2016 5:23 am

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
Last edited by voldemortvdk on Sun Aug 21, 2016 10:39 am, edited 1 time in total.

Raizan
Posts: 9
Joined: Thu Jul 21, 2016 7:10 pm
Has thanked: 1 time
Been thanked: 3 times

Re: Arduino Pro (Leonardo Micro)

Post by Raizan » Sun Aug 21, 2016 7:23 am

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...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest