Overview of Analog Joystick
Applications like video games that require a change in cursor position in a 2-D plane make use of analog joysticks as input devices.
The Analog joystick produces two voltages; one corresponding to the position with respect to X-axis and another corresponding to the position with respect to Y-axis. The voltages produced depend on the position of the joystick.
For more information about Analog Joystick and how to use it, refer to the topic Analog Joystick in the sensors and modules section.
To interface the Analog Joystick with MSP-EXP430G2 TI Launchpad, we need to use ADC on the microcontroller of the MSP-EXP430G2 TI Launchpad board.
Connection Diagram of Analog Joystick with MSP-EXP430G2 TI Launchpad
Get X and Y Directions of Analog Joystick using MSP-EXP430G2 TI Launchpad
Displaying analog joystick voltages in X and Y directions on the serial monitor of Energia.
Here, we will be using the analog pins of MSP-EXP430G2 TI Launchpad to process the analog voltages of the joystick.
Tread Carefully: MSP-EXP430G2 TI Launchpad board has a RAM of 512 bytes which is easily filled, especially while using different libraries. There are times when you need the Serial buffer to be large enough to contain the data you want and you will have to modify the buffer size for the Serial library. While doing such things, we must ensure that the code does not utilize more than 70% RAM. This could lead to the code working in an erratic manner, working well at times, and failing miserably at others.
There are times when the RAM usage may exceed 70% and the codes will work absolutely fine, and times when the code will not work even when the RAM usage is 65%.
In such cases, a bit of trial and error with the buffer size and/or variables may be necessary.
Analog Joystick Code for MSP-EXP430G2 TI Launchpad
const int joystick_x_pin = A3;
const int joystick_y_pin = A4;
void setup() {
Serial.begin(9600); /* Define baud rate for serial communication */
}
void loop() {
int x_adc_val, y_adc_val;
float x_volt, y_volt;
x_adc_val = analogRead(joystick_x_pin);
y_adc_val = analogRead(joystick_y_pin);
x_volt = ( ( x_adc_val * 3.3 ) / 1023 ); /*Convert digital value to voltage */
y_volt = ( ( y_adc_val * 3.3 ) / 1023 ); /*Convert digital value to voltage */
Serial.print("X_Voltage = ");
Serial.print(x_volt);
Serial.print("\t");
Serial.print("Y_Voltage = ");
Serial.println(y_volt);
delay(100);
}
Video of Analog Joystick for MSP-EXP430G2 TI Launchpad
Components Used |
||
---|---|---|
TI Launchpad MSP-EXP430G2 TI Launchpad MSP-EXP430G2 |
X 1 | |
Analog Joystick Joystick is an input device used to control the pointer movement in 2-dimension axis. It is mostly used in Video games. |
X 1 |
Downloads |
||
---|---|---|
|
Analog_Joystick_Interfacing_With_TI_Launchpad_INO | Download |