Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... •...

49
Pemrograman Raspberry Pi (1) Java dan Pi4J

Transcript of Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... •...

Page 1: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

PemrogramanRaspberry Pi (1)

Java dan Pi4J

Page 2: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Dasar Pemrograman Java di Raspberry Pi (1)

Page 3: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Kebutuhan Dasar

• Rasberry Pi Series board + Power Supply

• Raspbian Linux

• Laptop/PC + Programming Environment + Remote Connection Tools

• Modul Sensor

• Modul Aktuator

• Modul Data and Signal Converter / Modulator (opsional)

• Kabel Jumper

• Project Board

• Kabel LAN

• Kabel Roll (Listrik)

Page 4: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Raspberry Pi 3

Page 5: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Raspberry Pi 3

• SoC: Broadcom BCM2837• CPU: 4× ARM Cortex-A53, 1.2GHz• GPU: Broadcom VideoCore IV• RAM: 1GB LPDDR2 (900 MHz)• Networking: 10/100 Ethernet, 2.4GHz 802.11n wireless• Bluetooth: Bluetooth 4.1 Classic, Bluetooth Low Energy• Storage: microSD• GPIO: 40-pin header, populated• Ports: HDMI, 3.5mm analogue audio-video jack, 4× USB

2.0, Ethernet, Camera Serial Interface (CSI), Display Serial Interface (DSI)

Page 6: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Raspbian Jessie

The latest Raspbian Distribution, please check https://www.raspberrypi.org/downloads/ ^^

Page 7: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Pemrograman Java di Raspberry Pi

• Raspbian Linux pada dasarnya sudah memilikisupport terhadap beberapa bahasa pemrograman, termasuk Java

• Raspbian Jessie memiliki JDK 8 yang sudahter-install secara default (Java SE 8 Embedded)

• Pemrograman Java di Raspberry Pi menggunakanAPI Pi4J (http://pi4j.com/)

Page 8: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Pi4J API

• Pi4J is an open-source project providing a library for Java programmers to interact with the low-level I/O capabilities on the Raspberry Pi platform.• Open Source Project

• Low Level I/O Library

• Object-Oriented API

• Event Based

• Java & C (JNI + Native)

Page 9: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Fitur Pi4J API

• Low Level I/O Interfaces• Digital Interfaces

• GPIO (General Purpose Input Output)

• PWM (Pulse Width Modulation)

• Data Interfaces• UART, SERIAL (Universal Asynchronous Receiver/Transmitter)

• SPI (Serial Peripheral Interface)

• I²C (Inter-Integrated Circuit)

• Analog Interfaces

Page 10: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Fitur Pi4J Lanjutan

• Export & unexport GPIO pins

• Configure GPIO pin direction

• Configure GPIO pin edge detection

• Control/write GPIO pin states

• Pulse GPIO pin state

• Read GPIO pin states

• Listen for GPIO pin state changes (interrupt-based; not polling)

• Automatically set GPIO states on program termination (GPIO shutdown)

• Triggers for automation based on pin state changes

• Send & receive data via RS232 serial communication

• I2C Communication

• SPI Communication

• Extensible GPIO Provider interface to add GPIO capacity via expansion boards

• Access system information and network information from the Raspberry Pi

• Wrapper classes for direct access to WiringPi Library from Java

• Pulse Width Modulation Functionality Wrapper

Page 11: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Dasar Pemrograman Java di Raspberry Pi menggunakan Pi4J

Page 12: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

GPIO

• General-purpose input/output (GPIO) adalah pin generikpada sirkuit terpadu (chip) yang perilakunya (termasukapakah pin itu input atau output) dapat dikontrol(diprogram) oleh pengguna saat berjalan

• Pada Raspberry Pi, pin GPIO (general purpose input/output) terletak di salah satu sudut papan

• Pin-pin GPIO adalah penghubung antara Raspberry Pi dengan “dunia luar”• Bisa diumpamakan sebagai tombol-tombol yang dapat dinyalakan

atau dimatikan (input) atau bisa juga Raspberry Pi yang menyalakan/mematikan tombol2 tersebut (output)

• GPIO dapat diprogram untuk menghubungkan Raspberry Pi denganalat lain, inputnya tidak hanya dapat dihubungkan dengan tombol2 sederhana namun bisa juga dari alat lain seperti sensor atau data dari komputer lain

Page 13: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

GPIO

• Input or Output

• Digital States• HIGH ~ 3.3 VDC

• LOW ~ 0 VDC

• Models• Dependent on Raspberry Pi Model

• Model 3 B = 29 pins

Page 14: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

GPIO Digital States

Page 15: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

GPIO

Page 16: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

GPIO NumberingScheme :Raspberry 3Model B

Page 17: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

GPIO

• Programmable I/O Pins• Input from “something”

• Output for controlling “something”

Page 18: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Praktikum 1

Dasar Pemrograman GPIO padaRaspberry Pi dengan MenggunakanJava dan Pi4j

Page 19: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Praktikum 1

• Menyalakan LED dengan menggunakan Program Java Sederhana

Page 20: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Praktikum 1

• Alat dan Bahan• Laptop / PC yang sudah terinstall Java Development

Environment (ex. Netbeans dan JDK 8 + Pi4J)

• Remote Connection Tools (ex. Putty)

• Raspberry Pi board

• Power supply 5V

• Kabel LAN

• Project board / bread board

• LED

• Kabel jumper untuk pin

• Resistor ± 220 Ω

Page 21: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 1Mempersiapkan Rasberry Pi untuk dapatdiprogram melalui sistem remote

1. Persiapkan Micro SD Card minimum kapasitas 8 GB

2. Download Raspbian Linux OS dari website Raspbian

3. Extract dan Burn Raspbian OS ke dalam Micro SD Card dengan menggunakan PC / Laptop • Dapat menggunakan tools tambahan, misalnya UltraISO,

PowerISO atau ISO dan disc image tools yang lain

4. Pasang salah satu ujung kabel LAN di Raspberry Pi dan ujung lainnya di PC / Laptop

5. Masukkan Micro SD Card ke dalam Raspberry Pi

6. Pasang power supply ke Raspberry PI

Page 22: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 2Mempersiapkan rangkaian yang akandiprogram

Page 23: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 2Mempersiapkan rangkaian yang akandiprogram

Page 24: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

1. Buka setting jaringan Ethernet / LAN kita di Network and Sharing Center (Windows)

Langkah 3Menemukan alamat IP Address dariRaspberry Pi

Page 25: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 3Menemukan alamat IP Address dariRaspberry Pi

2. Cek IP Address PC/Laptop kita dan setting dalammode dinamis DHCP

3. Simpan dan keluar

4. Buka command prompt di PC/Laptop kita

5. Jalankan command ipconfig dan temukan ipaddress dinamis yang diberikan kepadaPC/Laptop kita

Page 26: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 3Menemukan alamat IP Address dariRaspberry Pi

Page 27: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 3Menemukan alamat IP Address dariRaspberry Pi

6. Temukan IP Address dari Raspberry Pi yang terkoneksi dengan Ethernet kita denganmenjalankan command arp –a

Page 28: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 3Menemukan alamat IP Address dariRaspberry Pi

2. Temukan IP Address dari Raspberry Pi yang terkoneksi dengan Ethernet kita denganmenjalankan command arp –a

Cari yang dynamic

Ex : 169.254.74.234

IP Address Raspberry Pi

Page 29: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 4Menguji koneksi dengan remote connection tools (Putty)

1. Download aplikasi putty di putty.org

2. Buka aplikasi putty

3. Isikan IP Address Raspberry Pi pada bagian Host Name

4. Pastikan Port sudah terisi nomor port SSH (22) dan Connection Type adalah SSH

5. Pilih dan tekan tombol Open

Page 30: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi
Page 31: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

6. Isikan username dan password akun linuxRaspbian (default)

a. Username : pib. Password : raspberry

Page 32: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 4Menguji koneksi dengan remote connection tools (Putty)

Page 33: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 5Mempersiapkan Java IDE untuk dapatdigunakan dalam remote developing

1. Kita gunakan Netbeans IDE dan JDK 8

2. Buka Netbeans

3. Masuk pada menu Tools → Platform

Page 34: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 5Mempersiapkan Java IDE untuk dapatdigunakan dalam remote developing

4. Pilih add Platform dan pilih Remote Java StandardEdition dan pilihNext

5. Isi sesuai alamatsistem yang akandi remote

6. Pilih Finish

Page 35: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 5Mempersiapkan Java IDE untuk dapatdigunakan dalam remote developing

Page 36: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 6Membuat project baru untukmelakukan pemrograman

1. Membuat projek Java baru

2. Tambahkan library Pi4J

3. Dan saatnya, it’s ngoding time ^^

Page 37: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

//void main

final GpioController gpio =GpioFactory.getInstance();

final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, "LED", PinState.HIGH);

pin.setShutdownOptions(true, PinState.LOW);

Thread.sleep(5000);

pin.low();

Thread.sleep(5000);

pin.toggle();

Thread.sleep(5000);

pin.pulse(1000, true);

gpio.shutdown();

Page 38: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Dasar Pemrograman Java di Raspberry Pi (2)

Page 39: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Pulse Width Modulation

• PWM ( Pulse Width Modulation) adalah salah satuteknik modulasi dengan mengubah lebar pulsa(duty cycle) dengan nilai amplitudo dan frekuensiyang tetap untuk mendapatkan tegangan rata-rata yang berbeda

• PWM adalah pemodulasian data untuktelekomunikasi, pengontrolan daya atau teganganyang masuk ke beban, regulator tegangan, audio effect dan penguatan, dll.

• Aplikasi PWM biasanya berupa pengendaliankecepatan motor DC, pengendalian motor servo, dan pengaturan nyala terang LED

Page 40: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Pulse Width Modulation

Page 41: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Pulse Width Modulation

Page 42: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Praktikum 2

Dasar Pemrograman PWM GPIO padaRaspberry Pi dengan MenggunakanJava dan Pi4j

Page 43: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Praktikum 2

• Menyalakan dan mematikan LED secara perlahandengan menggunakan Program Java Sederhana

Page 44: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi
Page 45: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Praktikum 2

• Alat dan Bahan• Laptop / PC yang sudah terinstall Java Development

Environment (ex. Netbeans dan JDK 8 + Pi4J)

• Remote Connection Tools (ex. Putty)

• Raspberry Pi board

• Power supply 5V

• Kabel LAN

• Project board / bread board

• LED

• Kabel jumper untuk pin

• Resistor ± 220 Ω

Page 46: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Langkah 1Membuat project baru untukmelakukan pemrograman

1. Langkah – langkah sebelumnya sama denganpraktikum sebelumnya

Page 47: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

//void main

Gpio.wiringPiSetup();

SoftPwm.softPwmCreate(PIN_NUMBER, 0, 100);

for (int i = 0; i <= 100; i++)

SoftPwm.softPwmWrite(PIN_NUMBER, i);

Thread.sleep(25);

System.out.println("Power = " + i + " %");

Thread.sleep(5000);

for (int i = 100; i >= 0; i--)

SoftPwm.softPwmWrite(PIN_NUMBER, i);

Thread.sleep(25);

System.out.println("Power = " + i + " %");

Page 48: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

https://www.youtube.com/watch?v=7cHIA3Nchp4

Pengembangan : Running LED / Lampu Hias

Page 49: Pemrograman Raspberry Pi (1)€¢Pemrograman Java di Raspberry Pi menggunakan API Pi4J ( ... • Access system information and network information from the Raspberry Pi

Terimakasih