Arduino Pro (Leonardo Micro)
- winnetouch
- Posts: 158
- Joined: Mon Jul 11, 2016 10:56 am
- Has thanked: 2 times
- Been thanked: 30 times
Re: Arduino Pro (Leonardo Micro)
Thanks I'll try figuring it out. Just one more question. How do you redefine the pins? I want to use pin0 on the pro micro. Is there a way to do that?
Re: Arduino Pro (Leonardo Micro)
I edited the code to include all the pins on the Arduino pro micro.
I don't know if the extra unused keys might degrade the performance. I use the same code with a smaller arrays of 12 keys only.
I don't know if the extra unused keys might degrade the performance. I use the same code with a smaller arrays of 12 keys only.
Code: Select all
#include <Keyboard.h>
#define BUTTONS 20
int keycode_arr[] =
{
118, // PIN0 'v'
119, // PIN1 'w'
120, // PIN2 'x'
121, // PIN3 'y'
32, // PIN4 space
10, // PIN5 enter
215, // PIN6 RIGHT
217, // PIN7 DOWN
216, // PIN8 LEFT
218, // PIN9 UP
122, // PIN10 Z
176, // PIN11 ENTER
17, // PIN12 CTRL
204, // PIN13 F11
112, // A0 PAUSE
177, // A1 ESC
97, // A2 'a'
98, // A3 'b'
108, // A4 (right shoulder - r)
114 // A5 "l" - left shoulder
};
int key_state[BUTTONS];
void setup()
{
PRR1 = PRR1 |
(
(1 << PRTIM2) |
(1 << PRTIM3) |
(1 << PRUSART1)
);
PRR0 = PRR0 |
(
(1 << PRTWI) |
(1 << PRSPI) |
(1 << PRTIM1) |
(1 << PRADC)
);
DDRB = DDRB & ~
(
(1 << DDB1) |
(1 << DDB2) |
(1 << DDB3) |
(1 << DDB4) |
(1 << DDB5) |
(1 << DDB6) |
(1 << DDB7)
);
PORTB = PORTB |
(
(1 << PB1) |
(1 << PB2) |
(1 << PB3) |
(1 << PB4) |
(1 << PB5) |
(1 << PB6) |
(1 << PB7)
);
DDRC = DDRC & ~
(
(1 << DDC6) |
(1 << DDC7)
);
PORTC = PORTC |
(
(1 << PC6) |
(1 << PC7)
);
DDRD = DDRD & ~
(
(1 << DDD0) |
(1 << DDD1) |
(1 << DDD2) |
(1 << DDD3) |
(1 << DDD4) |
(1 << DDD6) |
(1 << DDD7)
);
PORTD = PORTD |
(
(1 << PD0) |
(1 << PD1) |
(1 << PD2) |
(1 << PD3) |
(1 << PD4) |
(1 << PD6) |
(1 << PD7)
);
DDRE = DDRE & ~ (1 << DDE6);
PORTE = PORTE | (1 << PE6);
DDRF = DDRF & ~
(
(1 << DDF0) |
(1 << DDF1) |
(1 << DDF4) |
(1 << DDF5) |
(1 << DDF6) |
(1 << DDF7)
);
PORTF = PORTF |
(
(1 << PF0) |
(1 << PF1) |
(1 << PF4) |
(1 << PF5) |
(1 << PF6) |
(1 << PF7)
);
Keyboard.begin();
//Serial.begin(115200);
}
void loop()
{
int port_b;
int port_c;
int port_d;
int port_e;
int port_f;
port_b = PINB;
port_c = PINC;
port_d = PIND;
port_e = PINE;
port_f = PINF;
key_state[0] = ((port_d & (1 << PD2)) == 0); // PIN0
key_state[1] = ((port_d & (1 << PD3)) == 0); // PIN1
key_state[2] = ((port_d & (1 << PD1)) == 0); // PIN2
key_state[3] = ((port_d & (1 << PD0)) == 0); // PIN3
key_state[4] = ((port_d & (1 << PD4)) == 0); // PIN4
key_state[5] = ((port_c & (1 << PC6)) == 0); // PIN5
key_state[6] = ((port_d & (1 << PD7)) == 0); // PIN6
key_state[7] = ((port_e & (1 << PE6)) == 0); // PIN7
key_state[8] = ((port_b & (1 << PB4)) == 0); // PIN8
key_state[9] = ((port_b & (1 << PB5)) == 0); // PIN9
key_state[10] = ((port_b & (1 << PB6)) == 0); // PIN10
key_state[11] = ((port_b & (1 << PB7)) == 0); // PIN11
key_state[12] = ((port_d & (1 << PD6)) == 0); // PIN12
key_state[13] = ((port_c & (1 << PC7)) == 0); // PIN13
key_state[14] = ((port_f & (1 << PF7)) == 0); // A0
key_state[15] = ((port_f & (1 << PF6)) == 0); // A1
key_state[16] = ((port_f & (1 << PF5)) == 0); // A2
key_state[17] = ((port_f & (1 << PF4)) == 0); // A3
key_state[18] = ((port_f & (1 << PF1)) == 0); // A4
key_state[19] = ((port_f & (1 << PF0)) == 0); // A5
//Serial.println(key_state[6]);
for (int i = 0; i < BUTTONS; i++)
{
if (key_state[i] == 1)
{
//Serial.println(keycode_arr[i]);
Keyboard.press(keycode_arr[i]);
}
else
{
Keyboard.release(keycode_arr[i]);
}
}
}
Last edited by myPiZero on Mon Oct 24, 2016 12:51 pm, edited 2 times in total.
- winnetouch
- Posts: 158
- Joined: Mon Jul 11, 2016 10:56 am
- Has thanked: 2 times
- Been thanked: 30 times
- winnetouch
- Posts: 158
- Joined: Mon Jul 11, 2016 10:56 am
- Has thanked: 2 times
- Been thanked: 30 times
Re: Arduino Pro (Leonardo Micro)
Well... I'm back 
I don't think I'm doing this right. I modified the key hex codes and uploaded it to my spakrfun pro micro (that doesn't have a pin 11-13 but it continues from 14-16 and then 19-21 si I need a at least pin 16 also
)
Also. With they keys that I did modify... They don't seem to work. At least not on my mac. So what am I doing wrong?

