Rasp Pi Analog Joystick - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: Rasp Pi Analog Joystick (/thread-36315.html) |
Rasp Pi Analog Joystick - mmagner2022 - Feb-07-2022 I am currently trying to connect my raspberry pi 3 to an analog joystick controller using an ADC but when I run the code and move the joystick, it always returns a position of 0. Any help would be greatly appreciated. #!usr/bin/python import spidev import os import time #Define Axis Channels swt_channel = 0 vrx_channel = 1 vry_channel = 2 #Time Delay delay = 0.5 #Spi oeffnen spi = spidev.SpiDev() spi.open(0,0) spi.max_speed_hz=1000000 #Function for reading the MCP3008 channel between 0 and 7 def readChannel(channel): val = spi.xfer2([1,(8+channel)<<4,0]) data = ((val[1]&3) <<8) + val[2] return data #endless loop while True: #Determine position vrx_pos = readChannel(vrx_channel) vry_pos = readChannel(vry_channel) #SW determine swt_val = readChannel(swt_channel) #output print("VRx : {} VRy : {} SW : {}".format(vrx_pos,vry_pos,swt_val)) # wait time.sleep(delay) RE: Rasp Pi Analog Joystick - Larz60+ - Feb-07-2022 I found this video: https://www.youtube.com/watch?v=fX225p-Sh58 which interfaces an analog joystick to pi using the ADS7830 ADC board. Code is in python, but does not use the spidev package You didn't specify what you are using as an interface (ADC) however the code should be similar. Seems to be quite thorough. |