[NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Various user-contributed guides for hardware-related things
Post Reply
User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

[NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by sotasystems » Thu Nov 03, 2016 12:38 pm

This guide was copied directly from my original build post http://www.sudomod.com/forum/viewtopic. ... 5&start=30

Since I have been getting lots of private messages on this, and a few posts on my original post, I will try to describe what I have done in here. Because this guide was included in my original build log, rather than separated, I decided to make a new topic for this.

WELCOME TO MY GUIDE! I would kindly like to ask you to read through the entire guide first before you start to ask any questions, as it covers quite a bit and the answer to the question you have in mind could be covered in here.

WARNING:
First of all, I want to tell you that whatever you do following this guide, you do on your own risk. As we are in the age where people like to think that they can offload their own responsibilities onto other people, I feel I should point out that, should you choose to follow this guide on your own hardware/software, it is your own responsibility when something goes wrong in any way and you are entirely on your own.

Some forewords:

There have been many ladies and gentlemen who thought that this sketch HAS TO be used with analog stick(s) (1 or 2), and you might think the same, but I can assure you that this is a misunderstanding of yours. Read carefuly through this guide, as it also covers how to use the sketch without any analog sticks at all, solely for the purpose to use it with up to 14 buttons only!

This original sketch can be used with up to 2 analog sticks and 14 buttons, and you don't have to connect all 14 if you don't want so many.

Also, you are not forced to use PSP analog sticks only! Any 2 axis, 4 pin analog stick will work, too!

This is made possible by combining my script with some of [mention]Helder[/mention]'s for his AIO board, which [mention]wermy[/mention] has written. Thank you very much, gentlemen! :) Shoutout to these guys!

This way, the calibration process you had to do before is completely made unecessary and sticks just work out of the box and are much more accurate! :D

So now, if you have an analog stick different from a PSP 1000 and would like to use it, just hook it up accordingly to 5V (if it is 5V), GND, and the analog pins (A0 and A1 or A2 and A3). It may or may not work, I can't guarantee anything, but pretty much everything I tried just worked out of the box with no modifications needed to the code.

Enough rambling.
Now to the guide :):

Now, you will need the Arduino software 1.0.5r2 for that. You can use the portable (non-install), so if you do not want to overwrite your existing Arduino IDE, you don't have to. I found that my software runs on 1.0.5r2 only, that is why you need it. And since I use 1.0.5 and 1.0.6 it didn't bother me.
https://www.arduino.cc/en/Main/OldSoftw ... ases#1.0.x

Now, when you are using an arduino clone from SparkFun like me, you need additional software. Mine does look like this:
Image

If you have one that looks like this:
Image

I have confirmed that this one also works. Now, it might be that you have another leonardo micro clone that looks similar or actualy different from what I have used, so you have to try out yourself if it works.

The additional software you need is this:
http://www.mediafire.com/file/9wrpgc6fk ... re-1.6.zip

Unzip it in your Arduino/hardware folder (or your Arduino document folder alternatively) so that it would look like this on windows for example:
C:\Program Files (x86)\Arduino\hardware\SF32u4_boards-pre-1.6

Now, to make my sketch actualy work, you need to replace two files which have been modified you can download here:
http://www.mediafire.com/file/xkpgpxw9xn70lx6/USBAPI.h
and
http://www.mediafire.com/file/royrgfs7ia9f3cf/HID.cpp

First, navigate to Arduino\hardware\arduino\cores\arduino and then MAKE A BACKUP OF "HID.cpp" AND "USBAPI.h". Also, if you decide to just rename them, keep in mind to NAME THE EXTENSION DIFFERENT FROM ".h" OR ".cpp" OR ARDUINO WILL COMPLAIN.

Then you can place the two modified files there.

Plug in your Arduino clone.

Start the Arduino IDE and from "Tools" select "Board" and then "SparkFun Pro Micro 5V/16MHz"
and then also select your COM port.
Also, [mention]vnman[/mention] has found out, that with some boards it might happen that this does not work. Please instead select "Arduino Leonardo" from "Board" then.
Image
(Also check that it's set right by checking what it's saying in the bottom right).

Then from "File" select "Examples" -> "01.Basics" and then "Blink".
Upload this sketch.
If it now asks you for drivers (it may or may not), you can point it to Arduino\hardware\SF32u4_boards-pre-1.6\signed_driver, the drivers are included there.

Now everything should be prepared. You can now use my sketch to turn it into a controller with 14 buttons and 2 analog sticks:

http://www.mediafire.com/file/wnkhybdwc ... roller.ino

This sketch is "pre-configured" to be ready to go, but it is recommended to match the settings with your physical configuration:

Button configuration:

You can reconfigure the button mapping if desired and specify which pin is connected to which button on your gameboy. Take care though NOT to delete any of them if you don't use them! It WILL break the code. Please instead map the button you don't use to a free pin on your arduino! Don't use pins twice or more times! Only use the pins you physicaly have on your board!

Code: Select all

int PinA = 1;
int PinB = 0;
int PinX = 2;
int PinY = 3;
int PinStart = 4;
int PinSelect = 5;
int PinDPadUp = 6;
int PinDPadDown = 7;
int PinDPadLeft = 8;
int PinDPadRight = 9;
int PinL1 = 10;
int PinL2 = 16;
int PinR1 = 14;
int PinR2 = 15;
(Line 22-35)

After you have configured your button pins, a little below that snippet you can also configure which physical button will be which button number on the joystick and remap it if desired. If there is an unused button there, set it to 0. This is important if you don't use a pin in the upper snippet! Otherwise you can specify buttons from 1-14. Again, please do not use values twice or more times:

Code: Select all

int A = 1;
int B = 2;
int X = 3;
int Y = 4;
int Start = 5;
int Select = 6;
int DPadUp = 7;
int DPadDown = 8;
int DPadLeft = 9;
int DPadRight = 10;
int L1 = 11;
int L2 = 12;
int R1 = 13;
int R2 = 14;
(Line 39-52)

IF YOU DO NOT HAVE ANY ANALOG STICKS: THIS STEP IS STILL IMPORTANT FOR YOU!
Analog stick configuration:

Now, depending on the amount of analog sticks you have, change this snippet accordingly:

(It's self explanatory, but:)
0 is No analog stick at all
1 is 1 analog stick
2 is 2 analog sticks

[If you do not have any analog sticks, it is important you set this to 0, or the X and Y axis will go crazy all over the place when you have nothing connected to the analog inputs!]

Code: Select all

int AnalogSticks = 2;
(Line 7)

IF YOU DO NOT HAVE ANY ANALOG STICKS: Congratulations! You have finished at this point! :)

Otherwise, read on:


Also, depending on your setup, you can remap the analog inputs by specifying different analog inputs if desired. In that same snippet, you can also adjust the deadzone and invert any stick axes if needed (set from 0 to 1):

Code: Select all

int deadzone = 5; // Values under 5 will return 0
int x1Pin = A0;
int y1Pin = A1;
int x2Pin = A2;
int y2Pin = A3;
int InvertX1 = 0;
int InvertY1 = 0;
int InvertX2 = 0;
int InvertY2 = 0;
(Line 10-18)

I for example had to remap the first analog stick's X and Y axis inputs and invert the first X axis, because my analog sticks inside my gameboy are rotated.

I use 2 PSP 1000 analog sticks in my build.

1st analog stick (Or if you only have 1):
Connect Left/Right to A0 of your arduino
Connect Ground to Ground
Connect Up/Down to A1 of your arduino
Connect VCC to 5V

2nd analog stick:
Connect Left/Right to A2 of your arduino
Connect Ground to Ground
Connect Up/Down to A3 of your arduino
Connect VCC to 5V

Here is the wiring for the same PSP 1000 analog stick I have used for this (passed over directly from adafruit):
Image

If you have any other analog sticks, please refer to their coresponding wiring datasheet.

Autocalibration:

The analog sticks autocalibrate themselves every time the leonardo is powered up (usualy when you first power up your gameboy).
To calibrate your sticks, rotate them 360° a couple of times, and that is it.



Downloads for Helder's AIO, has modified sketch and Hex Files for USBasp:
http://www.mediafire.com/file/qebcxs7xf ... O+Code.zip
Last edited by sotasystems on Mon Nov 28, 2016 4:32 am, edited 17 times in total.
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by vnman » Thu Nov 17, 2016 7:30 am

Thanks for the guide.

One thing, I have to select "Leonardo Pro" in Adruino in order to reprogram my Adruino clone otherwise Adruino failed on upload.

Tested with the psp analog stick and it works. I ran out of the silicon buttons waiting for these (they are on the slow boat from China) to finish my 4th build...

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by sotasystems » Thu Nov 17, 2016 4:26 pm

vnman wrote:Thanks for the guide.

One thing, I have to select "Leonardo Pro" in Adruino in order to reprogram my Adruino clone otherwise Adruino failed on upload.

Tested with the psp analog stick and it works. I ran out of the silicon buttons waiting for these (they are on the slow boat from China) to finish my 4th build...
Did you use the same software like I statet in my guide?
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by vnman » Fri Nov 18, 2016 12:57 am

Same software version, tried on both Windows 10 & Debian. I have the blue variant.

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by sotasystems » Fri Nov 18, 2016 1:09 am

vnman wrote:Same software version, tried on both Windows 10 & Debian. I have the blue variant.
But it works fine when you select "Leonardo Pro" in the boards menu, yeah?

Can I safely put that in my guide?
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by vnman » Fri Nov 18, 2016 1:17 am

It works as expected. I have 6 buttons and 1 psp stick and ofcourse the start, select and directions.

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by sotasystems » Fri Nov 18, 2016 1:31 am

vnman wrote:It works as expected. I have 6 buttons and 1 psp stick and ofcourse the start, select and directions.
Thank you very much. :)
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by vnman » Fri Nov 18, 2016 3:16 am

