AVR USB Joystick

This project is a USB joystick based on a simple AVR ATmega8. The ATmega8 simulates a standard USB HID device with 8 analog axis and up to 28 buttons including the Coolie hat.

The project is based on Mjoy hardware and source code made by Mindaugas Milasauskas.
Unfortunately the Mjoy homepage no longer exists at: http://www.mindaugas.com/projects/MJoy/

Other sources are http://home.base.be/verlejan/Mjoy16E.html , http://www.flightsim.com/vbfs/content.php?2112 or Google.

I have changed the hardware to ATmega8 in SMD TQFP package to increase the analog channel number from 6 to 8. I made also the required code changes to support the 2 additional channels. Unfortunately the button order on the PCB header is a bit confuse, see the button and axis assignment image for details.

Circuit overview

Circuit overview
AVR-USB Joystick Schematic
AVR-USB Joystick Schematic
AVR_USB_Joystick_Schematic.pdf
Version: 1.0
249.0 KB
12309 Downloads
Details
Button and Axis Assignment on headers
Button and Axis Assignment on headers
AVR_USB_Joystick_BOM.txt
Version: 1.0
2.1 KB
5751 Downloads
Details
PCB Gerber Files
PCB Gerber Files
AVR_USB_Joystick_Gerber.zip
8.9 KB
3619 Downloads
Details
Sourcecode
Sourcecode
AVR_USB_Joystick_Code.zip
28.9 KB
6238 Downloads
Details

