First video of yours I've seen. I really appreciated the code-along-with-me explanation of what you were doing. Also, your explanation of bitwise operations and using a single integer to represent any combination of buttons was superb.
i wired the buttons and joystick to the correct pins, used the right capacators for other stuff on the board but all i get in the serial monitor is an infinate stream of backwards question marks from the arduino. i have checked and double checked, there are no coding/spelling/wiring problems, please help
Aaaal fiiiin encuentro un video con todo lo necesario para usar el joystick shield como Gamepad!!!! Me he roto la cabeza tratando de lograr usarlo como un periférico pero no encontraba la manera y nunca se me ocurrió hacer un programa en Python (no se usarlo la verdad😅😅😅😅) you are brilliant!!!
Hi i'm tried the coding of arduino and worked just fine but the code of python it won't work. It release the mesage: Exception has occurred: ModuleNotFoundError No module named 'imp' File "\Funduino-JoyStick\Funduino-JoyStick.py", line 1, in import serial ModuleNotFoundError: No module named 'imp' i already instaled the serial and pyautogui libraries. i'm using the Visual Studio Code with the version 3.12 of python on windows 10. it's like it doesn't understand that it has to import the libraries and only read "imp" (that's what i understand of the error message). I have the program sublime text but i don know how to run it in tha program. if you can give me a hand to make it work i wil be really grateful. sorry for the writing i'm not use to write in english, hope its understand
Right, after many hours (damn Python 3 updates throwing the coding off!) I have got my joystick working - my only problem is that it I cannot hold down the joystick. It only registers each direction input once. The readout on the Serial port is fine, the numbers are staying high if the joystick is pressed. But the python code seems to only allow a single press. It looks like this happens in the video at 11:22. Can you help?
Fixed, I just removed the line: "if key not in keysDown:". Otherwise once the key has been pressed and is added to KeysDown, the "pyautogui.keyDown(key)" will not run again, and the button will not be pressed again. I'll leave this here in case anyone has the same issue.
for the first line I'm getting this error: arduino = serial.Serial('/dev/cu.usbmodem1461', 115200, timeout=.1) AttributeError: module 'serial' has no attribute 'Serial' Any idea why? For those looking for the answer to this question, the solution was to change the line from the above to the following: arduino = serial.Serial(port = 'COM3', baudrate = 115200, timeout = 0.1)
My son really wants to start doing exactly this kind of thing. He's been getting into python, but we've never done anything with an Arduino. If we were to try to follow along with this video, could you give me links to things I would need to have?
Chris Huff Awesome! Sure thing - if you already have python up and running, what you’ll need to do is to download the Arduino IDE from their website www.arduino.cc . Get an Arduino Uno microcontroller and the joystick shield (perhaps you have an electronics store around your area that sells them both). That’s it! If you’d like to see the source code I wrote, both the arduino and python code is available on github github.com/mattiasjahnke/arduino-projects/tree/master/arduino-pc-joystick
Are there like different types of arduinos ? Cause I never used one before and I want to try it , but idk what I need , should I like just look for an arduino ? Or is there a specific type that I need for this. And also , how to setup the buttons and joysticks and stuff on the arduino ?
Yeah there are different kinds of Arduinos. This particular one is called ”Arduino UNO”, a very common type. The buttons/joystick are attached to a module called a ”shield” (which you buy fully assembled, all u need to do is to stick it on top of the UNO)
So I uploaded the Arduino code onto my board but I do not understand how to put the python on. When I copied the code you wrote onto python, it said that there were a ton of errors. Can someone explain
Ninjaitsu thanks! What I’m doing there is parsing the data coming off the serial. I’m starting to look for an S, so that a I know I’m in the beginning of a message. Then I read another string until I find a comma and make that in to an integer - that will be my dx. Then the same thing for dy. Did that explain it?
Im working with python 3.9.13, not sure which version of your python and serial is working on but i kept getting the error "ValueError: invalid literal for int() with base 10" after some research i figure out they might have change the output value to binary instead of just string, which may explains the reason why its impossible to convert to int or float Since the video had been made a long time now I don't think you would be replying to my comment anytime soon, however this is just to warn any python3.9 or future watcher about this issue. Unfortunately I still wasnt able to find the solution to this yet. I will be appreciated if anyone can give any possible solution to this one, thank you
Can you explain what steps you do before the import serial to be able to work your Arduino on Sublime Text? Im trying to copy what you are doing but I cant import the Arduino environment into Sublime Text.
Nicolas Franco In sublime I’m programming a python script. The python script ”talks” to the Arduino by connecting to the serial port (on which Arduino is connected and will write). So there’s nothing Arduino going on within sublime text, pure python
@@engineerish yes when I reached. The x analogReading (x_pin) Error wasn't declared I'm using arduino the latest It might be the program it self But. The port and everything is ok If i erase the x analogReading it will work
Can i ask if u put ur own sketches so. I. Will just copy paste Hehehehe I will appreciate that from u That will help me to much Coz i spent 20 hours just to figure it out then i gave up I became a zombie now
PRINCEof ARAB don’t quite understand what’s not declared.. the function call or the variable? Source code is available (I guess that’s what you’re referring to) so copy and paste all you want ;)
python code not working at me. no errors, but simply not working. please answer quick, need this for my informatics project in school. (sry for bad english im from Germany)
So try figuring out where the problem is; if you print to the console (in the python script) do you receive data from the arduino? If you run the serial monitor in the arduino ide, do you see any output?
Ok, so it sounds like the python code can’t connect to the serial port. 1) make sure again you have the right port name. 2) make sure you are not running the serial monitor at the same time (because then the port will be busy) 3) try getting a simpler example to work (follow a tutorial or something and get a proof of concept up and running) and see if there’s any learnings you can draw from that. Given that so many people run in to this problem, I should probably add some error handling and troubleshooting to the script
Hey I tried to get it to work, but my macbook isn't picking up on the inputs from the joystick shield. I copied the code from the link to the source code
@@curlybighead1111 On the line with '/dev/cu.usbmodem1461' - make sure that that serial port corresponds with your Arduino. You can see what yours is called by going in to the Arduino IDE -> Tools -> Port
curlybighead do you see data in the serial monitor in the arduino ide? Close down the serial monitor (since otherwize it will be hogging the serial port) and run the python script - try to just dump the data from the stream to the console in python - it should be the exact same thing as the serial monitor in the IDE
I'm wondering the same thing, I'm thinking of running the python script when launching EmulationStation to map the buttons to the keyboard then use those in the RetroPi controller configuration
The remove the last ([:-1]) and the two last ([:-2]) characters from a string in Python. stackoverflow.com/questions/15478127/remove-final-character-from-string
I don't know why but when I run the python script I don't get any results. I already uploaded the arduino code. Please reply fast. I think the python code is not working
Thorbjørn Hellehaven sure - that’s a way to do it. My way of looking at it is that this makes customization and mapping of keys a lot easier. Being able to quickly change a python script rather than having to reprogram the usb, upload c code and reprogram again. But either way would do it!
Congrats for your video, its really helpfull! I am thinking of applying this to control Recalbox on Raspberry Pi through bluetooth (HC05), but was unable to find the format I should be passing the data. Do you know if the bit operation you described would work?
Thanks! Cool! The format I used in this video was just a protocol I came up with during development - in order to get it to work with Recalbox, you'd probably have to adhere to their protocol. Good luck!
First video of yours I've seen. I really appreciated the code-along-with-me explanation of what you were doing. Also, your explanation of bitwise operations and using a single integer to represent any combination of buttons was superb.
David Beukes thank you! Glad you liked it 🙌
Finally an arduino project that is not only cool but also useful! !!! Thank you. I will definitely try this.
Great one day project! Will try it soon!
How did it go?
@@vuk_ustipak pretty well actually
i wired the buttons and joystick to the correct pins, used the right capacators for other stuff on the board but all i get in the serial monitor is an infinate stream of backwards question marks from the arduino. i have checked and double checked, there are no coding/spelling/wiring problems, please help
Portaboy7921 hade you set the baud rate to 115200 in the serial monitor?
Once uploaded to board, will the joystick show up on the the windows USB controllers calibration window.
win11 H
Aaaal fiiiin encuentro un video con todo lo necesario para usar el joystick shield como Gamepad!!!! Me he roto la cabeza tratando de lograr usarlo como un periférico pero no encontraba la manera y nunca se me ocurrió hacer un programa en Python (no se usarlo la verdad😅😅😅😅) you are brilliant!!!
Hi i'm tried the coding of arduino and worked just fine but the code of python it won't work. It release the mesage:
Exception has occurred: ModuleNotFoundError
No module named 'imp'
File "\Funduino-JoyStick\Funduino-JoyStick.py", line 1, in
import serial
ModuleNotFoundError: No module named 'imp'
i already instaled the serial and pyautogui libraries. i'm using the Visual Studio Code with the version 3.12 of python on windows 10. it's like it doesn't understand that it has to import the libraries and only read "imp" (that's what i understand of the error message).
I have the program sublime text but i don know how to run it in tha program. if you can give me a hand to make it work i wil be really grateful. sorry for the writing i'm not use to write in english, hope its understand
wouldnt it have been easier to use the keyboard library and let the arduino work as a keyboard?
Franklin Rosales sure that’s another way of doing it - this gave me the ability to reprogram it in python rather than fiddling with arduino code
Right, after many hours (damn Python 3 updates throwing the coding off!) I have got my joystick working - my only problem is that it I cannot hold down the joystick. It only registers each direction input once. The readout on the Serial port is fine, the numbers are staying high if the joystick is pressed. But the python code seems to only allow a single press. It looks like this happens in the video at 11:22. Can you help?
Fixed, I just removed the line: "if key not in keysDown:". Otherwise once the key has been pressed and is added to KeysDown, the "pyautogui.keyDown(key)" will not run again, and the button will not be pressed again. I'll leave this here in case anyone has the same issue.
Can you make a project like this but make a case of it? Like put the Arduino inside a 3d printed case or make it out of a different material...
Great job, might this work if I connected my atemga 328 with an ft232rl as a usb adaptor(as the chip doesn't have a usb built-in)??
sir pls help me i have uploaded all your code and also it is not showing any error but i cannot use my funduino joystick shield, pls help
for the first line I'm getting this error:
arduino = serial.Serial('/dev/cu.usbmodem1461', 115200, timeout=.1)
AttributeError: module 'serial' has no attribute 'Serial'
Any idea why?
For those looking for the answer to this question, the solution was to change the line from the above to the following:
arduino = serial.Serial(port = 'COM3', baudrate = 115200, timeout = 0.1)
Hi, how did you find the answer? it doesnt work for me
@@matiassilvera7011 I don’t recall. Probably brute force plug and chug. Sorry.
@@matiassilvera7011 check your port name
My son really wants to start doing exactly this kind of thing. He's been getting into python, but we've never done anything with an Arduino. If we were to try to follow along with this video, could you give me links to things I would need to have?
Chris Huff Awesome! Sure thing - if you already have python up and running, what you’ll need to do is to download the Arduino IDE from their website www.arduino.cc . Get an Arduino Uno microcontroller and the joystick shield (perhaps you have an electronics store around your area that sells them both). That’s it! If you’d like to see the source code I wrote, both the arduino and python code is available on github github.com/mattiasjahnke/arduino-projects/tree/master/arduino-pc-joystick
@@engineerish Thanks!
Would pressing B+F be the same as C+E since they both equal 6??
Are there like different types of arduinos ? Cause I never used one before and I want to try it , but idk what I need , should I like just look for an arduino ? Or is there a specific type that I need for this. And also , how to setup the buttons and joysticks and stuff on the arduino ?
Yeah there are different kinds of Arduinos. This particular one is called ”Arduino UNO”, a very common type. The buttons/joystick are attached to a module called a ”shield” (which you buy fully assembled, all u need to do is to stick it on top of the UNO)
Great VIdeo
Is there a Way to use it connecting a HC-05 or something like that?
Thank you
Same query
Did u find a soln?
So I uploaded the Arduino code onto my board but I do not understand how to put the python on. When I copied the code you wrote onto python, it said that there were a ton of errors. Can someone explain
bro i didn't understand about changing the port name
Awesome video and really helpful! But could you explain what you did in 8:38 - 8:50?
Ninjaitsu thanks! What I’m doing there is parsing the data coming off the serial. I’m starting to look for an S, so that a I know I’m in the beginning of a message. Then I read another string until I find a comma and make that in to an integer - that will be my dx. Then the same thing for dy. Did that explain it?
Im working with python 3.9.13, not sure which version of your python and serial is working on but
i kept getting the error "ValueError: invalid literal for int() with base 10"
after some research i figure out they might have change the output value to binary instead of just string, which may explains the reason why its impossible to convert to int or float
Since the video had been made a long time now I don't think you would be replying to my comment anytime soon, however this is just to warn any python3.9 or future watcher about this issue. Unfortunately I still wasnt able to find the solution to this yet. I will be appreciated if anyone can give any possible solution to this one, thank you
Update(solved) : just add a b behind the ',' , it works like a charmed
The value is red as binary, so it must be read in b form
Can you explain what steps you do before the import serial to be able to work your Arduino on Sublime Text? Im trying to copy what you are doing but I cant import the Arduino environment into Sublime Text.
Nicolas Franco In sublime I’m programming a python script. The python script ”talks” to the Arduino by connecting to the serial port (on which Arduino is connected and will write). So there’s nothing Arduino going on within sublime text, pure python
When i reached the analog reading its appeared wasn't declared
If i ears it it will work
Can u help me
PRINCEof ARAB hi, what’s not declared? arduino.read()?
@@engineerish yes when I reached. The x analogReading (x_pin)
Error wasn't declared
I'm using arduino the latest
It might be the program it self
But. The port and everything is ok
If i erase the x analogReading it will work
Can i ask if u put ur own sketches so. I. Will just copy paste Hehehehe
I will appreciate that from u
That will help me to much
Coz i spent 20 hours just to figure it out then i gave up
I became a zombie now
PRINCEof ARAB don’t quite understand what’s not declared.. the function call or the variable? Source code is available (I guess that’s what you’re referring to) so copy and paste all you want ;)
Please sir you gave the code source
But not your own code
Is there a way to use it with smartphones?
I don't think so , cause the pyautogui library doesn't work for mobile
python code not working at me. no errors, but simply not working. please answer quick, need this for my informatics project in school. (sry for bad english im from Germany)
Johannes Krempels most likely it’s the port name that needs to be changed
I changed the Port already, still doesnt work
So try figuring out where the problem is; if you print to the console (in the python script) do you receive data from the arduino? If you run the serial monitor in the arduino ide, do you see any output?
engineerish in the arduino ide the serial Monitor Works Great, but in the Python console i dont see anything.
Ok, so it sounds like the python code can’t connect to the serial port. 1) make sure again you have the right port name. 2) make sure you are not running the serial monitor at the same time (because then the port will be busy) 3) try getting a simpler example to work (follow a tutorial or something and get a proof of concept up and running) and see if there’s any learnings you can draw from that. Given that so many people run in to this problem, I should probably add some error handling and troubleshooting to the script
Hey I tried to get it to work, but my macbook isn't picking up on the inputs from the joystick shield. I copied the code from the link to the source code
Sorry it does recognise there are inputs on the arduino side of things, but nothing happens when I try to use it when I run the python script
@@curlybighead1111 On the line with '/dev/cu.usbmodem1461' - make sure that that serial port corresponds with your Arduino. You can see what yours is called by going in to the Arduino IDE -> Tools -> Port
@@engineerish I checked that and the port I have put down is the one I am using. What else could it be?
curlybighead do you see data in the serial monitor in the arduino ide? Close down the serial monitor (since otherwize it will be hogging the serial port) and run the python script - try to just dump the data from the stream to the console in python - it should be the exact same thing as the serial monitor in the IDE
Can you teach me how to connect it to the games?
I'm wondering the same thing, I'm thinking of running the python script when launching EmulationStation to map the buttons to the keyboard then use those in the RetroPi controller configuration
can I play modren combat 5 with it
Will windows 10 wordk as well?
Should work, haven’t tried it. You’ll need to modify some of the code ofc
@@engineerish thanks!
7:11 - Could you explain or translate that please? or at least direct me to what to google so I can find out what that means?
Absolutely - I suggest you google "bitwize operations" (and the "
i have trouble with the part with getting the button states it gives me a error
MBCraftnl what’s the error?
What does the [:-1] and [:-2] do?
The remove the last ([:-1]) and the two last ([:-2]) characters from a string in Python. stackoverflow.com/questions/15478127/remove-final-character-from-string
I don't know why but when I run the python script I don't get any results. I already uploaded the arduino code. Please reply fast. I think the python code is not working
Make sure the string on line "arduino = serial.Serial('/dev/cu.usbmodem1461', 115200, timeout=.1)" is the correct name for your Arduino serial
I checked it changed the port to COM9 as I am using windows
how can i run it on ubuntu ??
Does it work even on Android?
If you have an arduino with AT16U2 for USB, I would rather make it act as a USB-keyboard/mouse/gamepad
Thorbjørn Hellehaven sure - that’s a way to do it. My way of looking at it is that this makes customization and mapping of keys a lot easier. Being able to quickly change a python script rather than having to reprogram the usb, upload c code and reprogram again. But either way would do it!
Congrats for your video, its really helpfull! I am thinking of applying this to control Recalbox on Raspberry Pi through bluetooth (HC05), but was unable to find the format I should be passing the data. Do you know if the bit operation you described would work?
Thanks! Cool! The format I used in this video was just a protocol I came up with during development - in order to get it to work with Recalbox, you'd probably have to adhere to their protocol. Good luck!
Bro, mine doesn't work. I took the code from the description. I am 12 years old.
MNSR 1234 going to need a little more describtion than that in order to help out ;)
@@engineerish please help
and please also make a video on making ps 4 controller
Does it work with arduino leonardo?
juan camilo carmona sanchez I don’t know if this shield is compatible with the leonardo, check with your retailer
Think so they are pretty simular
what program you are using to code in python ?
I used Sublime this time
help me I want a copy of the code please
and how do you find out the port name
arduino tools bar port
Is that real
Cannot get python to work ; (
will it work Just with joystick
Electro Hithesh yeah no problem! You can use the same code and just have a single joystick connected to the Arduino
engineerish does it run for gta sanandres
hi Great one day project
What materials did you use?
Your not an actor this isnt a show just give us the info with out all the theatrics please for God's sake
gy