As long as you modify the Arduino sketch that receives the serial signals accordingly, you can format the string that gets sent however you like.
If you want your values to range from 0 - 1000 or to include decimals, or to use a different end-of-line character, by the way, you can do so. We'll set up the Arduino, then enable serial communication. Currently, that text isn't being sent to serial, because it would raise an error if there is nothing to connect to. If it looks like two numbers separated by a comma and followed by a semicolon, we're good. We'll also need to turn these numbers into a a character string, as the serial function sends data as a string of text in binary. The raw values are floating point decimals from -1 to 1, so it's convenient to multiply them and round them, then add 100 so that they are integers ranging from 0 to 200. If your controller is being read properly, move on to formatting the readings for serial. Otherwise, you'll have to do a keyboard interrupt (ctrl+C). Specify a button as the breakout button too. You can examine your controller in jstest-gtk to determine your axes, or in Python via trial-and-error. For my controller, the axes I wanted were one and three. If this doesn't work, try changing the axes to check in line 34. If detected, the Python program should report the name of the joystick, then begin writing out to the terminal the the values that Python is reading from the x-axis of each of the thumb sticks whenever they're moved from center. This will require an active desktop, so if you've been working on the Pi over SSH, hook up a monitor or access your Pi using a remote desktop. Jstest-gtk allows a user to view, test, and troubleshoot connected controllers. It should load the necessary libraries, check for a USB joystick, and output the name of the joystick it finds. Plug the controller into one of the Pi's USB ports, then run the python file controller-reader.py. Step 1 : Set up the Raspberry Pi and Video game Controllerġ.1 : Have Python recognize your controllerįollow the instructions that come with the Pi (or any of these: 1 2 3 4 5 ) so that you can boot into the Raspberry Pi. Joystick to Pi to Arduino to ESC to motor