Raspberry Pi‎ > ‎SANKI Device‎ > ‎

2-Axis Joystick


2-Axis Joystick

Hardware

 
https://sites.google.com/a/imediabank.com/sanki/project/sanki-device/2-axis-joystick/MCP3008_joystick-1024x930.png?attredirects=0
 
https://sites.google.com/a/imediabank.com/sanki/SP000320.jpg?attredirects=0
 
Photo Coming Soon

Pin Connect

Please Click the above Pin Connect Image.

Examples

          Pre-Install SPIDEV
  1. #
    #This program is modify 8led to 16led , raspberry pi control two 74hc595 
    # Good!
    #
    #
    #
    #!/usr/bin/python
     
    
    #!/usr/bin/python
    #--------------------------------------
    # This script reads data from a
    # MCP3008 ADC device using the SPI bus.
    #
    # Analogue joystick version!
    #
    # Author : Matt Hawkins
    # Date   : 17/04/2014
    #
    # http://www.raspberrypi-spy.co.uk/
    #
    #--------------------------------------
     
    import spidev
    import time
    import os
     
    # Open SPI bus
    spi = spidev.SpiDev()
    spi.open(0,0)
     
    # Function to read SPI data from MCP3008 chip
    # Channel must be an integer 0-7
    def ReadChannel(channel):
      adc = spi.xfer2([1,(8+channel)<<4,0])
      data = ((adc[1]&3) << 8) + adc[2]
      return data
     
    # Define sensor channels
    # (channels 3 to 7 unused)
    swt_channel = 0
    vrx_channel = 1
    vry_channel = 2
     
    # Define delay between readings (s)
    delay = 0.5
     
    while True:
     
      # Read the joystick position data
      vrx_pos = ReadChannel(vrx_channel)
      vry_pos = ReadChannel(vry_channel)
     
      # Read switch state
      swt_val = ReadChannel(swt_channel)
     
      # Print out results
      print "--------------------------------------------"
      print("X : {}  Y : {}  Switch : {}".format(vrx_pos,vry_pos,swt_val))
     
      # Wait before repeating loop
      time.sleep(delay)

Reference