SlideShare a Scribd company logo
Raspberry Pi with Java 8 + Pi4J 
Robert Savage 
Software Architect, MTS 
Harman International 
#DV14 #pi4j @savageautomate
What is Pi4J? 
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. 
www.pi4j.com 
• Open Source Project 
• Low Level I/O Library 
• Object-Oriented API 
• Event Based 
• Java & C (JNI + Native) 
#DV14 #pi4j @savageautomate
Pi4J Supported I/O 
Digital Interfaces 
• GPIO 
(General Purpose Input/Output) 
Data Interfaces 
• UART, SERIAL 
(Universal Asynchronous Receiver/Transmitter) 
• SPI 
(Serial Peripheral Interface) 
• I2C 
(Inter-Integrated Circuit) 
Analog Interfaces* 
#DV14 #pi4j @savageautomate
GPIO 
• Input or Output 
• Digital States 
• HIGH = +3.3 VDC 
• LOW = 0 VDC 
• RPi Models 
• A  B = ~21 GPIO 
• B+ = 28 GPIO 
• Compute Module = 46 GPIO 
#DV14 #pi4j @savageautomate
Pi4J GPIO Pin Addressing 
Visit pi4.com for a detailed pin addressing diagram! 
#DV14 #pi4j @savageautomate
GPIO Outputs 
• Control Things 
(ON  OFF) 
#DV14 #pi4j @savageautomate
GPIO Output Circuit 
#DV14 #pi4j @savageautomate
GPIO Output Example 
// 
create 
GPIO 
controller 
final 
GpioController 
gpio 
= 
GpioFactory.getInstance(); 
// 
create 
GPIO 
output 
pin 
final 
GpioPinDigitalOutput 
output 
= 
gpio.provisionDigitalOutputPin( 
RaspiPin.GPIO_12, 
PinState.LOW); 
// 
control 
GPIO 
output 
pin 
output.high(); 
output.low(); 
output.toggle(); 
// 
invert 
current 
state 
output.pulse(1000); 
// 
set 
state 
for 
a 
limited 
duration 
#DV14 #pi4j @savageautomate
GPIO Output Circuit 
Active-High Relay Board 
12 VDC  
Strobe 
Light 
12 VDC 
Illuminated  
Switch 
12 VDC 
Power Source 
#DV14 #pi4j @savageautomate
GPIO Output Demo 
• Sample Code 
• Live Demo 
#DV14 #pi4j @savageautomate
GPIO Inputs 
• Monitor Things 
• ON  OFF 
• Open  Close 
#DV14 #pi4j @savageautomate
GPIO Input Circuit 
#DV14 #pi4j @savageautomate
GPIO Input Reference 
• GPIO inputs require a “reference” voltage. 
• Without a reference, a GPIO pin can “float” 
• The Raspberry Pi includes internal PULL-UP and 
PULL-DOWN resistor settings that can be configured 
via Pi4J. 
#DV14 #pi4j @savageautomate
GPIO Input Reference 
• PULL-DOWN 
Resistance provides a reference (bias) to  
GROUND (0 VDC). If your circuit expects to  
provide +3.3VDC to signal the GPIO pin HIGH,  
then you need a PULL-DOWN reference.  
• PULL-UP 
Resistance provides a reference (bias) to  
+3.3 VDC. If your circuit expects to provide  
GROUND to signal the GPIO pin LOW, then  
you need a PULL-UP reference. 
#DV14 #pi4j @savageautomate
GPIO Input Reference 
Alternatively, you can build the PULL-UP or PULL-DOWN 
reference in the hardware circuit. The circuit below  
demonstrates a PULL-UP resistor at R1. 
This circuit signals the GPIO 
input pin to LOW when the 
switch closes the circuit and a 
path to GROUND is complete. 
PULL-UP 
RESISTOR 
#DV14 #pi4j @savageautomate
GPIO Input Example 
// 
create 
GPIO 
controller 
final 
GpioController 
gpio 
= 
GpioFactory.getInstance(); 
// 
create 
a 
GPIO 
input 
pin 
final 
GpioPinDigitalInput 
input 
= 
gpio.provisionDigitalInputPin( 
RaspiPin.GPIO_02, 
PinPullResistance.PULL_DOWN); 
#DV14 #pi4j @savageautomate
GPIO Input Listener Example 
// 
create 
event 
listener 
for 
GPIO 
input 
pin 
input.addListener((GpioPinListenerDigital) 
Java 8 
Lambda 
(GpioPinDigitalStateChangeEvent 
event) 
-­‐ 
{ 
// 
set 
output 
state 
to 
match 
the 
input 
state 
output.setState(event.getState()); 
}); 
#DV14 #pi4j @savageautomate
GPIO Input Demo 
• Sample Code 
• Live Demo 
#DV14 #pi4j @savageautomate
Pi4J Component API 
• The component APIs provides an abstraction layer from the 
hardware I/O layer. 
• This allows hardware design/circuitry to change with *less* impact 
to your implementation code. 
• For example, a RELAY could be controlled from GPIO, RS232, SPI, or 
I2C. You program defines the RELAY impl up front based on the 
hardware interface, but the rest of your program logic works against the 
RELAY component interface and not the direct hardware /communication 
IO interfaces. 
#DV14 #pi4j @savageautomate
Component Interfaces 
• Keypad 
• Light / LED 
• Dimmable Light 
• LCD 
• Power Controller 
• Relay 
• Momentary Switch 
• Toggle Switch 
• Analog Sensor 
• Distance Sensor 
• Motion Sensor 
• Temperature Sensor 
#DV14 #pi4j @savageautomate
GPIO Components Example 
// 
create 
LED 
component 
final 
Light 
light 
= 
new 
GpioLightComponment(output); 
// 
usage 
example 
light.on(); 
(or) 
light.off(); 
// 
create 
momentary 
switch 
component 
final 
MomentarySwitch 
ms 
= 
new 
GpioMomentarySwitchComponment( 
input, 
PinState.LOW, 
// 
“OFF” 
pin 
state 
PinState.HIGH); 
// 
“ON” 
pin 
state 
#DV14 #pi4j @savageautomate
Component Demo 
• Sample Code 
• Live Demo 
#DV14 #pi4j @savageautomate
UART / Serial / RS-232 
• The Raspberry Pi supports on on-board UART for 
serial communication. 
• Pi4J supports basic serial communication. 
• To use RS232 serial communication a level-shifter is 
required to convert between the TTL voltage levels 
(+3.3 VDC) and those required for RS232 
communication. 
#DV14 #pi4j @savageautomate
RS-232 Level Shifter 
#DV14 #pi4j @savageautomate
USB to RS-232 Adapter 
In addition to the on-board UART, you can also use a USB to 
RS232 adapter connected to the Raspberry Pi to provide 
RS232 serial communication. 
#DV14 #pi4j @savageautomate
UART / RS-232 Example 
// 
create 
an 
instance 
of 
the 
serial 
communications 
class 
final 
Serial 
serial 
= 
SerialFactory.createInstance(); 
// 
open 
the 
default 
serial 
port 
provided 
on 
the 
P1 
header 
// 
(this 
is 
where 
our 
LED 
reader 
is 
connected) 
serial.open(Serial.DEFAULT_COM_PORT, 
2400); 
// 
send 
Hello 
World 
message 
to 
sign 
serial.writeln(ID01PACLHello 
World! 
-­‐-­‐ 
); 
serial.writeln(ID01RPA); 
#DV14 #pi4j @savageautomate
UART / RS-232 Listener Example 
// 
create 
and 
register 
the 
serial 
data 
listener 
serial.addListener((SerialDataListener) 
Java 8 
Lambda 
(SerialDataEvent 
event) 
-­‐ 
{ 
// 
print 
out 
the 
data 
received 
to 
the 
console 
System.out.println(event.getData()); 
}); 
#DV14 #pi4j @savageautomate
UART / RS-232 Demo 
• Sample Code 
• Live Demo 
#DV14 #pi4j @savageautomate
Putting It All Together 
Lets create a real-world demo using a Raspberry 
Pi, Java, Pi4J, GPIO Inputs  Outputs, and RS232 
(Serial) devices to do something useful. 
#DV14 #pi4j @savageautomate
Demo Project Goal 
• Create a sophisticated model rocket launching 
platform. 
#DV14 #pi4j @savageautomate
Demo Project Requirements 
• Implement a safety key 
switch to arm the rocket 
and protect from  
accidental launch ignition. 
• Implement a launch 
activation button to  
initiate a launch sequence. 
#DV14 #pi4j @savageautomate
Demo Project Requirements 
• Implement an audible safety  
alarm to alert spectators of 
launch ready conditions. 
• Implement a visible alert 
device to notify spectators 
of launch ready conditions. 
#DV14 #pi4j @savageautomate
Demo Project Requirements 
• Implement an abort button 
to abort the launch sequence. 
• Implement a safety IR beam 
detector to abort launch if a 
person approaches the launch 
pad. 
#DV14 #pi4j @savageautomate
Demo Project Requirements 
• Implement an LED message board to show 
spectators the countdown and phases of the  
launch. 
• Implement a countdown timer for the launch 
sequence. 
#DV14 #pi4j @savageautomate
Demo Project Requirements 
• Implement an on-screen console/dashboard 
#DV14 #pi4j @savageautomate
Demo 
Project 
Wiring
Demo Project 
• Sample Code 
• Live Demo 
#DV14 #pi4j @savageautomate
Sides  source code available now at http://www.savagehomeautomation.com/devoxx

More Related Content

What's hot

Vlsi es-lab-manual
Vlsi es-lab-manualVlsi es-lab-manual
Vlsi es-lab-manual
twinkleratna
 
MG3130 gesture recognition kit
MG3130 gesture recognition kitMG3130 gesture recognition kit
MG3130 gesture recognition kit
Pantech ProLabs India Pvt Ltd
 
Wireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3EWireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3E
Vincent Claes
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
CAVEDU Education
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab work
JIGAR MAKHIJA
 
Intel galileo
Intel galileoIntel galileo
Intel galileo
Sofian Hadiwijaya
 
Micrcontroller iv sem lab manual
Micrcontroller iv sem lab manualMicrcontroller iv sem lab manual
Micrcontroller iv sem lab manual
RohiniHM2
 
AT89C52 Data sheet
AT89C52 Data sheetAT89C52 Data sheet
AT89C52 Data sheet
Microtech Solutions
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017
Stefano Sanna
 
Building your own RC Car with Raspberry Pi
Building your own RC Car with Raspberry PiBuilding your own RC Car with Raspberry Pi
Building your own RC Car with Raspberry Pi
Jeff Prestes
 
Introduction to the rockwell automation library of process objects
Introduction to the rockwell automation library of process objectsIntroduction to the rockwell automation library of process objects
Introduction to the rockwell automation library of process objects
IntelligentManufacturingInstitute
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical File
Soumya Behera
 
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
David Fowler
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
Raghav Shetty
 
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development
FastBit Embedded Brain Academy
 