I believe mine came preprogram as "Leonardo Pro" and that is why I have to select "Leonardo Pro" in Adruino software.

User avatar
sotasystems
Posts: 160
Joined: Sun Oct 09, 2016 4:56 am
Location: Germany, 127.0.0.1
Has thanked: 95 times
Been thanked: 93 times
Contact:

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by sotasystems » Fri Nov 18, 2016 4:34 am

vnman wrote:I believe mine came preprogram as "Leonardo Pro" and that is why I have to select "Leonardo Pro" in Adruino software.
Post changed accordingly. Thanks again
Ladies and gentlemen, I would like to inform you that I am currently moving very far away, and therefore I am very busy.

UPDATE: I am still alive! My ISP is setting up my internet on the 19th of January at my new place, explaining my offline-ness.

If you write me a PM, I will very likely take some time to respond.

Also, my 2nd build will soon go on, so if you've been following it, please stay tuned! :)

Many thanks for your understanding!

User avatar
JujuPi
Posts: 51
Joined: Mon Nov 21, 2016 2:08 am
Has thanked: 8 times
Been thanked: 16 times

Re: Sota's 14 buttons + 2 analog sticks guide for a (Sparkfun) Leonardo Pro Micro (Cheap teensy alternative)

Post by JujuPi » Thu Nov 24, 2016 9:16 pm

Sota I would like to thank you very much for making this publically available. We all should! I bought my Leonardo from Aliexpress for $4 because I am trying to make this project as cheap as possible. Guess what! It worked on first go and all I did was short out a random pin to ground and bingo it showed up on the calibration menu through Windows!

For all those wondering where I got mine - https://www.aliexpress.com/item/ATmega3 ... 75582.html

THANKS AGAIN SOTA! :) Much love from JujuPi

:D :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest