Reply
 
Thread Tools Display Modes
Old 11-25-2013, 07:33 PM   #1
overpro
Member
 
Join Date: Jul 2010
Location: Beijing
Posts: 158
Reputation power: 7
overpro is on a distinguished road
Default an Arduino USB Joystick controller, composite USB controller

This is an arduino Mega2560R3 based USB joystick controller,
I have successfully made it as a composite USB device ,
that means one arduino = two usb joystick controller, the reason to do this is DCSW only recognize 128 keys per USB joystick controller. If we have 2 then there will be 256 keys




program your Mega2560
download Arduino IDE from arduino.cc and download the arduino sketch from here:
Code:
https://github.com/calltherain/ArduinoUSBJoystick/tree/master/arduino
open the .ino file in Arduino IDE and upload it to your mega2560.

program the USB firmware
The 2nd step is to program the USB firmware, you need to use Atmel Flip:
http://www.atmel.com/tools/FLIP.aspx

Download and install flip, you need to make your Mega2560 enter DFU mode: with your mega2560 plugged, just simply shortcut the 2 pins momentarily at here:

Windows will recognize it as a new device, and you need to manually install the driver by using this file:
C:\Program Files (x86)\Atmel\Flip 3.4.7\usb\atmel_usb_dfu.inf

After the driver is installed, run Flip and select the chip type: ATmega16u2
then Open the USB port ( ctrl + u, click OPEN ) and load the usb controller firmware, see attached cvpJoystick YYYY-MMM-DD.zip file.

====1HID with 256 buttons is also available====
If you want a single joystick with 256 buttons please use this firmware instead.
http://forums.eagle.ru/showpost.php?...&postcount=142
But note that most of the Flight sims doesn't support such a joystick.
FSUIPC is the only one which has been confirmed works good for now.
----------------------------------------------------------------

Click "RUN" button at the lower left corner and it only takes 1 second to program the chip.
Unplug and replug your mega2560 and you are good to go.

If you want to make it back to a normal Mega2560 then repeat the above step but load the original mega2560 USBSerial firmware from here:
https://github.com/arduino/Arduino/t...uino-usbserial
Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex

Pin config on Mega2560
Pin 22~37 are row pins and 38~53 are column pins, you might need to build a keyboard matrix by your self, Row 0~3( pin 22,23,24,25) is reserved for rotary encoder, you need to wire the common pin of the rotary encoder to mega2560 22~25, and wire the A, B pin on the encoder to 0,1 or 2,3 or 4,5 ..... column pins ( mega2560 38,39 or 40,41 ..... )

Known Issue
The firmware might have some issue and if you encounter any problem please provide your comments on github or at this thread.
github.com/calltherain/ArduinoUSBJoystick
http://forums.eagle.ru/showpost.php?...85&postcount=5
If you want to build the firmware by yourself you need a Linux machine.

License
The code is released to Public Domain

Source Code
https://github.com/calltherain/ArduinoUSBJoystick
I hope you enjoy it.

ps. this firmware is inspired by Darran's project: Arduino UNO Big joystick HID firmware: http://hunt.net.nz/users/darran/weblog/15f92/
with out Darran's code I will never make this work. Thanks Darran.


---------------------------------
Firmware compilation instruction
---------------------------------


This is a simple instruction to guide you compile the firmware in ubuntu.

1. Make sure you have these packages installed on Ubuntu
Code:
build-essential
avr-libc
c-compiler
make
you can use this command to install these packages:
Code:
sudo apt-get install avr-libc c-compiler make build-essential
2. download the firmware source code from github
Code:
cd ~
git clone https://github.com/calltherain/ArduinoUSBJoystick.git
3. download LUFA library
Code:
cd ~/ArduinoUSBJoystick
wget https://lufa-lib.googlecode.com/files/LUFA-130901.zip
unzip LUFA-130901.zip -d LUFA
4. by the end of step 3, you should get a folder structure like this:


now go to /ArduinoUSBJoystick/firmware/cvpJoystickTest/ and execute
Code:
make
the compiled binary is cvpJoystick.hex, you can use FLIP to flash it into your Mega2560's atmega16u2 chip under it's DFU mode.


---------------------------------------------
Flash the original firmware to your Atmega16u2
---------------------------------------------

If you are unable to go to DFU mode it's possible that the firmware within your Atmega16u2 doesn't have a proper bootloader code within bootloader section in the flash.

You will need an USB ISP programmer to flash a correct firmware.

I attached a working version firmware (atmega16u2.zip) which includes a proper bootloader here just incase you can't find one.

connect your USB ISP programmer to the atmega16u2 ISP pins, you might need some Dupont Line to do this.


There are many ISP programmer software available out there, I personally use Progisp.exe, downlod atmega16u2.zip and extract it to .hex file, load it into progisp.exe and flash it, all done.
Attached Thumbnails
Click image for larger version

Name:	2013-11-26 03_13_00-Game Controllers.png
Views:	14778
Size:	27.0 KB
ID:	90983   Click image for larger version

Name:	DualController.jpg
Views:	13403
Size:	75.5 KB
ID:	90984   Click image for larger version

Name:	gotoDFU.jpg
Views:	12662
Size:	118.8 KB
ID:	90985  

Click image for larger version

Name:	2015-01-09 21_30_14-Ubuntu D6402 (1204 pre upgrade) [Running] - Oracle VM VirtualBox.jpg
Views:	8047
Size:	11.0 KB
ID:	111071   Click image for larger version

Name:	2015-01-09 21_51_05-1 Board - D__Parts_arduino_arduino-mega2560_R3-reference-design_Arduino_MEGA.jpg
Views:	8142
Size:	40.3 KB
ID:	111077  
Attached Files
File Type: zip cvpJoystick 2013-Nov-29.zip (3.5 KB, 1143 views)
File Type: zip atmega16u2.zip (6.0 KB, 341 views)
__________________
overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Last edited by overpro; 11-02-2015 at 12:21 AM. Reason: title change
overpro is offline   Reply With Quote
Old 11-25-2013, 08:19 PM   #2
Hansolo
Senior Member
 
Hansolo's Avatar
 
Join Date: Aug 2012
Location: Denmark
Posts: 1,175
Reputation power: 10
Hansolo is just really niceHansolo is just really nice
Default

Oustanding job Overpro Thanks for sharing

Cheers
Hans
__________________
Hansolo is offline   Reply With Quote
Old 11-25-2013, 09:18 PM   #3
don_sangria
Junior Member
 
Join Date: Apr 2012
Location: Switzerland, Baden
Posts: 22
Reputation power: 0
don_sangria is on a distinguished road
Default

Outstanding work! thank you very much for sharing!
Looking forward to see your setup and any further progress on your project!

Best Regards
Adrian
don_sangria is offline   Reply With Quote
Old 11-25-2013, 09:22 PM   #4
agrasyuk
Senior Member
 
agrasyuk's Avatar
 
Join Date: Aug 2011
Location: Buffalo Grove, IL
Posts: 1,691
Reputation power: 20
agrasyuk is a glorious beacon of lightagrasyuk is a glorious beacon of lightagrasyuk is a glorious beacon of lightagrasyuk is a glorious beacon of light
Default

Looks good. Thanks for sharing!
__________________
Anton.

My pit build thread .
Simple and cheap UFC project
agrasyuk is offline   Reply With Quote
Old 11-26-2013, 01:45 AM   #5
overpro
Member
 
Join Date: Jul 2010
Location: Beijing
Posts: 158
Reputation power: 7
overpro is on a distinguished road
Default

Known issue:

Issue#1 ( Fixed ):
after several hours, the button ID might drift to a new position, for example, the button 1 press might be changed to button 57 press.
I'm still investigating the issue, it might be caused by the RingBuffer manipulation in the USB firmware.
update: if Computer sleep (STR) and resume, the button id will drift.
update: Submitted a fix on github and updated the compiled .hex file in the main post.

Issue#2 (Fixed on 2013-Nov-29 )
With the controller attached, the computer will be blocked at POST, unless unplug it then computer will continue to boot:
The fix: The HID report will send to host only if the button status changed or the defined idle time has elapsed.

Issue #3 (Fixed on 2013-Nov-28 )
The Row8 ( digital pin 29) key scan code has an issue. It's a bug in arduino sketch.
https://github.com/calltherain/Ardui...Controller.ino
Now fixed.
__________________
overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Last edited by overpro; 11-28-2013 at 06:33 PM.
overpro is offline   Reply With Quote
Old 11-26-2013, 01:00 PM   #6
overpro
Member
 
Join Date: Jul 2010
Location: Beijing
Posts: 158
Reputation power: 7
overpro is on a distinguished road
Default

If you have programmed your MEGA2560 yesterday please flash the USB firmware back to normal MEGA2560 and reprogram the arduino sketch by downloading the sketch from github page.
And use the latest USB firmware in the top post.

Some error were fixed.
__________________
overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Last edited by overpro; 11-29-2013 at 02:48 AM.
overpro is offline   Reply With Quote
Old 11-26-2013, 03:15 PM   #7
Hobnob
Junior Member
 
Join Date: Sep 2013
Posts: 2
Reputation power: 0
Hobnob is on a distinguished road
Default

This looks great and just what i was looking for,

im trying to make the two MFCD's for the warthog, although i dont quite understand how i would wire this up, could you maeby post a picture or explain the physical connection of the buttons to the board? also can it support the 48 buttons needed for 2 mfcds?
Hobnob is offline   Reply With Quote
Old 11-27-2013, 02:40 AM   #8
overpro
Member
 
Join Date: Jul 2010
Location: Beijing
Posts: 158
Reputation power: 7
overpro is on a distinguished road
Default

Quote:
Originally Posted by Hobnob View Post
This looks great and just what i was looking for,

im trying to make the two MFCD's for the warthog, although i dont quite understand how i would wire this up, could you maeby post a picture or explain the physical connection of the buttons to the board? also can it support the 48 buttons needed for 2 mfcds?
This diagram is borrowed from MJoy16 document, the schema is almost identical, except we have 16 rows and 16 columns, and Row 1~4 are reserved for rotary encoders.

Please note that the diode is 1N4148, and this is REQUIRED to eliminate the ghost effect.


If you just want to perform some basic test, just wire the button's two pin to row / column pin:
Please note the row 5 ~ 16 should be used for button / toggle switch.


or you can test your rotary encoder as well, please note Row 1~4 are used for rotary encoder.
Attached Thumbnails
Click image for larger version

Name:	2013-11-27 10_18_32-MJoy16 - MJoy16-C1_Users_Manual_v1.pdf.png
Views:	14154
Size:	102.4 KB
ID:	91043   Click image for larger version

Name:	IMG_20131127_103402s.jpg
Views:	12656
Size:	60.0 KB
ID:	91045   Click image for larger version

Name:	IMG_20131127_103458s.jpg
Views:	12010
Size:	63.9 KB
ID:	91046  

__________________
overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro
overpro is offline   Reply With Quote
Old 11-27-2013, 02:11 PM   #9
icemaker
Member
 
icemaker's Avatar
 
Join Date: Aug 2006
Location: Near Lyon in France
Posts: 265
Reputation power: 14
icemaker is just really niceicemaker is just really nice
Default

Nice!!!
will check it asap!
icemaker is offline   Reply With Quote
Old 11-27-2013, 07:50 PM   #10
Quip
Junior Member
 
Join Date: Feb 2013
Posts: 36
Reputation power: 5
Quip has a spectacular aura about
Default

How can you have more than 32 buttons per DirectX controller??
Quip is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 10:21 PM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.