93 thoughts on “AVR USB Joystick

  1. Hey, i recently discovered your site. The project seems to be more than interesting. I am a student of electronics engineering and also a fan of flight simulation.

    Can you tell me if axis are stable? I mean if they dont oscilate and if joystick needs windows calibration.

    Maybe you can expand your article with some more info.

    Thank you very much bro, hope you reply!

    • Of course the axis are stable.
      Calibration is needed since the readout depends on the potentiometer you connect to the analog inputs.

  2. Fantastic update on the original! I am just getting started in microcontrollers and I though I would make this my first project. I have the 1.1 and 1.2 version source of mjoy but when trying to compile in AVR Studio 4 I get 3 errors about “Invalid redefinitions”.

    Anyways, your code compiles perfectly, but I was wondering what Atmega microcontrollers it can be used with? Can it be used with any in DIP packaging? I have been having a very hard time trying to locate any Atmega8 as everyone is out of stock. The closest I could find for the chip you used is the ATMEGA8-16AU. Would that work? Sorry for the bombardment of text LOL. Any advice or direction you could provide would be MUCH appreciated.

    • Look for the ATmega8A as a drop in replacement. not sure if the ATmega8 is still in production.

      You can use a ATmega8(A) in DIP packages too, but you need to change the schematic then since DIP and TQFP have a different pinout.

  3. Hi,

    I was wondering whether you have the board and schematic in Eagle format as well. I would like to modify them to be able to use a DIP packaged ATmega.

    Thanks

    • Sorry, but I do not work with Eagle, so there is no schematic or board file in Eagle format available.

  4. Hi,

    I want to use the project for racing wheel controller, but unfortunately no force feedback or vibration implemented, How i modify it in order to use force feedback or vibration motor ?

    Thanks a lot for your reply

    • You can not modify the AVR USB Joystick to use force feedback. That’s neither supported by hardware nor by software.

  5. Hello,

    has you got the Layout of the bord as a picture or something like this?
    I want to built the bord an can you make a list what i need to build it?

  6. Hello,

    I build 4 of these controllers a year ago and working fine, now when I plug in to the computer (all 4 of them) windows XP says that the USB device failed.
    Is it windows updates maybe?

    I tried to re-program the MCU and no problem, signature reads ok.

    Also, I’m interested in the source code (assembler), but have not done much assembler programming, only c/c++. What is the best way to understand how this USB-jostick code works? I tried to follow it but there is just so much of it.

    Thanks,

    • Sound like a problem due to an XP update to me.

      Most of the assembler code deals with the USB stack. I not sure about the complete code as well just digged deep enough to extent for more analog axis and buttons.

      But C code for HID devices working the same way exist already, look here: http://www.obdev.at/products/vusb/hidkeys.html

      You just need do deal with the USB interface and device descriptors to make a joystick.

    • That’s a 2 layer board, not sure if the layout as picture is usefull then.
      What you mean with “mass”, maybe board outline dimensions?

      Anyway, not earlier than two weeks since I’m in holidays.

  7. Nice work, been looking for something just like that to make controls for a flight simulator. I’ll have to look into the code a bit more when I get the chance.

    Mostly out of curiosity, how did you make your PCB’s? BatchPCB, or do you have some in-house capabilities to make them?

    • I do only single side PCB’s at home. Two or more layer layouts are given to a dedictated manufacturer. Usually I combine layouts from different projects to reach the minimum board size for manufacturing.

  8. Hi,
    I have built several board, and from some reason I have PCs that it’s working like a charm,while on others I get an unknown USB device message and can’t get it to work….

    please advise.

    Thanks

    • Seem to be a PC side USB problem. Just a wild guess, maybe some PCs do not support USB low speed devices any longer?

  9. Thanks for that…

    I tried now to connect it over an external USB hub, and it works this way…

    Any thoughts why shouldn’t it work with the my PC’s USB internal ports?

    Thanks again.

  10. I have been researching all I could find of what’s left of the original mjoy project and it seems a lot of issue comes from variations in the USB power source. An externally powered hub cured a lot of problems for a lot of different folks. I’m gonna try using a 7805 voltage regulator and a wall wort to keep the power stable between different PC’s. Meir, I’m curious to know if your external hub is powered by a wall wort?

    Thank you so much Michael for giving an older project new life! I am working on a project and desperately need some way to interface a single potentiometer as a joystick axis.

  11. Hi Jonothan, thanks for replying.
    I’m using a hub that has a power input, but I’m not plugging it, so basically you can say that this is a non powered hub.
    please update on your success with the 7805 voltage regulator.

  12. Hi Meir, glad it worked! I haven’t yet tried the 7805 but I have been looking at more “standard” USB circuits and made some mods to mine. I removed the 4.7k resistor and Windows 7 on a laptop recognized it as an input device but with errors. I changed the 3.3v zeners to more commonly used 3.6v zeners and the laptop picked it up right away! It is even recognized by my linux desktop. I’m still testing and refining it, as I have some problems with the pots, but I’ll post my results. Be sure to connect any unused pot inputs on the atmega to ground.

  13. Hello
    nice and interesting software to use as a Flight sim DIY joystick, I just have a question, what are the Fuses Hex codes to use this program in the ATMega 8 MC
    Thank you in Advance for your Response
    Regards

  14. Hello,

    any idea why I can’t build the sourcecode in AVRStudio 4.0 ?
    It says: Line too long (in .aps-file).
    (I’m an absolute newcomer in AVRSTudio)

    Matthias

  15. Hello great project.

    It is possible to migrate this project from Atmega8 to Atmega16? I have built mJoy16 but there is not source code. Next question: is possible to merge two pots (two inputs) as result one axis Y? I need this for throttle and brake and I need this on one axis.

    • Porting to mega16 shouldn’t be a big deal, you just need to rebuild the code with includes for mega16.

      Your poti problem seems to be more hardware related. I think you need to find a way to wire up the pots right to get the functionallity.

  16. Hello and thank you very much for so generously publishing all of your work online!
    I have assembled a USB/Analog/Joystick device, however I have followed the Mindaugas Milasauskas guide at: .flightsim.com/main/howto/mind.htm as it seemed easier and quicker to use the ATmega8 in a DIP package.
    Anywaze, I am having much the same problems as many who have posted here:
    My Mac sees the device as a Joystick/HID however my XP/Windows/PC will only see it as a USB, Unknown Device.
    Have you been able to come to any conclusions as to a mod to the hardware or code that will allow Windows to reliably id the device?
    Any further advice would be hugely appreciated and thanks again for your guidance thus far.
    Dan

    • You may try the suggestion from Jonothan Greene in his comment above.

      He changed the Zener diodes from 3.3V to 3.6V, seems it solved the problems.

  17. Thanks Michael, I ended up trying all suggestions in this order:
    -Installed a 7805 to provide discreet power.
    -Installed Zener Diods between 0V and +/- Data lines.
    -Removed the 4k7 Res.
    I tested between each mod, but, it wasn’t until I removed the 4K7 that XP would see the device. When I tried rerouting the power back to the USB 5V line, Windows lost it again.
    (My mac could still see the device regardless of each change)
    I’m not sure whether the system requires all of the mods before XP will recognise the device as an HID and am still unclear as to what difference removing the 4k7 made, but for now, the thing is working, so thanks again.

    I’m hoping to expand the system to include two rotary encoder inputs on some of the I/O lines.
    Is that something with which you have had any experience?

  18. Further testing has now shown that Windows will actually only see the device if it is powered with a battery (via the 7805) and not with a mains based supply (wall wort)
    Has anyone else had similar findings?
    I’m not sure whether the mains hum might effect the data from the AVR?

    • Dan, this is a late reply so you may have already worked it out, but just in case anyone else needs the information here it is – you shouldn’t need to use a 7805 voltage regular as long as you use 3.6v zener diodes and remove the 4.7k resistor. When I suggested trying a 7805 that was only for testing purposes because the original design used an incorrect method to drop the voltage on the Data lines. It will work using power from the USB, no external power should be required.

      Now considering the 7805 is not necessary anymore, the only reason I can guess as to why it would only run from a battery is that your wall wort was not at least 7.5v or higher, as most standard 7805’s need at minimum 1.5v higher voltage than what it will output (5v).

      Once again for clarity, you need to do both of the following:
      -Use 3.6v zener diodes
      -Remove 4.7k resistor

  19. Hi

    My name is Amir Rehman. I have read your article AVR USB Joystick about building a joystick. It is really a fantastic article which demonstrate the procedure very brilliantly. I am just to make a racing wheel joystick and your expertise forced me to ask you about making such joystick. I ll be thankful if you assist me how can I develop a racing wheel joystick.

    Kind Regards
    Amir Rehman

    • A racing wheel is nothing fancy. Build the mechanical part for the wheel including the potentiometer and connect it to one of the analog channel, done.

      • Hi Michael,

        I want to develop a racing wheel using this project. Assume I have Gran Turismo 5 on PC, will this joystick be playable with this game?

        Thanks

      • Another question,

        If this racing wheel be compared with logitech G27 then which would be good one?

  20. hi:
    I have a lot of problems with mjoy project because when I press a button, at same time press 2 or 3 more. can somebody help me with a schematic for dip pack atmega 8a please?
    I like to make exactly this project but i cant buy smd package. i´m based completely in this code version and schematic. Have somebody help me? Im loosing my head…and my job almost.

    http://flightsim.com/main/howto/mind.htm this where I´m based to make the project.

    • See my schematic, the reason why I added all the diodes to the buttons is to prevent pressing more than one button at the same time. The diodes are missing in the original schematic.

  21. I have 1 question about your project. I am simply looking for a usb replacement for a game port to sense contact closures (button presses) does the pc see this as a game port for software that is made to use the old style game port?

    Thanks
    Daryll

  22. Hi,

    I’m from Czech Republic, and I am really intrested in this project. I like it, but I’m afraid that will works. I’m a little scared that I draw a scheme, make it, join it, but it will not works. I wanna ask you to sent me email with the newest versions of hex file, schematic picture, and everything what I need to build this.

    I also wanna ask about version of ATmega8. Is it problem if i use ATmega8-16PU or ATmega8535-16AI? I’m afraid of programming the hex file, i know the package is different in 16PU version.

    Thank you so much for your reply, BB, Martin.

    • All informations only are latest, including schematic and firmware.

      Replacing the ATmega8 in SMD by a DIP version requires significant changes in schematic since packages have a different pin-out. The ATmega8535 can not be used.

    • Sorry I’m still anoying you, but could you make sharp (HQ) photos of the board? or send me picture of both sides, thank you.

      • 3.3V Zener was the initial part. From experience of other users you may use 3.6V instead.

        About Win7 I can’t tell you, have no computer with such OS installed.

  23. Hello again bro. It took me a while but i finally built one using atmega16. Only change m8define.inc for m16define.inc on Avr studio. Working perfectly except for some axis range problems… im getting 99% of range… still working on it. Diodes must be 3.6V as stated in documents.

  24. Hello,

    My name is Alfonso and I am working with a PS3 controller. I want to do a modding with the pad but I have a problem, I can’t use the home button, it doesn’t work. So, there is any way to emulate this button with this AVR Joystick?

    Thanks

  25. Hi,

    I am going to build an Arcade Stick used mainly for Fighting – and Arcade Games. 🙂

    The stick I ordered has one mass for all four directions.
    If I just put the diodes on the other side of the switches will they still prevent ghost keying?
    (They should, right?)

    I took a short look at the code and it seems to me all buttons are enabled by default.
    Considering the performance (some arcade games are pretty delay sensitive) would it be an improvement if I throw out all of the stuff I don’t need or isn’t it nessesary? (no need for analog controls)

    Despire studying Electical Engeneering I really prefer asking before I order too much stuff and went into trouble. 😉

    Thanks Lothar

    • About the diodes you have to try, don’t know for the moment.

      You can remove parts of the code, might give some improvement but I wouldn’t expect much.

  26. Hello. I would like to ask if this device can work with operating system Windows 7. Thank you

    • It’s supposed to work since a standard USB HID device will be emulated. Although I didn’t test under Win7, don’t have the OS.

  27. Got it working. Windowa didn’t recognize it until I changed the 27pF capacitors to 22pF as stated in the atmega8A datasheet.

    works great now!

  28. Hey, awesome project! I am making something similar, and have downloaded the source code for the MJoy. I was wondering two things, though.
    1. How can I designate which buttons are which to the computer, e. g. the L and R, ABXY buttons, etc.
    2. How can I go about adding another X axis another and Y axis for another analog stick? The MJoy code only has one stick and I can’t seem to figure it out.

    Thanks, I hope to get me controller working soon!

    • The buttons are predefined by the USB HID descriptor. All buttons will show up in the device manager and can be assigned to functions within a software/game, ex. flight simulator.

      This USB joystick interface has 8 analog axis, and here rules the same as for buttons.
      Axis are: X, Y, Z, rudder, throttle, Rx, Ry, Slider

  29. Great work !!
    One question , please ….may be out of context ?
    As I cannot implement more than 7 axis at the moment
    I used the Hid Report Descriptor as a base to try to implement 8 axis with a Pic 18F4550
    and I cannot get it to show on windows Game controller
    With an Atmel chip would it show on the Windows Game controller ?
    If it should I must do some thing wrong

  30. Is there any way I could directly map buttons on the matrix to keyboard keys without using additional software?

  31. Hi Micheal,

    this looks like a very interesting project to my. I am thinking about to use it for my flight simulator home cockpit. But would like to know which resistance you used for your potentiometers.

    An other thing. I guess K1 (ISP) is the default programming connector from Atmel?

    Florian

  32. Hi!
    A want to use Atmega8-16PU, but the “ATmega8 in SMD TQFP” has 8 adc channel and Atmega8-16PU has 6 adc channel. It won’t be a problem?
    Thanks!

    (sorry for my English, i’m Hungarian and 14 years old)

    • Atmega8-16PU will work but you need to change the code for the different controller type.
      Wiring diagram needs to be changed as well since the controller pinouts are different.

  33. What is the resolution of the axises? I think the original mjoy had 2 10bit and 4 8bit. Are they all 8 bit?

    • Currently the code doesn’t use a serial descriptor. That means the code needs to be changed/extended to report a device serial to the USB host. (No, I will not do that…)

  34. As i can see the MCU doesn’t have an USB peripheral, did you bitbang the whole communication? I come from the Microchip world, thanks.

  35. Hi Michael, I’m currently building this project in form of a usb-n64-controller – But I have trouble finding the button and axis assignment-file. Can you please provide me with a link leading to it? :^)

    Thx

    • Axis and button assignment is done in the USB report descriptor at the end in mjoy_8ch.asm file.

  36. friends plan to do a control with two axes and 13 buttons, as someone help me because not find a way to record the firmeware and hex on Atmega382

      • And how can I do this? Can I copy the Code and compile it for the Tiny13? Or how can I change the code?

        • Download the source code, change the USB descriptor inside the code to fit your needs, then compile again. I recommend to read about how USB works and what the descriptor is for.

  37. Hello, could someone explain how to program this object with today’s day and not a parallel programmer? AVRISP usb with progISP 1.72. I have already planned three components and will not work either.
    Best regards
    Valerio

    • K1 ISP is where you connect the AVR USB-ISP. This header has a standard STK500 compatible pinout.

  38. Good morning.
    I found a very old PC and I planned with PonyProg.
    I connected everything and I noticed that pressing the buttons do not respond immediately, but we also put 5 or 6 seconds to respond.
    You can help me with this? E ‘a software problem (which also has the hat buttons on D25-D28 and D22-D25 of not) or some component that, on the diagram, it is of value to change?

  39. Good evening, I do not know why I have deleted the message without saying anything.
    I said that I mounted the circuit and trying it I noticed that it is very slow to respond to commands. Someone could modify the code to make it faster? Or there are some components that must be changed in value? Then the “Hatswitch Button” to me are not the diodes D22 to D25 but on D25 diodes D28, it would be possible to move them to the schematic?

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments will be moderated! Spam deleted immediately!
Before you submit form:
Human test by Not Captcha