Interfacing Analog Joystick with Bpi:Uno32 (Generate a Square Wave)

Interfacing Analog Joystick with Bpi:Uno32 (Generate a Square Wave)

2nd November 2019 0 By Tanna TechBiz

Introducrion

  • The BPI:UNO32 is an ESP32 with Xtensa 32bit LX6 single/dual-core processor based embedded system. support Webduino ,arduino,microPython,Scratch.x function.
  • Here we are going to program it through Arduino IDE.
  • We are using Analog Joystick to interface with Bpi:Uno32.
  • An analog stick , sometimes called a control stickjoystick, or thumbstick is an input device for a controller (often a game controller) that is used for two-dimensional input.
  • The Analog Joystick is similar to two potentiometers connected together, one for the vertical movement (Y-axis) and other for the horizontal movement (X-axis). The joystick also comes with a Select switch. It can be very handy for retro gaming, robot control or RC cars.

Basic Understanding

  • Bpi:Uno32 is comes with in built ADC that is analog to digital converter. As any micro-controller or processor has its inbuilt process in digital values and here in joystick we get analog number from 0-1023 as output so we need to convert this analog values in to digital so our Bpi:Uno32 can process the data or you can say it can read the values from the Joystick.
  • The below image shows the basic characteristics of the analog joystick.

Component

Connection

Bpi:Uno32Analog Joystick
A0/36vrx
A3/39vry
5VVCC
GNDGND

Code

define joyX A0

define joyY A3

void setup() {
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
float xValue = analogRead(joyX);
float yValue = analogRead(joyY);
float xMap = map(xValue, 0,1023, 0, 7);
float yMap = map(yValue,0,1023,7,0);
//print the values with to plot or view
Serial.print(xMap);
Serial.print(“\t”);
Serial.println(yMap);

}

  • After uploading this code in to the Bpi:Uno32 you can see the value of your joystick position of (x, y) coordinate in serial monitor of Arduino IDE.

Generate a Square Wave

  • Now latest version of Arduino IDE has faciltiy to plot your values on graph for that IDE provides Serial Plotter.
  • To see this tool do following
    open Arduino IDE > tools > Serial Plotter
  • Now write the above code in Arduino IDE.
  • Upload it in Bpi:Uno32.
  • The open Serial Plotter instead Serial Monitor.
  • You can visualize your analog values coming from the Joystick in Graph.
  • Now to generate Square wave, do continuously moving joystick hand in any one particular direction like:
    Joystick has 4 quadrant
    (x, y), (-x, y), (-x, -y), (x, -y)