Pada
postingan sebelumnya kita telah mempelajari bagaimana cara mengendalikan robot wireless
menggunaan bluetooth berbasis smartphone Android.
Baca Juga :
Naah kali ini, kita akan
menggunakan modul bluetooth yang berbasis joystick wireless PS2. Adapun postingan ini dibuat agar bisa memahami tentang :
- Memahami fungsi pin receiver joystick wireless PS2
- Memahami pemrograman transmitter dan receiver data pada joystick wireless PS2.
- Mampu membuat robot kontrol wireless menggunakan joystick wireless PS2.
Gambar 1 Range koordinat (A). Joystick wireles PS2 (B).
|
Komunikasi joystick wireless PS2 memanfaatkan teknologi komunikasi
wireless dengan frekuensi sinyal radio ISM 2.4 GHz untuk menghubungkan
perangkat transmitter joystick ke perangkat penerima atau receiver joystick
yang relatif pendek. Komunikasi joystick wireless PS2 hanya dapat mengirim dan
menerima data sekitar 10 meter. Dalam hal ini analog joystick berfungsi sebagai
transmitter pemberi perintah, sedangkan receiver joystick sebagai penerima
perintah yang akan menggerakan aktuator.
1 Bahan dan Komponen
Berikut
adalah daftar bahan dan komponen yang dibutuhkan untuk membuat robot digital
yang dikendalikan oleh joystik wireless PS2.
NO
|
Nama Komponen
|
Jumlah
|
1
|
LCD 16X2
|
1 Buah
|
2
|
Kabel Jumper
|
Secukupnya
|
3
|
Battery AA 1.5 V
|
4 Buah
|
4
|
Software Arduino
|
1
|
5
|
IC L293D
|
1 Buah
|
6
|
Akrilik
|
Secukupnya
|
7
|
Arduino Mega 2560
|
1 Buah
|
8
|
Sensor Ultrasonic HC-SR04
|
1 Buah
|
9
|
Joystik PS 2 Wireless M-Tech
|
1 Set
|
10
|
Motor Servo DC
|
2 Buah
|
11
|
Battery AAA 1.5 V
|
2 Buah
|
12
|
Solder
|
1 Buah
|
13
|
Timah
|
Secukupnya
|
14
|
PC
|
1Set
|
2 Fungsi Pin Receiver Joystick
Wireless PS2 Pada Robot
Berikut
adalah salah satu jenis joystik wireless PS2 M-TECH yang kita gunakan dalam tutorial ini.
Gambar 2 Joysick Wireless PS2 |
Gambar 3. Keterangan Pin Receiver Joystick |
Untuk penjelasan lebih lanjut tentang fungsi-fungsi pin receiver. Bisa anda baca DISINI.
Tabel 2 Keterangan Pin Receiver Joystick PS2 pada Robot.
Pin
|
Pin Receiver ke Arduino
|
Keterangan
|
1
|
Pin Digital 13
|
Data (Penempatan pin
digital bersifat bebas)
|
2
|
Pin Digital 12
|
Command (Penempatan pin digital bersifat bebas)
|
3
|
Tidak dihubungkan
|
Motor Vibrate
|
4
|
GND
|
GND pada Arduino
|
5
|
VCC
|
3.3 Volt pada Arduino
|
6
|
Pin Digital 11
|
Attention (Penempatan pin
digital bersifat bebas)
|
7
|
Pin Digital 10
|
Clock (Penempatan pin
digital bersifat bebas)
|
8
|
Tidak dihubungkan
|
N/C
|
9
|
VCC / GND
|
Joystick M-TECH (VCC 5 V), Joystick SONY (GND)
|
3
Desain Robot Berbasis Joystick Wireless PS2
Desain aktual
robot kontrol digital menggunakan joystick wireless PS2 pada software Fritzing
sebagai berikut :
1. Susun rangkain robot kontrol seperti Gambar 27.6
Gambar 4 Desain hardware Fritzing robot kontrol digital
berbasis joystick wireless PS2.
|
Gambar 4 diatas menunjukan bahwa robot ini menggunakan kontrol
joystick sebagai penerima dan pengirim data perintah.
Tabel
3 Logika gerak pada arduino untuk menterjemahkan karakter yang dikirim oleh
joystick
Karakter
|
PORT 7
|
PORT 6
|
PORT 5
|
PORT 4
|
Makna
|
PSB_PAD_UP
|
LOW
|
HIGH
|
HIGH
|
LOW
|
Maju
|
PSB_PAD_DOWN
|
HIGH
|
LOW
|
LOW
|
HIGH
|
Mundur
|
PSB_PAD_RIGHT
|
LOW
|
HIGH
|
LOW
|
HIGH
|
Belok
Kanan
|
PSB_PAD_LEFT
|
HIGH
|
LOW
|
HIGH
|
LOW
|
Belok
Kiri
|
2. Download Library joystik pada [ http://www.billporter.info/playstation-2-controller-arduino-library-v1-0/ ]
3. Simpan Library PS2 ke document => Arduino => libraries
4. Atau bisa juga klik menu skech pada software Arduino => Include Library => add.ZIP library => cari file PS2X_lib3.zip yang telah disimpan/klik PS2X_lib3.zip => klik open.
Gambar 5 Cara menambahkan library baru pada software arduino 1.6.3 |
5. Hubungkan Arduino ke komputer dengan kabel serial USB.
6. Pada sofware Arduino klik file => examples => ”nama file Library Joystick”=>
klik PS2X-example.
Gambar 6 Example program joystick wireless membaca data tombol
joystick
|
7. Sesuaikan setiap PIN receiver joystick pada PS2X-example => klik Tools => pilih board arduino uno => pilih port USB yang dipakai.
8. Upload program PS2X-example => buka serial monitor arduino => pilih baudrate 57600.
Gambar 7 Komunikasi “Sukses” Arduino dan
Joystick Wireless PS2.
|
9. Jika yang tampil pada serial monitor bukan seperti Gambar 7 tapi seperti Gambar 8 maka ada kabel receiver yang salah pin atau tidak tersambung.
Gambar 8 Komunikasi “Gagal”
Arduino dan Joystick Wireless PS2.
|
10. Jika semuanya benar, tapi tetap seperti gambar 27. Maka buka documents => arduino => libraries => PS2X-lib3 => buka file PS2X_lib.
11. Ubah #define CTRL_BYTE_DELAY 4 menjadi #define CTRL_BYTE_DELAY 3
Gambar 8 Perubahan besar Komunikasi Delay pada libraries
Joystick
|
12. Save. Buka lagi serial monitor arduino => klik 1 atau 2 atau 3 kali tombol reset di Arduino Uno sampai komunikasi sukses seperti Gambar 27.9
13. Dalam jenis-jenis joystick ada perbedaan dalam receiver joystick [PIN 9 “Acknowedge”] yang sebagian harus dihubungkan ke Vcc [Joystick M-TECH], disambung ke Gnd [SONY], dan ada juga yang tidak harus dihubungkan ke pin apapun pada Arduino Uno.
14. Setelah komunikasi berhasil, ketik program di bawah atau hanya tambahkan saja bagian pentingnya pada program PS2X-example.
Program_1 Arduino Robot
Joystick Wireless PS2
#include <PS2X_lib.h> //for v1.6
#define PS2_DAT
13 // Pin Digital Arduino
#define PS2_CMD
12 // Pin Digital Arduino
#define PS2_SEL
11 // Pin Digital Arduino
#define PS2_CLK
10 // Pin Digital Arduino
#define pressures
false
#define rumble
false
PS2X ps2x;
int error = 0;
byte type = 0;
byte vibrate = 0;
void setup(){
Serial.begin(57600);
delay(300);
error =
ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);
if(error ==
0){
Serial.print("Found Controller, configured successful ");
Serial.print("pressures = ");
if
(pressures)
Serial.println("true ");
else
Serial.println("false");
Serial.print("rumble
= ");
if
(rumble)
Serial.println("true)");
else
Serial.println("false");
Serial.println("Try out all the buttons, X will vibrate the
controller, faster as you press harder;");
Serial.println("holding L1 or R1 will print out the analog stick
values.");
Serial.println("Note: Go to www.billporter.info for updates and to
report bugs.");
}
else if(error
== 1)
Serial.println("No controller found, check wiring, see readme.txt
to enable debug. visit www.billporter.info for troubleshooting tips");
else if(error
== 2)
Serial.println("Controller found but not accepting commands. see
readme.txt to enable debug. Visit www.billporter.info for troubleshooting
tips");
else if(error
== 3)
Serial.println("Controller refusing to enter Pressures mode, may
not support it. ");
type =
ps2x.readType();
switch(type) {
case 0:
Serial.print("Unknown Controller type found ");
break;
case 1:
Serial.print("DualShock Controller found ");
break;
case 2:
Serial.print("GuitarHero Controller found ");
break;
case
3:
Serial.print("Wireless Sony DualShock Controller found ");
break;
}
}
void loop() {
if(error == 1)
return;
if(type == 2){
ps2x.read_gamepad();
if(ps2x.ButtonPressed(GREEN_FRET))
Serial.println("Green Fret Pressed");
if(ps2x.ButtonPressed(RED_FRET))
Serial.println("Red Fret Pressed");
if(ps2x.ButtonPressed(YELLOW_FRET))
Serial.println("Yellow Fret Pressed");
if(ps2x.ButtonPressed(BLUE_FRET))
Serial.println("Blue
Fret Pressed");
if(ps2x.ButtonPressed(ORANGE_FRET))
Serial.println("Orange
Fret Pressed");
if(ps2x.ButtonPressed(STAR_POWER))
Serial.println("Star
Power Command");
if(ps2x.Button(UP_STRUM))
Serial.println("Up Strum");
if(ps2x.Button(DOWN_STRUM))
Serial.println("DOWN Strum");
if(ps2x.Button(PSB_START))
Serial.println("Start is being held");
if(ps2x.Button(PSB_SELECT))
Serial.println("Select
is being held");
if(ps2x.Button(ORANGE_FRET)) {
Serial.print("Wammy Bar Position:");
Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
}
}
else {
//DualShock Controller
ps2x.read_gamepad(false,
vibrate);
if(ps2x.Button(PSB_START))
Serial.println("Start is being held");
if(ps2x.Button(PSB_SELECT))
Serial.println("Select is being held");
if(ps2x.Button(PSB_PAD_UP)) {
// ROBOT MAJU
Serial.print("Up held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
digitalWrite(7, LOW); //Sesuaikan dengan Pin Motor Driver yang ke
Arduino Uno
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}
else
if(ps2x.Button(PSB_PAD_RIGHT)){ // ROBOT
BELOK KANAN
Serial.print("Right held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
}
else
if(ps2x.Button(PSB_PAD_LEFT)){ // ROBOT
BELOK KIRI
Serial.print("LEFT held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}
else
if(ps2x.Button(PSB_PAD_DOWN)){ // ROBOT
MUNDUR
Serial.print("DOWN held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5,
LOW);
digitalWrite(4, HIGH);
}
else {
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
}
if(ps2x.Button(PSB_L2)){ //ROBOT CELEBRATION MAJU MUNDUR
Serial.println("L2 pressed");
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
delay(500);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
}
else
if(ps2x.Button(PSB_R2)){ //ROBOT
CELEBRATION BELOK KANAN & KIRI
Serial.println("R2 pressed");
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}
else
if(ps2x.Button(PSB_TRIANGLE)){ //TOMBOL SEGITIGA
Serial.println("Triangle pressed");
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}
else
if(ps2x.Button(PSB_CIRCLE)) { //TOMBOL BULAT
Serial.println("Circle just pressed");
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(4, HIGH);
}
else
if(ps2x.Button(PSB_SQUARE)){ //TOMBOL
KOTAK
Serial.println("Square just
released");
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
}
else
if(ps2x.Button(PSB_CROSS)) { //TOMBOL X
Serial.println("X just changed");
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4,
HIGH);
}
vibrate =
ps2x.Analog(PSAB_CROSS);
if
(ps2x.NewButtonState()) {
if(ps2x.Button(PSB_L3))
Serial.println("L3 pressed");
if(ps2x.Button(PSB_R3))
Serial.println("R3 pressed");
if(ps2x.Button(PSB_L2))
Serial.println("L2 pressed");
if(ps2x.Button(PSB_R2))
Serial.println("R2 pressed");
if(ps2x.Button(PSB_TRIANGLE))
Serial.println("Triangle pressed");
}
if(ps2x.ButtonPressed(PSB_CIRCLE))
Serial.println("Circle just pressed");
if(ps2x.NewButtonState(PSB_CROSS))
Serial.println("X just changed");
if(ps2x.ButtonReleased(PSB_SQUARE))
Serial.println("Square
just released");
if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) {
Serial.print("Stick Values:");
Serial.print(ps2x.Analog(PSS_LY), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
}
}
delay(50);
}
BACA JUGA :
Untuk Program Robot Joystick Analog Silahkan Klik link dibawah ya...
Semoga bermanfaat..
siap..semoga membantu
ReplyDelete