Intel galileo gen 2
Intel galileo gen 2Intel galileo gen 2
Intel galileo gen 2
srknec
 
Tae technologies powers up with reliable control system
Tae technologies powers up with reliable control systemTae technologies powers up with reliable control system
Tae technologies powers up with reliable control system
IntelligentManufacturingInstitute
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gates
Ricardo Castro
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
Eslam Mohammed
 
Device Abstraction in OSGi Based Embedded Systems - Dimitar Valtchev
Device Abstraction in OSGi Based Embedded Systems - Dimitar ValtchevDevice Abstraction in OSGi Based Embedded Systems - Dimitar Valtchev
Device Abstraction in OSGi Based Embedded Systems - Dimitar Valtchev
mfrancis
 

What's hot (20)

Vlsi es-lab-manual
Vlsi es-lab-manualVlsi es-lab-manual
Vlsi es-lab-manual
 
MG3130 gesture recognition kit
MG3130 gesture recognition kitMG3130 gesture recognition kit
MG3130 gesture recognition kit
 
Wireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3EWireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3E
 
[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218[5]投影片 futurewad樹莓派研習會 141218
[5]投影片 futurewad樹莓派研習會 141218
 
Embedded system lab work
Embedded system lab workEmbedded system lab work
Embedded system lab work
 
Intel galileo
Intel galileoIntel galileo
Intel galileo
 
Micrcontroller iv sem lab manual
Micrcontroller iv sem lab manualMicrcontroller iv sem lab manual
Micrcontroller iv sem lab manual
 
AT89C52 Data sheet
AT89C52 Data sheetAT89C52 Data sheet
AT89C52 Data sheet
 
Android Things Linux Day 2017
Android Things Linux Day 2017 Android Things Linux Day 2017
Android Things Linux Day 2017
 
Building your own RC Car with Raspberry Pi
Building your own RC Car with Raspberry PiBuilding your own RC Car with Raspberry Pi
Building your own RC Car with Raspberry Pi
 
Introduction to the rockwell automation library of process objects
Introduction to the rockwell automation library of process objectsIntroduction to the rockwell automation library of process objects
Introduction to the rockwell automation library of process objects
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical File
 
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
 
Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development Part-1 : Mastering microcontroller with embedded driver development
Part-1 : Mastering microcontroller with embedded driver development
 
Intel galileo gen 2
Intel galileo gen 2Intel galileo gen 2
Intel galileo gen 2
 
Tae technologies powers up with reliable control system
Tae technologies powers up with reliable control systemTae technologies powers up with reliable control system
Tae technologies powers up with reliable control system
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gates
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
 
Device Abstraction in OSGi Based Embedded Systems - Dimitar Valtchev
Device Abstraction in OSGi Based Embedded Systems - Dimitar ValtchevDevice Abstraction in OSGi Based Embedded Systems - Dimitar Valtchev
Device Abstraction in OSGi Based Embedded Systems - Dimitar Valtchev
 

Similar to RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)

Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
Java Webinar #9: “Raspberry Pi Platform for Java Programmers”Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
GlobalLogic Ukraine
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry Pi
Neil Broers
 
