I'm trying to make a joystick. The idea is that I will get an analog input from a pot by arduino I'll send the value to visual studio via serial port and finally I have to put this value as joystick analog input to the system so I'll be able to use it in the games but I couldn't find the command to do this.
I found a command like SendKey and I tried it but the result isn't what I needed. For example if I use the SendKey.Send("a") the car in the game acts fully turned to left. I want to use the potentiometer like an analog stick. If I turn the pot half way, the steering wheel will turn half way.
I think it would be definitely a better idea to implement a HID joystick profile instead handling serial data and create a virtual joystick in windows via C#. But if it is very important for you to have a virtual joystick check the vJoy project.
As I mentioned above, I would implement a HID Joystick profile. You can do that in many ways and it is not complicated at all.
For example use a Arduino board that have a native supports of joystick HID profile (such as the Teensy Boards), use a Arduino which you can modify to use a Joystick library (e.g. USBAPI) (like the Arduino Leonardo boards, instructions see here), or use a compatible bluetooth module with HID firmware, such as the RN42 HID from Sparkfun. There are several example codes for that application in the web.
Related
I have a USB microscope camera and I would like to open the Windows 10 camera app automatically if the camera gets connected to a USB port. After checking that this isn't possible with Windows 10 at the settings level, I have decided to write a short C# program that monitors the USB ports for a camera device connection (and runs the camera display app).
As to the monitoring I haven't got a slightest clue where to begin. Needless to say that the monitoring program should be lean with respect to blocking ressources, because it would be running all the time. Can I simply obtain an event notification of USB connection? Do I have to expect problems with permissions?
And of course, suggestions for alternative approaches are welcome, if any. Note that I do not want to capture and display video from the camera myself, unless it is easier to do it that way instead of opening the existing camera app.
assuming the microscope is using the web-camera interface I would look for guides about how to enumerate and connect to web-cameras. I have found a few alternatives:
Media capture API
Aforge
Versatile WebCam
I had most success with versatile webcam, but if you just want to enumerate devices any of them should do. Aforge is probably the easiest to use.
You can then use a timer to check for devices, and do something if the microscope is connected.
If the microscope is not a webcamera you will need to refer to the camera documentation on how to enumerate devices.
I'm creating an Alt-Tab pedal with an Arduino. The idea is that the user will just press down on a pedal that will hit a button on the Arduino, and this would be the equivalent of hitting the ALT+TAB key (thereby allowing you to stealthily switch windows).
I'm also open to just minimizing the window.
The problem is, I'm not really sure how to go about this. Should I use a command that runs a batch file? Is there a command in C I can implement this with? I'm open to any suggestions.
SendKeys.Send("%{TAB}");
Or use SendInput() in a C program.
Based on the other answers, it sounds like you’re proposing to have the Arduino connected to the computer with USB and send a letter when the pedal is pushed, then have a program on the computer side receive that message and invoke Alt-Tab.
There’s a different way to do this: Teensy 2.0 is an Arduino variant based on the ATmega32U4 microcontroller. This is an AVR chip that has built-in USB support, instead of a serial port that’s translated to USB with a USB-serial bridge as you’ll find on an Arduino.
One of the features is that it can actually emulate a USB keyboard. You can plug it into a computer and have it send Alt-Tab on a pedal press without writing any software on the computer side, and it will work anywhere.
See this tutorial: http://blog.makezine.com/archive/2011/04/the-awesome-button.html
Basically, it uses an "Easy Button" (you'd use the pedal) to enter a pre-set keyboard character or characters (Alt-Tab in your case) through a USB port. It should have everything you need to figure out your project.
The Teensy++ is smaller and cheaper than an Arduino and can be hidden in your pedal box, tidy as can be. A program to do what you desire would take less time than installing the Teensyduino software into the Arduino environment. I think it is the bomb, particularly for keyboard and MIDI stuff (you could make a pedal for "Start Song" or the all important "All Notes Off").
http://pjrc.com/store/teensy.html
http://pjrc.com/teensy/td_keyboard.html
There are several recipes in Arduino Cookbook related to using an Arduino to emulate a mouse and/or keyboard.
I want to try add a simple slider (something like throtle on joysticks) to my computer.
The hardware part shouldn't be a problem as I can almost do anything about it. It only comes down to having some kind of driver for it.
What I have at the moment is a microcontroller and a potentiometer, which by turning the potentiometer I can transfer values between 0 and 254 to the RS232 of PC. Is this enough from hardware point of view?
Would be nice if you can give me some tips about where to look for info, what to do, and in the best case some code snippets.
So what I am looking for is to be able to present my hardware to windows as a GAMEPAD or JOYSTICK.
Thanks
The gamepad and joystick you mention are likely HID devices (if they are natively being recognized as such) - gamecontroller
Here's some information on the gamecontroller HID class
http://msdn.microsoft.com/en-us/windows/hardware/gg487464
You will need to develop a HID emulator driver which either
identifies (via some sort of unique
id obtained from querying the serial
port hardware)
or is configured as
one of the device types you mention
(gamecontroller).
You then need to translate the values coming in over the serial port to the appropriate values for the HID class you are emulating.
Here's an example in python of a HID emulation driver
http://code.google.com/p/hidemulator/
Here's a c++ example
http://examples.oreilly.de/english_examples//9780735618039/cd_contents/Samples/Chap13/hidfake/hidfake.htm
You can try to look at SerialPort class.
The most useful event is DataReceived.
Sorry that I didn't get the exact question you asked. I just used this class in my project and felt a little excited about it. I hope someone else can give you a better answer.
I learned recently how PS2 game controllers send continuous updates to the PS2, with data identifying which buttons have been pressed, etc.
Having an adapter that allows my PS2 game controller to connect to a USB port, I started looking into writing a driver to allow it to control the mouse (similar to Joy2Mouse (http://atzitznet.no-ip.org/Joy2Mouse3/) ), as an exercise in understanding how it works.
I am having trouble even grasping the basics of how to access and asynchronously poll a USB device for input, and was wondering if anyone had any example code (C#) for accessing the USB device and polling its input, or could explain how it is done?
From what I can gather, I will need to use some windows drivers for accessing the USB device, but I have no experience of this, and so don't know how to do this.
Thanks for any help you can give.
Those PS2 adapters interface with the controller for you, and provide a joystick interface for you.
There are a few ways of accessing a joystick. An older method (but still works) is by using Managed DirectX. http://www.codeproject.com/KB/directx/joystick.aspx
Note that Managed DirectX is no longer released. You might try SlimDX (http://slimdx.org/features.php)
I am working on a personal project involving sending simple signals from my computer to a circuit via USB. Basically I am using the USB signal as the gate signal for a MOSFET which will in turn activate a relay to turn on/off various AC peripherals. For example if I want to turn on a light bulb for 5 seconds every minute I would be sending a 1 down the first wire for the first 5 seconds of every minute.
This is my problem: I have no idea how to manually send a 0/1 down a specific wire on a USB cable, or even interact with a USB port at all :(
So I guess there are multiple parts to this question, is it possible to interact directly with the bits being sent via a USB port? If so how would I do this? I am familiar with C++ and C#, so I really hope that you can do it in one of those...
Thanks!
edit Hmm so it looks like the USB port actually only has one 5V pin so direct USB interaction wont work. Going to take a look at a parallel adapter and get back on it.
USB is a bad fit for anything that doesn't have a USB interface at the other end of the wire. If you don't want to get into building your own USB device, I'd suggest buying a USB to serial adapter, which gives you two directly-controllable output lines (the flow control lines), or a USB to parallel adapter, which gives you more than 8 lines.
Chris Johnson's answer has a link to instructions for Windows serial port programming. You'll want to look at section 7 -- the SETDTR, CLRDTR, SETRTS, and CLRRTS are your flow control line toggles (for the DTR and RTS lines, respectively).
As far as hardware goes, a "1" (SET) value on a flow control line is +3 to +15 volts on the line, and a "0" is -3 to -15. Actual voltages can vary between devices; measure it to be sure. (EDITED; I got the 1 and 0 mixed up. The control lines use the opposite convention from the data lines.)
Here are Wikipedia pages for voltage characteristics and pinouts.
EDIT: Having done some more research on USB-to-parallel adapters, I don't think they will give the needed level of control. For best results, you'll need a PCI or PCMCIA parallel card, or a parallel port built into the motherboard.
I'm not a Windows programmer, but this library might be useful for controlling the parallel port's lines from Windows.
The easiest thing to do for this application is to use serial port emulation, either with a USB-Serial cable, or with a USB-Serial converter chip (e.g. the FTDI FT232) in your hardware device.
Either way, this allows you to interact with your USB device as you would a serial port (see, e.g. here for how to do this in C++ in Windows)
Much like Chris suggested, you can get a USB slave device from FTDI. $27 at digikey will get you a small board with all the fine wiring already done.
However, for your purposes the bit-banging mode described on page 39 of the datasheet would be much better than the UART mode (UARTs generate pulses at several kilohertz, you want to have the voltage stay at the level you set it to).
Hopefully your MOSFET will turn on with a 3V signal since the FTDI will put out approximately 3.1-3.2V for a high output.
Also, make sure you use the latest drivers from FTDI... a couple years ago they had drivers (WHQL-certified even) that caused frequent BSOD, and I've often found that driver CDs that come with hardware are several years out of date.
I built something very similar to what you are doing (I was running a car window motor from a usb device, used a mossfet H bridge (the HDR1X8 on the diagram) to drive the motor.). You need a USB to I/O device this is what I used (I got a U421, they fit perfectly over the center line of a breadboard, the 401 works well with breadboards too if you don't have a split one.
They give you a dll and you just link in to it with your code. its just as simple as making a call to WriteA and WriteB for writing out to your mosfet device. Be warned logic level lines are not meant to drive current so you will need to hook this up to a transistor if you expect any kind of medium to large current flow. See App1 in the application notes of the menu on the usbmicro site to see the proper way to hook it up.
Use a USB prototype board. It usually comes with a software SDK.
Check out these links from my web site:
1.You can use a usb to serial converter. All you need to know is here
2.You can use programming to access the usb directly but for this one you have to have a driver already installed for you device. Details are here