Difference between revisions of "Analog Joystick"
Jump to navigation
Jump to search
Line 14: | Line 14: | ||
[[File:Joystick-electro.JPG|x400px]] | [[File:Joystick-electro.JPG|x400px]] | ||
− | |||
= How to control it in MicroPython = | = How to control it in MicroPython = | ||
Line 45: | Line 44: | ||
= Related Tutorial Videos = | = Related Tutorial Videos = | ||
<youtube>3J3GbD2PrCs</youtube> | <youtube>3J3GbD2PrCs</youtube> | ||
+ | |||
+ | |||
+ | = Background = | ||
+ | This is conceptually what is inside the joystick. | ||
+ | |||
+ | [[File:Joystick-inside.PNG|x400px]] |
Revision as of 20:13, 29 August 2020
Contents
Description
The analog joystick includes 2 Potentiometer and one digital switch.
It has 5 connectors:
- GND - connected to GND
- 5V - which is in our cases connected to 3.3V
- VRx - the voltage representing the position in X
- VRy - the voltage representing the position in Y
- SW - 0 if pressed
How to connect it electrically
How to control it in MicroPython
Basic code to generate a 500 Hz signal
reading all values and printing them to the console
1 #Example usage for ESP32
2 from machine import Pin, ADC
3 from time import sleep
4 # analog inputs for X and Y
5 analogPinX = ADC(Pin(34))
6 analogPinY = ADC(Pin(35))
7 #switching the analog input to 12Bit (0...4095)
8 analogPinX.atten(ADC.ATTN_11DB)
9 analogPinY.atten(ADC.ATTN_11DB)
10 # digital input on pin 26
11 sw = Pin(26, Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor
12
13 while True:
14 analogValX = analogPinX.read()
15 analogValY = analogPinY.read()
16 switch = sw.value()
17
18 print("x:%s y:%s sw:%s" % (analogValX, analogValY, switch))
19
20 sleep(1)
Related Tutorial Videos
Background
This is conceptually what is inside the joystick.