doveman Posted August 17, 2014 Posted August 17, 2014 I just bought an old Thrustmaster F-16 FLCS to cannibalise the stick to extend my Sidewinder FFB2, something like this http://forums.eagle.ru/attachment.php?attachmentid=83931&d=1371853528 Taking it apart, I see that there's just 5 wires coming from the stick for all the hats and buttons, so it's obviously using some sort of matrix. Will it be possible to use this with my Arduino Mega and appropriate code or will I have to just disconnect the existing wiring and solder up a separate wire per switch? Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
Nopileus Posted August 17, 2014 Posted August 17, 2014 (edited) I have this code for Teensy i found somewhere on the Internet a while ago, i can't remember the source though. This won't work on a normal Arduino without changing it, so be warned. Grab it here http://cl.ly/252W1j1K3a35 Edit: the source in post #22 on here Edited August 17, 2014 by Nopileus 1
doveman Posted August 18, 2014 Author Posted August 18, 2014 Thanks Nopileus, you've made me very happy to learn I can just stick with the existing 5 wires using the SPI bus and I don't have to wire 20-odd individual wires instead :) Shouldn't be too hard to adapt the code for the Arduino Mega hopefully and will leave me lots of inputs for other funky stuff as well. Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
doveman Posted August 20, 2014 Author Posted August 20, 2014 OK, I have to admit I'm a bit over my head here and need some help adapting the code to my Arduino Mega. I might end up buying a Teensy or something else cheap to use with the stick, as it might be a waste to use a Mega for it, even if I do wire up the original FFB buttons to it but all I've got is three Megas (with Ethernet shields) for now, so I want to test it with that to start with. Comparing the pinouts of the Teensy 2.0 https://www.pjrc.com/teensy/pinout.html and the Mega http://arduino.cc/en/Main/arduinoBoardMega , I can see the latter uses pins 50-53 for the SPI (MISO, MOSI, SCK, SS), whereas the Teensy uses Pins 0-3 (SS, SCLK, MOSI, MISO). The only pin assignment I can see in the code is for SS: const int slaveSelectPin = 0; so do I just need to change this to const int slaveSelectPin = 53; for the Mega? Another thing to be mindful is that simFFB only allows for assigning a trim button from those on the FFB joystick, so if I wanted to use that (which I'm not sure about at the moment), I'd either need to add an extra button to the F16 stick which is wired to the FFB2 board, or disconnect one of the F16 buttons from it's matrix and wire it directly to the FFB2 board, assuming that won't mess up the matrix and stop it working that is. Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
TigersharkBAS Posted August 21, 2014 Posted August 21, 2014 Was the original joystick a USB based stick? Have you considered flashing an Arduino as a USB device. I know this doesn't help with your wiring up issue but it might help simply things later. http://www.obdev.at/products/vusb/index.html [sIGPIC][/sIGPIC] Creator of: F-18C VFA-195 "Dambusters" 1998 CAG Livery https://forums.eagle.ru/showthread.php?t=213788 F-18C VFA-195 "Dambusters" July 2001 CAG Livery https://forums.eagle.ru/showthread.php?t=215950 Pilot avatars for DCS Logbook https://forums.eagle.ru/showthread.php?t=221160 How to make a DCS A-10C Panel http://forums.eagle.ru/showthread.php?t=65998
doveman Posted August 21, 2014 Author Posted August 21, 2014 Was the original joystick a USB based stick? Have you considered flashing an Arduino as a USB device. I know this doesn't help with your wiring up issue but it might help simply things later. http://www.obdev.at/products/vusb/index.html Nope, the F16 stick is gameport based. The FFB2 is USB but I'll be using that just for the pots and wiring up a separate button box to use the button inputs from that, so the F16 stick buttons/hats will have to go through a separate device. I'll eventually be building panels and running them via the Ethernet shield using Arduino2DCS or some other bridge application, so I'm not sure it would be worth setting up a separate board as a USB device when I could use a shared Mega to run both some panels and the stick, although if I can use something cheap for just the stick it might be worth considering. I'm not sure what advantage there is from making the stick appear as a USB device though. Certainly using the Ethernet instead of USB avoids the issue of devices changing assignment when replugged and I understand there's less issues with bandwidth or something using Ethernet. This tutorial http://codeandlife.com/2012/01/25/avr-attiny-usb-tutorial-part-2/ is using an ATtiny2313, which I could pick up for about £2. It needs some other components but it will still probably be a lot cheaper than a Teensy 2.0. I'm not sure if the same thing could be done with a Mega and whether it would need all the external components or if the Mega already has those built-in, so I'd need a tutorial written for doing it with the Mega, or someone who can translate that one where necessary, if I were to try it. I'm seems like it might be a lot of work though, compared to just running an Arduino the normal way, via USB which shows up as a COM port, or via the Ethernet shield, and then using a bridge to translate between either of those into language DCS can understand. Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
TigersharkBAS Posted August 21, 2014 Posted August 21, 2014 Since you are planning to use it for output I would keep things simple and stick with USB serial comms and bridge software. I don't see why your mega can't handle this. Wish I could help more :-( [sIGPIC][/sIGPIC] Creator of: F-18C VFA-195 "Dambusters" 1998 CAG Livery https://forums.eagle.ru/showthread.php?t=213788 F-18C VFA-195 "Dambusters" July 2001 CAG Livery https://forums.eagle.ru/showthread.php?t=215950 Pilot avatars for DCS Logbook https://forums.eagle.ru/showthread.php?t=221160 How to make a DCS A-10C Panel http://forums.eagle.ru/showthread.php?t=65998
doveman Posted August 21, 2014 Author Posted August 21, 2014 Since you are planning to use it for output I would keep things simple and stick with USB serial comms and bridge software. I don't see why your mega can't handle this. Wish I could help more :-( You may well be right. Maybe the advantages of using Ethernet are more for panels with both input and output and for simple output for a stick, USB will suffice. The Megas weren't particularly expensive, so I'm not totally averse to using one for the stick (and maybe using the spare inputs for a panel) but it might be more sensible to use something much cheaper, like a ATtiny2313 and save the Mega for where it's really needed. I've already got them though and I'm not using them for anything else at the moment, so I might as well use one for the stick for now and think about changing it later, when I get round to building my panels. Anyway, I'll have a play with the code and see if I can get anything out of it :) Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
Sokol1_br Posted August 22, 2014 Posted August 22, 2014 Another thing to be mindful is that simFFB only allows for assigning a trim button from those on the FFB joystick, so if I wanted to use that (which I'm not sure about at the moment), I'd either need to add an extra button to the F16 stick which is wired to the FFB2 board, or disconnect one of the F16 buttons from it's matrix and wire it directly to the FFB2 board, assuming that won't mess up the matrix and stop it working that is. :) Joystick buttons are a NC circuits - only work when you press then. So you can unplug one from F16FCS grip matrix and hook in MSFF2 USB board, as need. Sokol1
doveman Posted August 22, 2014 Author Posted August 22, 2014 Joystick buttons are a NC circuits - only work when you press then. So you can unplug one from F16FCS grip matrix and hook in MSFF2 USB board, as need. Sokol1 That's great. Thanks for the info. Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
Hempstead Posted August 23, 2014 Posted August 23, 2014 AFAIK, F16 FLCS's stick electronics is similar to Cougar and Warthog, just a bit older and slower version. Hempstick should work right out of the box. And you get 14bit instead of Mega's 10 bit. Also, you get 1ms USB report rate, i.e extremely low latency. That is, you turn a game port stick into a state of the art joystick. Just follow the instructions for Cougar and it should work.
doveman Posted August 23, 2014 Author Posted August 23, 2014 (edited) AFAIK, F16 FLCS's stick electronics is similar to Cougar and Warthog, just a bit older and slower version. Hempstick should work right out of the box. And you get 14bit instead of Mega's 10 bit. Also, you get 1ms USB report rate, i.e extremely low latency. That is, you turn a game port stick into a state of the art joystick. Just follow the instructions for Cougar and it should work. I very much like what you've done with the Hempstick and it certainly makes sense to use an interrupt-driven system rather than loop polling. However, I'll only be using the switches from the F16 stick, as the FFB2 needs to handle the pots so that the FFB works, so I'm not there'd be any real-world benefit in using the Hempstick just for that. I can get an Arduino Due for as little as £12 (or £15 from the UK) http://www.ebay.co.uk/itm/DUE-R3-Board-SAM3X8E-32-bit-ARM-Cortex-M3-Control-Board-Module-For-Arduino-Z-/201105636770?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item2ed2d47da2 so the cost of buying another board isn't really a factor but if I can use a smaller board, maybe one of the Pro Micros I already have (I'm only using the Mega for testing and don't intend to use it for the long-term unless I have to), then it might help with the layout and keeping things tidy in the box I'll need to build to hold the electronics and motors. Having said that, if I find I need to buy another board for this project (i.e. the Pro Micro isn't suitable and I don't want to use the Mega), then it would probably make sense to buy an Arduino Due and build a Hempstick rather than spend about the same on a Teensy 2.0, so I may do that. EDIT: I note you say that a separate programmer/debugger is required for the Arduino Due, which cost quite a bit and would make it too expensive for me, for this project at least. I can't really get my head round an Ardunio board that can't be programmed via USB like all the others and sites selling them, like Sparkfun, don't appear to mention this important limitation https://www.sparkfun.com/products/11589 but if that is the case, then it would be cheaper to use the SAM4S XPLAINED Pro instead but they seem to cost about £30, which is really more than I'm aiming to spend and there don't seem to be any cheap Chinese clones on e-bay. Edited August 23, 2014 by doveman Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
Hempstead Posted August 23, 2014 Posted August 23, 2014 I note you say that a separate programmer/debugger is required for the Arduino Due, which cost quite a bit and would make it too expensive for me, for this project at least. I can't really get my head round an Ardunio board that can't be programmed via USB like all the others and sites selling them, like Sparkfun, don't appear to mention this important limitation https://www.sparkfun.com/products/11589 but if that is the case, then it would be cheaper to use the SAM4S XPLAINED Pro instead but they seem to cost about £30, which is really more than I'm aiming to spend and there don't seem to be any cheap Chinese clones on e-bay. Arduino Due/X does have an atmega programmed for Arduino debugging/programming on board. So, if you use it with Arduino IDE, you don't need to buy a separate programmer/debugger. It's just that we can't use this "debugger/programmer" with Atmel Studio, Atmel doesn't support this one. But Arduino folx are graceful enough to wire out the JTAG debugging pins for other debuggers. This is what ATSAM-ICE and Atmel ICE debuggers support. In other words, Arduino Due/X board can be use for both Arduino purpose and anything else, including Atmel Studio for Hempstick, unlike its older brothers. I suspect that there will not be any clone for the XPro boards, because Atmel does not sell the EDBG chip to anybody. Moreover, the cloners have very little incentives to do the XPro's small market. Also, note that Arduino Due/X's JTAG debug header is 10pin 0.5" pitch.... ATSAM-ICE does not come with 0.5" pitch header. You'd have to buy an Olimex adapter and wire for it. Atmel ICE, however is native 10 pin 0.5" pitch. And Due/X's layout has a little problem -- the 10pin 0.5" header won't go in. You'd have to cut a little plastic corner to get it in. No big deal.
doveman Posted August 26, 2014 Author Posted August 26, 2014 Arduino Due/X does have an atmega programmed for Arduino debugging/programming on board. So, if you use it with Arduino IDE, you don't need to buy a separate programmer/debugger. It's just that we can't use this "debugger/programmer" with Atmel Studio, Atmel doesn't support this one. But Arduino folx are graceful enough to wire out the JTAG debugging pins for other debuggers. This is what ATSAM-ICE and Atmel ICE debuggers support. In other words, Arduino Due/X board can be use for both Arduino purpose and anything else, including Atmel Studio for Hempstick, unlike its older brothers. Thanks for the info, I understand why the Due needs the debugger/programmer now. They do seem rather expensive though, so I would probably use an XPro board instead, to keep costs down. I'm actually wondering whether I should just keep the F-16 stick intact and wire up both the switches and pots to an Arduino or Hempstick and use it for flying planes. It rather depends on whether the pots in the F-16 stick are any good. I'm sure it's possible to replace them or even substitute hall sensors but that might be a bit beyond me. My FFB2 probably has sufficient buttons for the KA-50 or UH-1H, so I could just use the existing stick with an extension for those and switch to the F-16 stick when I want to fly planes. I'll probably still need to buy a throttle for those, which could be the TM Hog one if it's available separately or something else. Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
doveman Posted September 3, 2014 Author Posted September 3, 2014 I found this code to make the Leonardo function as a USB joystick: http://www.imaginaryindustries.com/blog/?p=80 I've tested it on my Pro Micro and it works and sends random data for testing purposes, as intended. I wonder if anyone would be able to help me adapt and merge the code written for the Teensy, to read the buttons via SPI http://forum.il2sturmovik.com/topic/1790-there-any-better-joystick-ms-sidewinder-force-feedback-2/#entry46472 with the above USB output code? In USBAPI.h, the main joystick-related code seems to be: // Joystick // Implemented in HID.cpp // The list of parameters here needs to match the implementation in HID.cpp typedef struct JoyState // Pretty self explanitory. Simple state to store all the joystick parameters { uint8_t xAxis; uint8_t yAxis; uint8_t zAxis; uint8_t xRotAxis; uint8_t yRotAxis; uint8_t zRotAxis; uint8_t throttle; uint8_t rudder; uint8_t hatSw1; uint8_t hatSw2; uint32_t buttons; // 32 general buttons } JoyState_t; class Joystick_ { public: Joystick_(); void setState(JoyState_t *joySt); }; extern Joystick_ Joystick; and in HID.cpp: // Joystick // Usage: Joystick.move(inputs go here) // // The report data format must match the one defined in the descriptor exactly // or it either won't work, or the pc will make a mess of unpacking the data // Joystick_::Joystick_() { } #define joyBytes 13 // should be equivalent to sizeof(JoyState_t) void Joystick_::setState(JoyState_t *joySt) { uint8_t data[joyBytes]; uint32_t buttonTmp; buttonTmp = joySt->buttons; data[0] = buttonTmp & 0xFF; // Break 32 bit button-state out into 4 bytes, to send over USB buttonTmp >>= 8; data[1] = buttonTmp & 0xFF; buttonTmp >>= 8; data[2] = buttonTmp & 0xFF; buttonTmp >>= 8; data[3] = buttonTmp & 0xFF; data[4] = joySt->throttle; // Throttle data[5] = joySt->rudder; // Steering data[6] = (joySt->hatSw2 << 4) | joySt->hatSw1; // Pack hat-switch states into a single byte data[7] = joySt->xAxis; // X axis data[8] = joySt->yAxis; // Y axis data[9] = joySt->zAxis; // Z axis data[10] = joySt->xRotAxis; // rX axis data[11] = joySt->yRotAxis; // rY axis data[12] = joySt->zRotAxis; // rZ axis //HID_SendReport(Report number, array of values in same order as HID descriptor, length) HID_SendReport(3, data, joyBytes); // The joystick is specified as using report 3 in the descriptor. That's where the "3" comes from } Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
lxsapper Posted September 3, 2014 Posted September 3, 2014 (edited) I just bought an old Thrustmaster F-16 FLCS to cannibalise the stick to extend my Sidewinder FFB2, something like this http://forums.eagle.ru/attachment.php?attachmentid=83931&d=1371853528 Taking it apart, I see that there's just 5 wires coming from the stick for all the hats and buttons, so it's obviously using some sort of matrix. Will it be possible to use this with my Arduino Mega and appropriate code or will I have to just disconnect the existing wiring and solder up a separate wire per switch? Very Similar! :D Edited September 3, 2014 by lxsapper
doveman Posted September 3, 2014 Author Posted September 3, 2014 Very Similar! :D Well he's using a £200+ Warthog instead of a £15 Pro Micro but apart from that ;) Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
lxsapper Posted September 4, 2014 Posted September 4, 2014 Well he's using a £200+ Warthog instead of a £15 Pro Micro but apart from that ;) "He" would be Me! :)
doveman Posted March 18, 2015 Author Posted March 18, 2015 (edited) Finally got the buttons working! I found this sketch which was adapted from the original F-16 sketch and added the analogue axis https://github.com/gerryk/USBJoystick I was only getting output from three buttons and they were each triggering loads of buttons when pressed. However, replacing the section below "void loop() {" with this: SPISettings settingsA(1000000, MSBFIRST, SPI_MODE0); SPI.beginTransaction(settingsA); digitalWrite(ss,LOW); // reading only, so data sent does not matter buttonInputs1 = SPI.transfer(0x00); buttonInputs2 = SPI.transfer(0x00); buttonInputs3 = SPI.transfer(0x00); digitalWrite(ss,HIGH); SPI.endTransaction(); got it working and now each button/hat triggers correctly. The explanation of why this was necessary (as provided by the person who kindly assisted me) is that the original Teensy SPI code emulated the slow arduino Uno performance by default. That has now been changed to 'default to as fast as possible' which in most cases is a good thing, since the SPI code is blocking (code pauses until bytes are received) so you want them complete as fast as possible. So with the updated SPI libraries we need to explicitly say 'run slow'. Edited March 18, 2015 by doveman Main rig: i5-4670k @4.4Ghz, Asus Z97-A, Scythe Kotetsu HSF, 32GB Kingston Savage 2400Mhz DDR3, 1070ti, Win 10 x64, Samsung Evo 256GB SSD (OS & Data), OCZ 480GB SSD (Games), WD 2TB and WD 3TB HDDs, 1920x1200 Dell U2412M, 1920x1080 Dell P2314T touchscreen
Sokol1_br Posted March 18, 2015 Posted March 18, 2015 A little late, but Mega_Mozg add support for Wart/Cougar/F22 shift registers in MMjoy firmware. :)
Bazooka Posted March 19, 2015 Posted March 19, 2015 OK...silly question from a nuggat....whats a Hempstick?
cichlidfan Posted March 19, 2015 Posted March 19, 2015 OK...silly question from a nuggat....whats a Hempstick? The first thing that comes to mind...is certainly not the right answer. :lol: ASUS ROG Maximus VIII Hero, i7-6700K, Noctua NH-D14 Cooler, Crucial 32GB DDR4 2133, Samsung 950 Pro NVMe 256GB, Samsung EVO 250GB & 500GB SSD, 2TB Caviar Black, Zotac GTX 1080 AMP! Extreme 8GB, Corsair HX1000i, Phillips BDM4065UC 40" 4k monitor, VX2258 TouchScreen, TIR 5 w/ProClip, TM Warthog, VKB Gladiator Pro, Saitek X56, et. al., MFG Crosswind Pedals #1199, VolairSim Pit, Rift CV1 :thumbup:
Sokol1_br Posted March 19, 2015 Posted March 19, 2015 (edited) OK...silly question from a nuggat....whats a Hempstick? A firmware for development boards Arduino Due/X and Atmel SAM4S XPLAIN Pro (~110$) that create a joystick controller with functions similar to Tm Wart/Cougar, but with 64/128 buttons. http://www.hempstick.org/The_Official_Hempstick_Site/Welcome.html Edited March 19, 2015 by Sokol1_br
T_A Posted March 19, 2015 Posted March 19, 2015 I prefer cichlidfan`s hempstick better :D IAF.Tomer My Rig: Core i7 6700K + Corsair Hydro H100i GTX Gigabyte Z170X Gaming 7,G.Skill 32GB DDR4 3000Mhz Gigabyte GTX 980 OC Samsung 840EVO 250GB + 3xCrucial 275GB in RAID 0 (1500 MB/s) Asus MG279Q | TM Warthog + Saitek Combat Pedals + TrackIR 5 [sIGPIC][/sIGPIC]
Recommended Posts