Raspberry pi and pi4j
Raspberry pi and pi4jRaspberry pi and pi4j
Raspberry pi and pi4j
Narendran Solai Sridharan
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
RICELEEIO
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
lostcaggy
 
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Anne Nicolas
 
1032 practical linux system administration
1032 practical linux system administration1032 practical linux system administration
1032 practical linux system administration
Noel Ng
 
PPT+.pdf
PPT+.pdfPPT+.pdf
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
Mujahid Hussain
 
Internet of Things With PHP
Internet of Things With PHPInternet of Things With PHP
Internet of Things With PHP
Adam Englander
 
Scratch pcduino
Scratch pcduinoScratch pcduino
Scratch pcduino
Jingfeng Liu
 
Switch & LED using TMS320C6745 DSP
Switch & LED using TMS320C6745 DSPSwitch & LED using TMS320C6745 DSP
Switch & LED using TMS320C6745 DSP
Pantech ProLabs India Pvt Ltd
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
Tom Paulus
 
Exploring Raspberry Pi
Exploring Raspberry PiExploring Raspberry Pi
Exploring Raspberry Pi
Lentin Joseph
 
Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station
Marco Pirruccio
 
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
Mr.Nukoon Phimsen
 
Introducing the Arduino
Introducing the ArduinoIntroducing the Arduino
Introducing the Arduino
Charles A B Jr
 
Raspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application Development
Corley S.r.l.
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
Sarwan Singh
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and Circuits
Jason Griffey
 

Similar to RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014) (20)

Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
Java Webinar #9: “Raspberry Pi Platform for Java Programmers”Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
Java Webinar #9: “Raspberry Pi Platform for Java Programmers”
 
Building the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry PiBuilding the Internet of Things with Raspberry Pi
Building the Internet of Things with Raspberry Pi
 
Raspberry pi and pi4j
Raspberry pi and pi4jRaspberry pi and pi4j
Raspberry pi and pi4j
 
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game ConsoleRaspberry Pi GPIO Tutorial - Make Your Own Game Console
Raspberry Pi GPIO Tutorial - Make Your Own Game Console
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
 
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
Kernel Recipes 2018 - New GPIO interface for linux user space - Bartosz Golas...
 
1032 practical linux system administration
1032 practical linux system administration1032 practical linux system administration
1032 practical linux system administration
 
PPT+.pdf
PPT+.pdfPPT+.pdf
PPT+.pdf
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Internet of Things With PHP
Internet of Things With PHPInternet of Things With PHP
Internet of Things With PHP
 
Scratch pcduino
Scratch pcduinoScratch pcduino
Scratch pcduino
 
Switch & LED using TMS320C6745 DSP
Switch & LED using TMS320C6745 DSPSwitch & LED using TMS320C6745 DSP
Switch & LED using TMS320C6745 DSP
 
Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013Getting Started With Raspberry Pi - UCSD 2013
Getting Started With Raspberry Pi - UCSD 2013
 
Exploring Raspberry Pi
Exploring Raspberry PiExploring Raspberry Pi
Exploring Raspberry Pi
 
Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station
 
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
 
Introducing the Arduino
Introducing the ArduinoIntroducing the Arduino
Introducing the Arduino
 
Raspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application DevelopmentRaspberry Pi - HW/SW Application Development
Raspberry Pi - HW/SW Application Development
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and Circuits
 

Recently uploaded

Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Trailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptxTrailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptx
ImtiazBinMohiuddin
 
Best Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP ImplementationBest Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP Implementation
Envertis Software Solutions
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
kalichargn70th171
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
Jhone kinadey
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
campbellclarkson
 
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual PerfectionBuilding the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Applitools
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
servicesNitor
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)
alowpalsadig
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
TheFutureIsDynamic-BoxLang-CFCamp2024.pdf
TheFutureIsDynamic-BoxLang-CFCamp2024.pdfTheFutureIsDynamic-BoxLang-CFCamp2024.pdf
TheFutureIsDynamic-BoxLang-CFCamp2024.pdf
Ortus Solutions, Corp
 
Refactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contextsRefactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contexts
Michał Kurzeja
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
Softradix Technologies
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
Zycus
 
Folding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a seriesFolding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a series
Philip Schwarz
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 

Recently uploaded (20)

Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Trailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptxTrailhead Talks_ Journey of an All-Star Ranger .pptx
Trailhead Talks_ Journey of an All-Star Ranger .pptx
 
Best Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP ImplementationBest Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP Implementation
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
 
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual PerfectionBuilding the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)Photoshop Tutorial for Beginners (2024 Edition)
Photoshop Tutorial for Beginners (2024 Edition)
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
TheFutureIsDynamic-BoxLang-CFCamp2024.pdf
TheFutureIsDynamic-BoxLang-CFCamp2024.pdfTheFutureIsDynamic-BoxLang-CFCamp2024.pdf
TheFutureIsDynamic-BoxLang-CFCamp2024.pdf
 
Refactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contextsRefactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contexts
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
 
Folding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a seriesFolding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a series
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 

RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)

  • 1. Raspberry Pi with Java 8 + Pi4J Robert Savage Software Architect, MTS Harman International #DV14 #pi4j @savageautomate
  • 2. What is Pi4J? 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. www.pi4j.com • Open Source Project • Low Level I/O Library • Object-Oriented API • Event Based • Java & C (JNI + Native) #DV14 #pi4j @savageautomate
  • 3. Pi4J Supported I/O Digital Interfaces • GPIO (General Purpose Input/Output) Data Interfaces • UART, SERIAL (Universal Asynchronous Receiver/Transmitter) • SPI (Serial Peripheral Interface) • I2C (Inter-Integrated Circuit) Analog Interfaces* #DV14 #pi4j @savageautomate
  • 4. GPIO • Input or Output • Digital States • HIGH = +3.3 VDC • LOW = 0 VDC • RPi Models • A B = ~21 GPIO • B+ = 28 GPIO • Compute Module = 46 GPIO #DV14 #pi4j @savageautomate
  • 5. Pi4J GPIO Pin Addressing Visit pi4.com for a detailed pin addressing diagram! #DV14 #pi4j @savageautomate
  • 6. GPIO Outputs • Control Things (ON OFF) #DV14 #pi4j @savageautomate
  • 7. GPIO Output Circuit #DV14 #pi4j @savageautomate
  • 8. GPIO Output Example // create GPIO controller final GpioController gpio = GpioFactory.getInstance(); // create GPIO output pin final GpioPinDigitalOutput output = gpio.provisionDigitalOutputPin( RaspiPin.GPIO_12, PinState.LOW); // control GPIO output pin output.high(); output.low(); output.toggle(); // invert current state output.pulse(1000); // set state for a limited duration #DV14 #pi4j @savageautomate
  • 9. GPIO Output Circuit Active-High Relay Board 12 VDC Strobe Light 12 VDC Illuminated Switch 12 VDC Power Source #DV14 #pi4j @savageautomate
  • 10. GPIO Output Demo • Sample Code • Live Demo #DV14 #pi4j @savageautomate
  • 11. GPIO Inputs • Monitor Things • ON OFF • Open Close #DV14 #pi4j @savageautomate
  • 12. GPIO Input Circuit #DV14 #pi4j @savageautomate
  • 13. GPIO Input Reference • GPIO inputs require a “reference” voltage. • Without a reference, a GPIO pin can “float” • The Raspberry Pi includes internal PULL-UP and PULL-DOWN resistor settings that can be configured via Pi4J. #DV14 #pi4j @savageautomate
  • 14. GPIO Input Reference • PULL-DOWN Resistance provides a reference (bias) to GROUND (0 VDC). If your circuit expects to provide +3.3VDC to signal the GPIO pin HIGH, then you need a PULL-DOWN reference. • PULL-UP Resistance provides a reference (bias) to +3.3 VDC. If your circuit expects to provide GROUND to signal the GPIO pin LOW, then you need a PULL-UP reference. #DV14 #pi4j @savageautomate
  • 15. GPIO Input Reference Alternatively, you can build the PULL-UP or PULL-DOWN reference in the hardware circuit. The circuit below demonstrates a PULL-UP resistor at R1. This circuit signals the GPIO input pin to LOW when the switch closes the circuit and a path to GROUND is complete. PULL-UP RESISTOR #DV14 #pi4j @savageautomate
  • 16. GPIO Input Example // create GPIO controller final GpioController gpio = GpioFactory.getInstance(); // create a GPIO input pin final GpioPinDigitalInput input = gpio.provisionDigitalInputPin( RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN); #DV14 #pi4j @savageautomate
  • 17. GPIO Input Listener Example // create event listener for GPIO input pin input.addListener((GpioPinListenerDigital) Java 8 Lambda (GpioPinDigitalStateChangeEvent event) -­‐ { // set output state to match the input state output.setState(event.getState()); }); #DV14 #pi4j @savageautomate
  • 18. GPIO Input Demo • Sample Code • Live Demo #DV14 #pi4j @savageautomate
  • 19. Pi4J Component API • The component APIs provides an abstraction layer from the hardware I/O layer. • This allows hardware design/circuitry to change with *less* impact to your implementation code. • For example, a RELAY could be controlled from GPIO, RS232, SPI, or I2C. You program defines the RELAY impl up front based on the hardware interface, but the rest of your program logic works against the RELAY component interface and not the direct hardware /communication IO interfaces. #DV14 #pi4j @savageautomate
  • 20. Component Interfaces • Keypad • Light / LED • Dimmable Light • LCD • Power Controller • Relay • Momentary Switch • Toggle Switch • Analog Sensor • Distance Sensor • Motion Sensor • Temperature Sensor #DV14 #pi4j @savageautomate
  • 21. GPIO Components Example // create LED component final Light light = new GpioLightComponment(output); // usage example light.on(); (or) light.off(); // create momentary switch component final MomentarySwitch ms = new GpioMomentarySwitchComponment( input, PinState.LOW, // “OFF” pin state PinState.HIGH); // “ON” pin state #DV14 #pi4j @savageautomate
  • 22. Component Demo • Sample Code • Live Demo #DV14 #pi4j @savageautomate
  • 23. UART / Serial / RS-232 • The Raspberry Pi supports on on-board UART for serial communication. • Pi4J supports basic serial communication. • To use RS232 serial communication a level-shifter is required to convert between the TTL voltage levels (+3.3 VDC) and those required for RS232 communication. #DV14 #pi4j @savageautomate
  • 24. RS-232 Level Shifter #DV14 #pi4j @savageautomate
  • 25. USB to RS-232 Adapter In addition to the on-board UART, you can also use a USB to RS232 adapter connected to the Raspberry Pi to provide RS232 serial communication. #DV14 #pi4j @savageautomate
  • 26. UART / RS-232 Example // create an instance of the serial communications class final Serial serial = SerialFactory.createInstance(); // open the default serial port provided on the P1 header // (this is where our LED reader is connected) serial.open(Serial.DEFAULT_COM_PORT, 2400); // send Hello World message to sign serial.writeln(ID01PACLHello World! -­‐-­‐ ); serial.writeln(ID01RPA); #DV14 #pi4j @savageautomate
  • 27. UART / RS-232 Listener Example // create and register the serial data listener serial.addListener((SerialDataListener) Java 8 Lambda (SerialDataEvent event) -­‐ { // print out the data received to the console System.out.println(event.getData()); }); #DV14 #pi4j @savageautomate
  • 28. UART / RS-232 Demo • Sample Code • Live Demo #DV14 #pi4j @savageautomate
  • 29. Putting It All Together Lets create a real-world demo using a Raspberry Pi, Java, Pi4J, GPIO Inputs Outputs, and RS232 (Serial) devices to do something useful. #DV14 #pi4j @savageautomate
  • 30. Demo Project Goal • Create a sophisticated model rocket launching platform. #DV14 #pi4j @savageautomate
  • 31. Demo Project Requirements • Implement a safety key switch to arm the rocket and protect from accidental launch ignition. • Implement a launch activation button to initiate a launch sequence. #DV14 #pi4j @savageautomate
  • 32. Demo Project Requirements • Implement an audible safety alarm to alert spectators of launch ready conditions. • Implement a visible alert device to notify spectators of launch ready conditions. #DV14 #pi4j @savageautomate
  • 33. Demo Project Requirements • Implement an abort button to abort the launch sequence. • Implement a safety IR beam detector to abort launch if a person approaches the launch pad. #DV14 #pi4j @savageautomate
  • 34. Demo Project Requirements • Implement an LED message board to show spectators the countdown and phases of the launch. • Implement a countdown timer for the launch sequence. #DV14 #pi4j @savageautomate
  • 35. Demo Project Requirements • Implement an on-screen console/dashboard #DV14 #pi4j @savageautomate
  • 37. Demo Project • Sample Code • Live Demo #DV14 #pi4j @savageautomate
  • 38. Sides source code available now at http://www.savagehomeautomation.com/devoxx