I don't think I'm doing this right. I modified the key hex codes and uploaded it to my spakrfun pro micro (that doesn't have a pin 11-13 but it continues from 14-16 and then 19-21 si I need a at least pin 16 also

Also. With they keys that I did modify... They don't seem to work. At least not on my mac. So what am I doing wrong?
Code: Select all
#include <Keyboard.h>
#define BUTTONS 20
int keycode_arr[] =
{
26, // PIN0 'w'
22, // PIN1 's'
4, // PIN2 'a'
7, // PIN3 'd'
46, // PIN4 '.'
176, // PIN5 Enter
28, // PIN6 y
27, // PIN7 x
6, // PIN8 c
25, // PIN9 v
20, // PIN10 q
8, // PIN11 e
17, // PIN12 CTRL
204, // PIN13 F11
112, // A0 PAUSE
177, // A1 ESC
97, // A2 'a'
98, // A3 'b'
108, // A4 (right shoulder - r)
114 // A5 "l" - left shoulder
};
int key_state[BUTTONS];
void setup()
{
PRR1 = PRR1 |
(
(1 << PRTIM2) |
(1 << PRTIM3) |
(1 << PRUSART1)
);
PRR0 = PRR0 |
(
(1 << PRTWI) |
(1 << PRSPI) |
(1 << PRTIM1) |
(1 << PRADC)
);
DDRB = DDRB & ~
(
(1 << DDB1) |
(1 << DDB2) |
(1 << DDB3) |
(1 << DDB4) |
(1 << DDB5) |
(1 << DDB6) |
(1 << DDB7)
);
PORTB = PORTB |
(
(1 << PB1) |
(1 << PB2) |
(1 << PB3) |
(1 << PB4) |
(1 << PB5) |
(1 << PB6) |
(1 << PB7)
);
DDRC = DDRC & ~
(
(1 << DDC6) |
(1 << DDC7)
);
PORTC = PORTC |
(
(1 << PC6) |
(1 << PC7)
);
DDRD = DDRD & ~
(
(1 << DDD0) |
(1 << DDD1) |
(1 << DDD4) |
(1 << DDD6) |
(1 << DDD7)
);
PORTD = PORTD |
(
(1 << PD0) |
(1 << PD1) |
(1 << PD4) |
(1 << PD6) |
(1 << PD7)
);
//If you want to use digital pins 1 (TX) and 0 (RX) uncomment the following lines of PORTD
//note that digital pin 1 is TX
DDRD = DDRD & ~
(
(1 << DDD3) |
(1 << DDD2)
);
PORTD = PORTD |
(
(1 << PD3) |
(1 << PD2)
);
//end comment here
DDRE = DDRE & ~ (1 << DDE6);
PORTE = PORTE | (1 << PE6);
DDRF = DDRF & ~
(
(1 << DDF0) |
(1 << DDF1) |
(1 << DDF4) |
(1 << DDF5) |
(1 << DDF6) |
(1 << DDF7)
);
PORTF = PORTF |
(
(1 << PF0) |
(1 << PF1) |
(1 << PF4) |
(1 << PF5) |
(1 << PF6) |
(1 << PF7)
);
Keyboard.begin();
//Serial.begin(115200);
}
void loop()
{
int port_b;
int port_c;
int port_d;
int port_e;
int port_f;
port_b = PINB;
port_c = PINC;
port_d = PIND;
port_e = PINE;
port_f = PINF;
key_state[0] = ((port_d & (1 << PD2)) == 0); // PIN0
key_state[1] = ((port_d & (1 << PD3)) == 0); // PIN1
key_state[2] = ((port_d & (1 << PD1)) == 0); // PIN2
key_state[3] = ((port_d & (1 << PD0)) == 0); // PIN3
key_state[4] = ((port_d & (1 << PD4)) == 0); // PIN4
key_state[5] = ((port_c & (1 << PC6)) == 0); // PIN5
key_state[6] = ((port_d & (1 << PD7)) == 0); // PIN6
key_state[7] = ((port_e & (1 << PE6)) == 0); // PIN7
key_state[8] = ((port_b & (1 << PB4)) == 0); // PIN8
key_state[9] = ((port_b & (1 << PB5)) == 0); // PIN9
key_state[10] = ((port_b & (1 << PB6)) == 0); // PIN10
key_state[11] = ((port_b & (1 << PB7)) == 0); // PIN11
key_state[12] = ((port_d & (1 << PD6)) == 0); // PIN12
key_state[13] = ((port_c & (1 << PC7)) == 0); // PIN13
key_state[14] = ((port_f & (1 << PF7)) == 0); // A0
key_state[15] = ((port_f & (1 << PF6)) == 0); // A1
key_state[16] = ((port_f & (1 << PF5)) == 0); // A2
key_state[17] = ((port_f & (1 << PF4)) == 0); // A3
key_state[18] = ((port_f & (1 << PF1)) == 0); // A4
key_state[19] = ((port_f & (1 << PF0)) == 0); // A5
//Serial.println(key_state[6]);
for (int i = 0; i < BUTTONS; i++)
{
if (key_state[i] == 1)
{
//Serial.println(keycode_arr[i]);
Keyboard.press(keycode_arr[i]);
}
else
{
Keyboard.release(keycode_arr[i]);
}
}
}
Re: Arduino Pro (Leonardo Micro)
I modified the code after you saw my comment. Please use the new code.
- winnetouch
- Posts: 158
- Joined: Mon Jul 11, 2016 10:56 am
- Has thanked: 2 times
- Been thanked: 30 times
Re: Arduino Pro (Leonardo Micro)
damn it. Either that last code or something I did bricked my pro micro. I can't bring it back to life anymore
. The port doesn't show up and doing the double click thing doesn't do anything. Looks like I'm screwed.

- winnetouch
- Posts: 158
- Joined: Mon Jul 11, 2016 10:56 am
- Has thanked: 2 times
- Been thanked: 30 times
Re: Arduino Pro (Leonardo Micro)
I found that online yesterday and tried multiple fixes. I don't have the programmer chip so I can't use that method. I tried shorting the ground and reset pins and succeded maybe 2x out of 100 to restart the bootloader but the compiler was never fast enough to load a new code to the chip. The double push doesn't seem to work for me like it should. I did use a wire not a tact switch though.
-
- Posts: 21
- Joined: Wed Oct 05, 2016 7:48 am
- Location: Glasgow, Scotland
- Has thanked: 3 times
- Been thanked: 5 times
- Contact:
Re: Arduino Pro (Leonardo Micro)
Lpoolm wrote:i also am struggling with where to connect my usb, does anyone have an answer to this yet?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
thanks

Just checked this out both by eye and with my multimeter, I have not tried it yet, waiting for my usb hub to arrive.
The resistors are tiny on these, some very fine wire will be required to attach to the end of them.
- winnetouch
- Posts: 158
- Joined: Mon Jul 11, 2016 10:56 am
- Has thanked: 2 times
- Been thanked: 30 times
Re: Arduino Pro (Leonardo Micro)
I managed to fix my sparfun pro micro but the code still doesn't work for me. I'm testing it on my laptop. I copied the code in to my arduino software and uploaded it to my sparfun pro mini. Then I opened up a text editor and tried pressing the buttons. Only the v and y pins worked and even then the y pin was not the correct pi on the sparkfun pro micro. It should be pin 10 but it acted like pin 4.myPiZero wrote:I modified the code after you saw my comment. Please use the new code.
Last edited by winnetouch on Tue Nov 01, 2016 5:59 am, edited 1 time in total.
Who is online
Users browsing this forum: No registered users and 1 guest