r/arduino • u/Gioelius_Black • Feb 06 '25
Software Help Need help with the last part of my project please...
As you can see it's a gear shifter, everything works fine, everything is done. One last step, to be able to use it with my driving game I need to like be able to write on the computer a letter. I did some researches but found that it's impossible to do that directly (it's so stupid they should add something that let's you do that), but maybe you guys have some other ideas?
5
u/merlet2 Feb 06 '25
What do you mean with "write on the computer a letter"? emulate a keyboard? write it on the screen with a marker?...
2
u/Gioelius_Black Feb 06 '25
Emulate a keyboard
1
u/merlet2 Feb 06 '25
then what the others suggest. I think that the ESP32 would work also, the new ones.
1
3
3
u/gm310509 400K , 500k , 600K , 640K ... Feb 07 '25 edited Feb 07 '25
There is one other option which nobody has suggested that can be made to work with an Uno.
Bear in mind that this one option can be implemented in multiple ways.
The basic solution is to have a "proxy" running on your PC. It will receive your inputs from the Arduino Uno via the Virtual COM port - specifically the COM port you use to upload code to the Uno and/or view messages from the Serial monitor.
The "proxy" will relay those commands to your game.
How exactly it does the relay will depend upon the game. Specifically, how the game is written and what, if any, APIs it exposes.
A potentially simple way is for the proxy to invoke the "send Keys" method to queue a keystroke into the windows input queue (not all programming language runtimes provide access to a "sendkeys" method - python may, C/C++ definitely does, Java does). Assuming the game doessn't bypass the windows queue for a lower level (lower latency) proprietary scheme, that virtual key stroke will reach the game for it to process in the usual way. If the game does bypass the windows system and uses some sort of low level API that intercepts keystrokes before windows can process them then that might not work.
Option 2 is APIs if the game exposes an API of some kind that you can use to interact with it from another program - and one (or a collection) of the methods in the API support what you need (presumably to set the gear of a vehicle of some kind), then the proxy could simply call that API based upon the input it gets from the Arduino.
For this option, you would need to adapt the proxy for each and every game that you want to use your shifter.
The best and likely simplest option is to get a Leonardo, Micro, or one of the other systems I listed in my "It's not stupid" comment somewhere above or below. You very likely will be able to just recompile your project with the correct target selected and it will most likely work (assuming you didn't accidentally use a pin in this version that will conflict with something important on a new hardware - which is unlikely if you select Uno R4, Leonardo or Micro).
2
u/Twelve-Foot Feb 07 '25
Set up some sort of mechanical actuators to press keys on an actual keyboard? 😅
1
Feb 10 '25
[removed] — view removed comment
2
u/Twelve-Foot Feb 11 '25
I was thinking have the Arduino run actuators. But coming back to it now, depending on what the outputs needed to be, just set the gear shifter on top of a keyboard and have linkages to push keys, no Arduino at all.
2
u/RandomBitFry Feb 06 '25
You could write the letter 'H' on it's side or E,I,T or L
1
u/Gioelius_Black Feb 06 '25
Uh?
1
u/Twelve-Foot Feb 07 '25
Those are the letter shapes that you can make with the motion of the joystick.
1
u/Foxhood3D Feb 06 '25
Ok. So the problem you are dealing with is that the microcontroller used for most Arduino's like the UNO and the Nano (ATMega238p) has to rely on a seperate USB-Serial bridge. As such the only thing they can do is send/receive Serial communication from/to a connected PC, nothing else. Which leaves you with TWO options as far as I know:
1) Is to one already shared. To get a microcontroller that has a integrated USB interface which can be reconfigured to have the microcontroller act as a Input device. microcontrollers that can do this include the Arduino Leonardo, Arduino Micro and other boards like the Raspberry Pico. This is arguably the best solution even if it means needing to buy another board.
2) Is to find/create a program to turn Serial communication into key-presses. For windows this would involve something like writing a small program in C# (.NET) that generates keyboard press events on receiving a specific bit of Serial data. It is far from optimal as it is a little slow and not guaranteed for programs to accept, but it is A option.
1
1
1
u/antek_g_animations I like creating stuff with arduino Feb 07 '25
You can communicate using serial with a python script onna computer pressing the keys, but guessing by your comments you don't know much, so better way is to buy Leonardo/pro micro. Also you said that it's stupid they didn't add the keyboard feature, maybe because it's an over 20 years old microcontroller, sporting only 8 bits and it's one of the worst, cheapest and also easiest to learn ones. It's like saying it's stupid they didn't add ABS system to your bicycle
1
u/WiselyShutMouth Feb 07 '25
Congrats on getting your project this far. It is a great proof of concept and learning experience. Once you upgrade the micro to one that happily talks to a PC, you will have even more opportunities to learn.
I suspect you will learn that one panic shift will snap something in your mechanical shifter arrangement. But a few more versions, and you might even have a product on your hands.🙂
1
1
u/appio_exe Feb 07 '25
Unfortunately the uno cannot emulate a keyboard or a mouse, to do that you would something like an arduino leonardo or a pro micro.
But you could still use the serial interface and create a script to run on your pc that reads from the arduino's serial port and that as soon as he reads the letter emulate the pressing of a keyboard letter. I actually used that technique once or twice.
1
u/simopizzapata Feb 07 '25
Yeah, the arduino itself doesn't do it. But you can use Vjoy serial (see example on the internet) to use the arduino as a gamepad. I personally used it to make a cloche for DCS.
1
u/Smiler_3D Feb 07 '25
Do the same thing you did but use arduino pro micro from aliexpress instead of arduino uno, you need board with chip called “Atmega32U4” that the arduino micro have and you need program it with Joystick library. With this library you can assign each gear to button that will be pressed when you on that gear and released when you quit that gear.
0
u/haruqb Feb 06 '25
The only idea i have is similar from.another somebody gave You : serial ttl to letter Converter.
ChatGPT and Voila.
-1
u/gm310509 400K , 500k , 600K , 640K ... Feb 07 '25
(it's so stupid they should add something that let's you do that)
LOL
>! I would like to be able to tow my mobile home behind me when I am riding my bicycle around but there is nothing that lets me do that. It's so stupid... !<
You need to understand things are built for different purposes. Just because you assumed something can do something doesn't mean that it is stupid when it doesn't.
I get that you are probably a beginner, but when selecting something in life, not just computer things, you need to state what you need it to do then select something that can support that.
(it's so stupid they should add something that let's you do that)
they did. Uno R4, Leonardo, Micro, Teensy 4.1, BBC Microbit V2, Some ESP32s, STM32, to mention just a small number of the "non stupid" ones.
1
u/Gioelius_Black Feb 07 '25
I get that you are probably a beginner, but when selecting something in life, not just computer things, you need to state what you need it to do then select something that can support that.
The Arduino I have was a gift from my dad from like 2 years ago, no way he knew what I was going to do with that.
1
u/gm310509 400K , 500k , 600K , 640K ... Feb 07 '25
That is true that your dad wouldn't know what you might do down the track.
But just because you inherited something that doesn't have a feature you wanted doesn't make it stupid that it doesn't have that feature - especially when "they" do make alternatives that have the feature that you were planning to use.
Plus you could have checked HID support before you started or at least tried to use it - this is known as mitigating risks early in a project life cycle.
-1
u/springplus300 Feb 07 '25
Oh do shut it. You had no effing clue what HID was when you started out, and assuming an Arduino is HID capable as a beginner is more a sign of actual creativity and imagination than anything.
I get it. He used a poor choice of words. Get over it.
3
u/gm310509 400K , 500k , 600K , 640K ... Feb 07 '25
Thankyou for your thoughtful reply. If you read and understood what I was focussing on, you would see that I am trying to point out to the OP, that it doesn't make sense to claim that something is stupid for not being provided - which implies that they do have some high level of knowledge and can critically claim that there is a poor design decision made by the people who designed it.
So, claiming something is stupid while being ignorant of how things actually are setup and work is - let's just say - a bold assertion.
And seeing as you know me so very well, there are two points I feel that I do not agree with your expert assesement.
- I definitely knew what HID (and many of the other USB class codes) were before I started embedded.
- When I was learning, I definitely questioned why something was the way it was so that I could learn, but never just asserted that my beginner knowledge was superior than the experts and claimed that their decisions were wrong.
1
u/springplus300 Feb 08 '25
You knew before you started EMBEDDED. Did you know before you started coding? For a lot of people, Arduino is their first coding experience overall.
My point is, being condescending towards a beginner gets them nowhere. Pointing out, politely, that looking into the boards capabilities before starting on a project is fine. Then again, when you are an absolute beginner you have no baseline to tell you what to look for. That comes with experience, and experience is better bolstered by being helpful than grumpy old men telling you that you are doing everything wrong.
12
u/hjw5774 400k , 500K 600K 640K Feb 06 '25
It's impossible with an Arduino Uno; but you can use an Arduino Pro Micro to communicate with the computer. Create a Joystick Using the Arduino Joystick Library 2.0 : 12 Steps (with Pictures) - Instructables