Jump to content

an Arduino USB HID controller, composite USB controller


overpro

Recommended Posts

Hi icemaker

 

 

 

I have followed your writings,

 

i had connect pin 30 to pin 38 and light buton 1 on cvp joy#2 >> everything is normal

 

but,

 

i had connect pin 22 to pin 38 on cvp joy#1 light button 1 and 2. and x / y axis distorted.

 

is this a problem? or i need use rotary encoder for cvp joy#1?

 

attachment.php?attachmentid=106828&stc=1&d=1415226655

 

another problem is,

 

x - y axis dont work . i had connect like this pict. but dont work

 

AnalogReadSerial_BB.png

Hi banillasky, the code has the analogread() commented out in the arduino code ( it's located at the very end of the code ), you can uncomment the line and it should work. Please read the first few posts in this thread, there are some discussions.

 

Will this work with an Arduino Uno R3 ?

( with less inputs, obviously )

Uno R3 uses ATMega16U2 so the USB firmware can be used, but the arduino code can't be used on Uno, it requires some changes

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

Thanks for the reply Overpro. I don't know enough about coding to make a functional sketch. I will buy a 2560...

---------------------------------------------------------

PC specs:- Intel 386DX, 2mb memory, onboard graphics, 14" 640x480 monitor

Modules owned:- Bachem Natter, Cessna 150, Project Pluto, Sopwith Snipe

Link to comment
Share on other sites

  • 1 month later...

HI OverPro

 

Would it be a huge ask to get you to compile the USB firmware so the Joystick presents some different names? Reason behind the ask it I'm thinking I'm going to need at least two of them in a pit, especially now the rotarys are working.

 

If I rightly remember it presents itself in windows as CVP, could you generate two new sets of firmware where one presents itself as CVP-1, and the other as CVP-2, or something like that so its easier to identify which board I'm working on.

 

Thanks

 

Peter

Link to comment
Share on other sites

HI OverPro

 

Would it be a huge ask to get you to compile the USB firmware so the Joystick presents some different names? Reason behind the ask it I'm thinking I'm going to need at least two of them in a pit, especially now the rotarys are working.

 

If I rightly remember it presents itself in windows as CVP, could you generate two new sets of firmware where one presents itself as CVP-1, and the other as CVP-2, or something like that so its easier to identify which board I'm working on.

 

Thanks

 

Peter

 

Hi Peter,

 

If you don't mind to have an ubuntu linux VM installed I can let you know how to compile the firmware, so you can change the name to what ever you want.

 

Regards

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

Thanks for the offer Overpro, I'll build a Ubuntu VM up.

 

Cheers

 

Peter

 

Hi OverPro

 

I managed to loose myself in the wonderful world of Linux makefiles, while looking for the step that I missed after making the first binaries I found this on the AMTEL site:

/*

Atmel Studio 6.2 sp1 (build 1502) Installer – with .NET

Atmel Studio 6.2 sp1 (build 1502) Installer – with .NET

(721 MB, updated October 2014)

 

This installer contains Atmel Studio 6.2 service pack 1 with Atmel Software Framework 3.19 and Atmel Toolchain. This installer also contains MS Visual Studio Shell and .NET 4.0. Select this installer if you need to install Atmel Studio on a computer not connected to the internet.

/*

 

Could I use this to compile the firmware or is GCC under linux needed? I'll apologise if its a numpty question, I've been spoilt with c# :)

 

Update - looks like I may have approached this the wrong way - is downloading the 8 bit tool chain from here the best way to get the right compiler loaded?

http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORLINUX.aspx

 

 

Cheers

 

Peter


Edited by bnepethomas
Link to comment
Share on other sites

Hi OverPro

 

I managed to loose myself in the wonderful world of Linux makefiles, while looking for the step that I missed after making the first binaries I found this on the AMTEL site:

/*

Atmel Studio 6.2 sp1 (build 1502) Installer – with .NET

Atmel Studio 6.2 sp1 (build 1502) Installer – with .NET

(721 MB, updated October 2014)

 

This installer contains Atmel Studio 6.2 service pack 1 with Atmel Software Framework 3.19 and Atmel Toolchain. This installer also contains MS Visual Studio Shell and .NET 4.0. Select this installer if you need to install Atmel Studio on a computer not connected to the internet.

/*

 

Could I use this to compile the firmware or is GCC under linux needed? I'll apologise if its a numpty question, I've been spoilt with c# :)

 

Update - looks like I may have approached this the wrong way - is downloading the 8 bit tool chain from here the best way to get the right compiler loaded?

http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORLINUX.aspx

 

 

Cheers

 

Peter

 

Well I haven't tried to compile the firmware under windows, so a stable approach would be use Linux to compile the firmware, and we don't need to edit Makefile too much.

 

I added a simple instructions on how to compile it under linux, actually It's very easy. please check the first post of this thread.

 

If you prefer windows anyway, then I believe GNU make ( MinGW make.exe or cygwin ) and GCC for windows is required. And winavr from sourceforge.com is required as well.


Edited by overpro

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

hi, bnepethomas, if you want to use windows then avr studio is the way to go. I use microchip not atmel but the process is the same. There is a version of flip for windows I believe. You would not use a makefile with avr studio, that gets generetaed by the ide automatically, you just have to set up a project folder and most probably have to select the type of chip and toolchain from within the ide. If you have not done it before it can be a bit daunting, but after using vs with c# you should be ok. You would also have to make sure that all the paths in the headers are correct. With usb, windows distinguishes each device by three values, vendor id, product id and serial/revision number. Just changing the name would not work I believe, you would need to change the serial/revision number to identify a different device. In the file called descriptors.c there is a section of code headed 'const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =', in that section of code you will find the device id's. Change the value .ReleaseNumber from 3 to 4, and that should do. If you wanted to add a third device, you could change it to 5, the actual value does not matter, just needs to be different for each device. This is my understanding of how this works, maybe someone else could chip in and confirm this is right or that maybe I am talking bullshit as usual.

Link to comment
Share on other sites

hi, bnepethomas, if you want to use windows then avr studio is the way to go. I use microchip not atmel but the process is the same. There is a version of flip for windows I believe. You would not use a makefile with avr studio, that gets generetaed by the ide automatically, you just have to set up a project folder and most probably have to select the type of chip and toolchain from within the ide. If you have not done it before it can be a bit daunting, but after using vs with c# you should be ok. You would also have to make sure that all the paths in the headers are correct. With usb, windows distinguishes each device by three values, vendor id, product id and serial/revision number. Just changing the name would not work I believe, you would need to change the serial/revision number to identify a different device. In the file called descriptors.c there is a section of code headed 'const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =', in that section of code you will find the device id's. Change the value .ReleaseNumber from 3 to 4, and that should do. If you wanted to add a third device, you could change it to 5, the actual value does not matter, just needs to be different for each device. This is my understanding of how this works, maybe someone else could chip in and confirm this is right or that maybe I am talking bullshit as usual.

 

:) thanks for the pointers - this gives more of an. Understanding do Plan B.

 

Cheers

 

Peter

Link to comment
Share on other sites

On this keyboard matrix would a toggle switch take 2 keys to make it turn on and off? I've been messing around with a joystick encoder that has 2wires for each button and I hook a toggle switch up to it and it flipped the switch on but I could turn the switch off? I'm reading on this dcs bios and they use a 2 position on and on 3 pin toggle switch connected to an arduino board one pin to ground one pin to a pin and the 3rd to another pin. I was going to just use push buttons for my pit to go with your keyboard matrix.

 

The toggle switch works just like a push button, you flip on the switch then it's on, flip it to the off position then it's off. I don't quite understand on this: "I hook a toggle switch up to it and it flipped the switch on but I could turn the switch off"

Are you saying after flip on the toggle switch you are unable to flip it back to the off position?

I tested by using http://www.planetpointy.co.uk/joystick-test-application/

and never encountered this issue before.

 

 

For the 3 pin toggle switch, you can just wire the common (middle) pin of the toggle switch to the ROW pin in the matrix board, and wire the left / right pin of the switch to the COLUMN pin.

 

 

But some of the switchs don't really work right with push buttons unless I have two buttons for each switch.

Can you please provide more details on this?

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

This thread explains the reason behind your problem and how to solve it:

How to set up toggle switches (a tutorial)

Note: I have no idea if that information is still accurate.

 

If your aircraft is supported by Helios, you can use that instead to map your joystick buttons to actions in the simulation.

 

If your aircraft is supported by DCS-BIOS (at the time of writing: A-10C and UH-1H), you can program your Arduino as a DCS-BIOS-compatible serial device instead. If available, this is the option that is easiest to use, but it will not allow you to use the same switch for different actions in different aircraft (at least not without knowing how to program C++).

Link to comment
Share on other sites

Yes I used a 2 pin toggle switch and when I flipped the switch on it flip the switch on in the game like its supposed to but when I flip it off it stays on in the game.

 

Uh, got it, just as Ian mentioned above, please refer to that link on how to configure the switches in DCSW

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

The push button works well, but nothing with encoder. Where is the mistake? Thank you!

 

Shouldn't that blue wire be connected to ground?

The connection of the push button in your Fritzing sketch also does not make any sense at all. Only one side of the button is connected at all...


Edited by [FSF]Ian
Link to comment
Share on other sites

Hi Overpro!

I wish you a good new year.

This time, i need your help about cabling. This is what I have done :

 

The push button works well, but nothing with encoder. Where is the mistake? Thank you!

 

Hi usul

 

:wacko: i can't see any error in the wiring, have you tried remove the button and just keep the rotary encoder alone to see if it works?

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

I again tried with and without push button. But it's better now, i dont know why. Pins 22 & 23 work fine with encoder and with push button. Still nothing with pins 24 & 25.

Thank you!

what tools are you using for testing the button / encoder ?

 

If you are using the Windows joystick test window for this then that make sense because the window only shows first 32 buttons status, you can try using some other tools such as "Pointy's joystick test"


Edited by overpro

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

Hi Overpro,

Thanks for your amazing work. It would give me much more fun from virtual flying.

Since I'm finishing pcb for 16 encoders, 16 toggles, 32 buttons and 3 axes I have several questions to you:

1. Could you give me some hints how to disable second controller (only one visible in OS).

2. How to disable unwanted axes since they make a lot of noise and it seems that one pot connected to one input drives all of them in a weird manner.

3. I am wondering about changing behavior of one row of toggles in the way that an event would be send as a 100 ms pulse and not to stay on until toggle is switched. I have to get more into the code but if you have any hints then I would be very grateful.

Link to comment
Share on other sites

Hi Overpro,

1. Could you give me some hints how to disable second controller (only one visible in OS).

This requires change the firmware code for atmega16u2, delete the all the descriptors related to Endpoint 2 Output, and this also lead to the joystick HID report data structure changes so the arduino code also need to be modified : comment out all the key scan code from Row8 to Row16.

2. How to disable unwanted axes since they make a lot of noise and it seems that one pot connected to one input drives all of them in a weird manner.

Wire all the unwanted analog input pin to ground.

3. I am wondering about changing behavior of one row of toggles in the way that an event would be send as a 100 ms pulse and not to stay on until toggle is switched. I have to get more into the code but if you have any hints then I would be very grateful.

To generate a "pulse" for a toggle switch or button ( edge triggered instead of level triggered) the key scan code should work like this:

1. Scan the key value, 0 is on, 1 is off ( we have input pins set to Input with Pull Up )

2. Compare the scan value with the previous round's value ( need some buffer to store the previous value ), if you want a pulse when you flip on the toggle then the truth table is like below. Note that the "prev" and "current" value is the key scan value ( 0 = on , 1 = off ) and the result is the value should be put into the HID report ( 1 = 0n, 0 = off )

 
prev   current   result
1(off)  0(on)      1
0       0          0 
0       1          0
1       1          0

3. after the HID report data is assembled for this round refresh the prev key

scan value with the current one.

 

4. BUUUUUUUUUUUUT not finished yet, this algorithm needs more code to deal with the delay, with the above algorithm the pulse width is totally depends on the time difference between 2 rounds of keyscan: if the 2 rounds of the keyscan is only 3ms then the pulse width is also 3ms, this width is not enough for some of the flight sims especially FSX.

 

The delay code works like this, declare an array of buffer to store how many keyscan rounds elapsed since the start of the delay for each button. Say we want to delay a pulse for 30 rounds, then increase the counter by one in each round of the keyscan. Once the counter reaches 30, set the the "result" to 0 and clear the corresponding counter to 0.

 

the delay is used for rotary encoders, you can see how it is implemented in arduino sketch.

  • Like 1

overpro = I'm not good at Nintendo Mario and always get "Game over" pretty fast, so over~~pro

Link to comment
Share on other sites

Overpro,

 

First, thank you for taking your time to create this sketch and get it working for those of us without programming skills.

 

I've had a Mega2560 for three years now, and have not been able to find a long term use for it until now.

 

 

With that said, I uncommented the analog inputs line and programmed the Arduino with the sketch, and then flashed it to appear as a joystick.

 

Buttons are working great, but my analog inputs are not.

 

I hooked up a Parallax 27800 two axis joystick to Analog pins 0 and 1 with 0 being the Up/Down axis and 1 being the Left/Right axis.

 

The movement of the stick is detected, but it is not working correctly.

 

When the stick is at rest, the system shows the joystick response as being maximum.

When I move the stick to the right, the response meter starts at 0 and moves up to the 50% mark.

 

When I put it at rest, it goes back down to 0 and then maximizes at 100%.

When I move the stick to the left, it drops down from 100% to 50%. At rest, it goes back to 100%.

 

Every potentiometer I have hooked up, no matter what brand or resistance level exhibits this same characteristic.

 

Help?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...