SlideShare a Scribd company logo
1
Confidential
2
Confidential
Raspberry Pi Platform for Java
Programmers
Dmytro Ihnatiev
Raspberry Pi Platform for Java Programmers
29.04.2021
3
3
Confidential
Raspberry Pi general overview
4
Confidential
What is Raspberry Pi
• Single Board Computer
• Linux Operating system -
Raspbian
• ARM Architecture
• Low Cost
• Low Power
• Has the ability to interact with
the outside world GPIO (used
in a wide array of digital maker
projects, from music machines
and parent detectors to
weather stations and tweeting
birdhouses with infra-red
cameras, etc.)
5
Confidential
Raspberry Pi other models
Raspberry Pi Pico Raspberry Pi 400 unit
6
Confidential
Finding Compatible Hardware
• Zillions of devices available
• Search Amazon, Adafruit for
Raspberry Pi devices
• 3.3V or 5V, I2C, GPIO, Serial
• “Hats” can be used to expand
capability by stacking boards
7
Confidential
Ground Pin, Power Pin, GPIO what is it?
The Raspberry Pi 4 board has a GPIO header with 40 pins (amount could be different from
model to model).
Ground Pins
The ground is very useful for making a common reference between all components in your
circuit. Always remember to connect all components to the ground.
Power Pins
Those pins can be used to power components such as sensors or small actuators.
GPIO
GPIO means General Purpose Input/Output. Basically that’s one pin you can use to write data to
external components (output), or read data from external components (input).
8
Confidential
Pin numbering example (Pinout)
9
9
Confidential
Java (Pi4J) for Raspberry Pi
10
Confidential
What is Pi4J?
• Open Source Project
• Raspberry Pi Platform (Linux/ARM)
• Abstraction over Low Level I/O
• Supports I/O Programming
• Object-oriented API
• Event Based
• Java / C (JNI + Native)
• Provides Listeners , Triggers & Component API
• Provides Java Classes supporting I/O Operations
11
Confidential
Brief history of Pi4J
The Pi4J Project was started in 2012, the same year the Raspberry Pi was introduced as a tool to
provide Java developers a simple and familiar object-oriented interface library to access the low-level
I/O capabilities of the Raspberry Pi including GPIO, I2C, SPI, PWM and Serial communications.
12
Confidential
Version 1.4 of Pi4J
The original library which started in 2012 and got a last release in 2021. Up till version 1.3 the
library targets Java 8, while version 1.4 relies on Java 11.
Main features:
• 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
13
Confidential
Version 2 of Pi4J
As of Version 2.0, Pi4J will no longer include support for peripheral devices and add-on
chipsets/boards as part of the core project. A new plugin model has been introduced in version
2.0 that should help enable third-party development and support third-party add-ons which may
be developed and maintained independently of the core Pi4J project.
Main features:
• Fluent APIs/Interfaces
• Immutable Runtime Context
• Extensible Provider/Platform/Plug-in
Architecture
• Builder-patterns for creating new I/O
instances
• Dependency Injection via Pi4J Annotations
• Well-documented source code
• Hardware PWM Support
• Remote I/O Support (via TCP/IP)
• Java 11
• In addition to the features listed above, Pi4J
version 2.0 also abandons the old WiringPi
pin numbering scheme in favor of the more
traditional and commonly used Broadcom
pin numbering scheme.
14
Confidential
Version 2 of Pi4J
As of Version 2.0, Pi4J will no longer include support for peripheral devices and add-on
chipsets/boards as part of the core project. A new plugin model has been introduced in version
2.0 that should help enable third-party development and support third-party add-ons which may
be developed and maintained independently of the core Pi4J project.
Main features:
• Fluent APIs/Interfaces
• Immutable Runtime Context
• Extensible Provider/Platform/Plug-in
Architecture
• Builder-patterns for creating new I/O
instances
• Dependency Injection via Pi4J Annotations
• Well-documented source code
• Hardware PWM Support
• Remote I/O Support (via TCP/IP)
• Java 11
• In addition to the features listed above, Pi4J
version 2.0 also abandons the old WiringPi
pin numbering scheme in favor of the more
traditional and commonly used Broadcom
pin numbering scheme.
15
Confidential
GPIO Programming with Pi4J
• Hardware Pins to Motorola Broadcom chipset numbering
• Physical pin locations can change between board revisions
• Pi4J can use Broadcom or WiringPi numbering schemes
• Input or Output Pins
• High (3.3 VDC) or Low (0 VDC) States
• Outputs used to control things like relays, lights, motors, bells, etc.
• Pullup and Pulldown resistors
16
Confidential
Main design classes (Pi4J 1.4)
• Listeners. Provides the ability to react on
events from triggers
• Triggers. Create an event on state
change
• Components (Deprecated in Pi4J 2.0)
Other Components
• Pull up and Pull down Resistors
• Toggle output and handy methods to access
pins and change their states
17
Confidential
Pull up and Pull Down resistors
The pull-down resistor pulls the voltage
down to zero. If the pull-up switch is pressed,
it pulls the voltage up to whatever the +
supply is.
The pull-up resistor pulls the voltage up to
whatever the + supply is. If the pull-down
switch is pressed, it pulls the voltage down to
zero.
18
Confidential
GPIO Output Circuit Example
GpioController gpio = GpioFactory.getInstance();
GpioPinDigitalOutput output =
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_12,
PinState.LOW);
output.high(); // set to high state
output.low(); // set to low state
output.toggle(); // switch to other state
output.pulse(1000); // set state for a duration
19
Confidential
GPIO Input Circuit Example
GpioController gpio = GpioFactory.getInstance();
GpioPinDigitalInput input = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02,
PinPullResistance.PULL_DOWN);
input.addListener((GpioPinListenerDigital) (GpioPinDigitalStateChangeEvent
event) -> {
System.out.println(
"State = " + event.getState() +
", Edge = " + event.getEdge() +
", Pin = " + event.getPin() +
", Pressed = " + input.isHigh()
);
} );
20
Confidential
Resources
• Pi4J - https://pi4j.com/1.2/index.html
• GitHub Pi4J - https://github.com/Pi4J/pi4j
• Pi4J 2.0 - https://pi4j.com/
• GPIO - https://www.raspberrypi.org/documentation/usage/gpio/README.md
• WiringPi - http://wiringpi.com/
• Extensive support for many devices for many languages -
https://github.com/ControlEverythingCom
• Hardware Vendors (SeeedStudio Grove, Adafruit – Provides Python code for
most of their hardware, Texas Instruments (sold by Mouser, DigiKey, etc.)
• Pi Starter and Learning Kit Vendors (CanaKit, Adeept, etc.)
21
Confidential

More Related Content

PDF
Embedded Webinar #12 “GloDroid or Boosting True Open Source Android Stack Dev...
GlobalLogic Ukraine
 
PDF
Embedded Webinar #13: "From Zero to Hero: contribute to Linux Kernel in 15 mi...
GlobalLogic Ukraine
 
PPTX
Java10 new features 2018
Arjun Bhati
 
PDF
Redfish and python-redfish for Software Defined Infrastructure
Bruno Cornec
 
PPTX
Installing Rational Rhapsody Designer 8.2 or 8.2.1 for Executable MBSE
Fraser Chadburn
 
PDF
Understand the Trade-offs Using Compilers for Java Applications
C4Media
 
ODP
Os Grossupdated
oscon2007
 
PDF
IPMI is dead, Long live Redfish
Bruno Cornec
 
Embedded Webinar #12 “GloDroid or Boosting True Open Source Android Stack Dev...
GlobalLogic Ukraine
 
Embedded Webinar #13: "From Zero to Hero: contribute to Linux Kernel in 15 mi...
GlobalLogic Ukraine
 
Java10 new features 2018
Arjun Bhati
 
Redfish and python-redfish for Software Defined Infrastructure
Bruno Cornec
 
Installing Rational Rhapsody Designer 8.2 or 8.2.1 for Executable MBSE
Fraser Chadburn
 
Understand the Trade-offs Using Compilers for Java Applications
C4Media
 
Os Grossupdated
oscon2007
 
IPMI is dead, Long live Redfish
Bruno Cornec
 

What's hot (20)

PPT
OpenDaylight nluug_november
Christopher Price
 
PDF
Isn’t it Ironic that a Redfish is software defining you
Bruno Cornec
 
PDF
BKK16-212: What's broken on ARM64?
Linaro
 
PDF
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
Qualcomm Developer Network
 
PDF
Os Lattner
oscon2007
 
PDF
A Java Implementer's Guide to Better Apache Spark Performance
Tim Ellison
 
PDF
FEL 12 Release Notes
chitlesh
 
PDF
Os Rego
oscon2007
 
PDF
Alfresco Day Vienna 2015 - Technical Track - Developer Platform Updates
Alfresco Software
 
PPTX
Splunk Modular Inputs / JMS Messaging Module Input
Damien Dallimore
 
PDF
Oracle Linux Nov 2011 Webcast
Terry Wang
 
PDF
BKK16-301A Expanding the Enterprise Landscape in Centos
Linaro
 
PPTX
Rational Rhapsody 8.3 with Cygwin and iFixes (www.executablembse.com)
Fraser Chadburn
 
PDF
Serverless Java: JJUG CCC 2019
Shaun Smith
 
PPTX
開放原始碼 Ch1.2 intro - oss - apahce foundry (ver 2.0)
My own sweet home!
 
PDF
Mavenizing your Liferay project
mimacom
 
PDF
Deep Learning for Java Developer - Getting Started
Suyash Joshi
 
PDF
Yocto - 7 masters
Intel Software Brasil
 
PDF
Next Generation Client APIs in Envoy Mobile
C4Media
 
PDF
Os Koziarsky
oscon2007
 
OpenDaylight nluug_november
Christopher Price
 
Isn’t it Ironic that a Redfish is software defining you
Bruno Cornec
 
BKK16-212: What's broken on ARM64?
Linaro
 
Developing for Industrial IoT with Linux OS on DragonBoard™ 410c: Session 3
Qualcomm Developer Network
 
Os Lattner
oscon2007
 
A Java Implementer's Guide to Better Apache Spark Performance
Tim Ellison
 
FEL 12 Release Notes
chitlesh
 
Os Rego
oscon2007
 
Alfresco Day Vienna 2015 - Technical Track - Developer Platform Updates
Alfresco Software
 
Splunk Modular Inputs / JMS Messaging Module Input
Damien Dallimore
 
Oracle Linux Nov 2011 Webcast
Terry Wang
 
BKK16-301A Expanding the Enterprise Landscape in Centos
Linaro
 
Rational Rhapsody 8.3 with Cygwin and iFixes (www.executablembse.com)
Fraser Chadburn
 
Serverless Java: JJUG CCC 2019
Shaun Smith
 
開放原始碼 Ch1.2 intro - oss - apahce foundry (ver 2.0)
My own sweet home!
 
Mavenizing your Liferay project
mimacom
 
Deep Learning for Java Developer - Getting Started
Suyash Joshi
 
Yocto - 7 masters
Intel Software Brasil
 
Next Generation Client APIs in Envoy Mobile
C4Media
 
Os Koziarsky
oscon2007
 
Ad

Similar to Java Webinar #9: “Raspberry Pi Platform for Java Programmers” (20)

PPTX
Unit 3 Complete.pptx
Selvaraj Seerangan
 
PPTX
Rasberry pie--- power point presentation
trangasaivarun
 
PDF
IoT Physical Devices and End Points.pdf
GVNSK Sravya
 
PPTX
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
PPTX
IoT for data science Module 5 - Raspberry Pi.pptx
MadhurimaDas52
 
PPTX
Building the Internet of Things with Raspberry Pi
Neil Broers
 
PDF
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
Mr.Nukoon Phimsen
 
PPTX
Got Python I/O: IoT Develoment in Python via GPIO
Adam Englander
 
PDF
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
savageautomate
 
PPTX
Up and running with Raspberry Pi
Shahed Mehbub
 
PDF
IoT: LoRa and Java on the PI
JWORKS powered by Ordina
 
PDF
Raspberry pi technical documentation
GR Techno Solutions
 
PPTX
Internet of Things With PHP
Adam Englander
 
PPTX
Unit 6 - PART2.pptx
BLACKSPAROW
 
PDF
RASPBERRY PI is an communication board using between electronic devices
mietcse1415
 
PPTX
Raspberry pi and pi4j
Narendran Solai Sridharan
 
PPTX
RaspberryPi.pptx
Pheo25
 
DOCX
Raspberry Pi
Rukaifra Incorporation
 
PPTX
IOT notes ....,.........
taetaebts431
 
PPTX
Raspberry Pi Introduction
Michal Sedlak
 
Unit 3 Complete.pptx
Selvaraj Seerangan
 
Rasberry pie--- power point presentation
trangasaivarun
 
IoT Physical Devices and End Points.pdf
GVNSK Sravya
 
M.Tech Internet of Things Unit - III.pptx
AvinashAvuthu2
 
IoT for data science Module 5 - Raspberry Pi.pptx
MadhurimaDas52
 
Building the Internet of Things with Raspberry Pi
Neil Broers
 
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
Mr.Nukoon Phimsen
 
Got Python I/O: IoT Develoment in Python via GPIO
Adam Englander
 
RASPBERRY PI WITH JAVA 8 + Pi4J (Devoxx 2014)
savageautomate
 
Up and running with Raspberry Pi
Shahed Mehbub
 
IoT: LoRa and Java on the PI
JWORKS powered by Ordina
 
Raspberry pi technical documentation
GR Techno Solutions
 
Internet of Things With PHP
Adam Englander
 
Unit 6 - PART2.pptx
BLACKSPAROW
 
RASPBERRY PI is an communication board using between electronic devices
mietcse1415
 
Raspberry pi and pi4j
Narendran Solai Sridharan
 
RaspberryPi.pptx
Pheo25
 
IOT notes ....,.........
taetaebts431
 
Raspberry Pi Introduction
Michal Sedlak
 
Ad

More from GlobalLogic Ukraine (20)

PDF
GlobalLogic JavaScript Community Webinar #21 “Інтерв’ю без заспокійливих”
GlobalLogic Ukraine
 
PPTX
Deadlocks in SQL - Turning Fear Into Understanding (by Sergii Stets)
GlobalLogic Ukraine
 
PDF
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
PDF
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Ukraine
 
PDF
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Ukraine
 
PDF
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic Ukraine
 
PPTX
Штучний інтелект як допомога в навчанні, а не замінник.pptx
GlobalLogic Ukraine
 
PPTX
Задачі AI-розробника як застосовується штучний інтелект.pptx
GlobalLogic Ukraine
 
PPTX
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
GlobalLogic Ukraine
 
PDF
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Ukraine
 
PDF
JavaScript Community Webinar #14 "Why Is Git Rebase?"
GlobalLogic Ukraine
 
PDF
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic Ukraine
 
PPTX
Страх і сила помилок - IT Inside від GlobalLogic Education
GlobalLogic Ukraine
 
PDF
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic Ukraine
 
PDF
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic Ukraine
 
PDF
“How to Secure Your Applications With a Keycloak?
GlobalLogic Ukraine
 
PDF
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 
PPTX
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Ukraine
 
PDF
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic Ukraine
 
PDF
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
GlobalLogic Ukraine
 
GlobalLogic JavaScript Community Webinar #21 “Інтерв’ю без заспокійливих”
GlobalLogic Ukraine
 
Deadlocks in SQL - Turning Fear Into Understanding (by Sergii Stets)
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Ukraine
 
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic Ukraine
 
Штучний інтелект як допомога в навчанні, а не замінник.pptx
GlobalLogic Ukraine
 
Задачі AI-розробника як застосовується штучний інтелект.pptx
GlobalLogic Ukraine
 
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
GlobalLogic Ukraine
 
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Ukraine
 
JavaScript Community Webinar #14 "Why Is Git Rebase?"
GlobalLogic Ukraine
 
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic Ukraine
 
Страх і сила помилок - IT Inside від GlobalLogic Education
GlobalLogic Ukraine
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic Ukraine
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic Ukraine
 
“How to Secure Your Applications With a Keycloak?
GlobalLogic Ukraine
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Ukraine
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic Ukraine
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
GlobalLogic Ukraine
 

Recently uploaded (20)

PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
Software Development Methodologies in 2025
KodekX
 
Software Development Company | KodekX
KodekX
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 

Java Webinar #9: “Raspberry Pi Platform for Java Programmers”

  • 2. 2 Confidential Raspberry Pi Platform for Java Programmers Dmytro Ihnatiev Raspberry Pi Platform for Java Programmers 29.04.2021
  • 4. 4 Confidential What is Raspberry Pi • Single Board Computer • Linux Operating system - Raspbian • ARM Architecture • Low Cost • Low Power • Has the ability to interact with the outside world GPIO (used in a wide array of digital maker projects, from music machines and parent detectors to weather stations and tweeting birdhouses with infra-red cameras, etc.)
  • 5. 5 Confidential Raspberry Pi other models Raspberry Pi Pico Raspberry Pi 400 unit
  • 6. 6 Confidential Finding Compatible Hardware • Zillions of devices available • Search Amazon, Adafruit for Raspberry Pi devices • 3.3V or 5V, I2C, GPIO, Serial • “Hats” can be used to expand capability by stacking boards
  • 7. 7 Confidential Ground Pin, Power Pin, GPIO what is it? The Raspberry Pi 4 board has a GPIO header with 40 pins (amount could be different from model to model). Ground Pins The ground is very useful for making a common reference between all components in your circuit. Always remember to connect all components to the ground. Power Pins Those pins can be used to power components such as sensors or small actuators. GPIO GPIO means General Purpose Input/Output. Basically that’s one pin you can use to write data to external components (output), or read data from external components (input).
  • 10. 10 Confidential What is Pi4J? • Open Source Project • Raspberry Pi Platform (Linux/ARM) • Abstraction over Low Level I/O • Supports I/O Programming • Object-oriented API • Event Based • Java / C (JNI + Native) • Provides Listeners , Triggers & Component API • Provides Java Classes supporting I/O Operations
  • 11. 11 Confidential Brief history of Pi4J The Pi4J Project was started in 2012, the same year the Raspberry Pi was introduced as a tool to provide Java developers a simple and familiar object-oriented interface library to access the low-level I/O capabilities of the Raspberry Pi including GPIO, I2C, SPI, PWM and Serial communications.
  • 12. 12 Confidential Version 1.4 of Pi4J The original library which started in 2012 and got a last release in 2021. Up till version 1.3 the library targets Java 8, while version 1.4 relies on Java 11. Main features: • 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
  • 13. 13 Confidential Version 2 of Pi4J As of Version 2.0, Pi4J will no longer include support for peripheral devices and add-on chipsets/boards as part of the core project. A new plugin model has been introduced in version 2.0 that should help enable third-party development and support third-party add-ons which may be developed and maintained independently of the core Pi4J project. Main features: • Fluent APIs/Interfaces • Immutable Runtime Context • Extensible Provider/Platform/Plug-in Architecture • Builder-patterns for creating new I/O instances • Dependency Injection via Pi4J Annotations • Well-documented source code • Hardware PWM Support • Remote I/O Support (via TCP/IP) • Java 11 • In addition to the features listed above, Pi4J version 2.0 also abandons the old WiringPi pin numbering scheme in favor of the more traditional and commonly used Broadcom pin numbering scheme.
  • 14. 14 Confidential Version 2 of Pi4J As of Version 2.0, Pi4J will no longer include support for peripheral devices and add-on chipsets/boards as part of the core project. A new plugin model has been introduced in version 2.0 that should help enable third-party development and support third-party add-ons which may be developed and maintained independently of the core Pi4J project. Main features: • Fluent APIs/Interfaces • Immutable Runtime Context • Extensible Provider/Platform/Plug-in Architecture • Builder-patterns for creating new I/O instances • Dependency Injection via Pi4J Annotations • Well-documented source code • Hardware PWM Support • Remote I/O Support (via TCP/IP) • Java 11 • In addition to the features listed above, Pi4J version 2.0 also abandons the old WiringPi pin numbering scheme in favor of the more traditional and commonly used Broadcom pin numbering scheme.
  • 15. 15 Confidential GPIO Programming with Pi4J • Hardware Pins to Motorola Broadcom chipset numbering • Physical pin locations can change between board revisions • Pi4J can use Broadcom or WiringPi numbering schemes • Input or Output Pins • High (3.3 VDC) or Low (0 VDC) States • Outputs used to control things like relays, lights, motors, bells, etc. • Pullup and Pulldown resistors
  • 16. 16 Confidential Main design classes (Pi4J 1.4) • Listeners. Provides the ability to react on events from triggers • Triggers. Create an event on state change • Components (Deprecated in Pi4J 2.0) Other Components • Pull up and Pull down Resistors • Toggle output and handy methods to access pins and change their states
  • 17. 17 Confidential Pull up and Pull Down resistors The pull-down resistor pulls the voltage down to zero. If the pull-up switch is pressed, it pulls the voltage up to whatever the + supply is. The pull-up resistor pulls the voltage up to whatever the + supply is. If the pull-down switch is pressed, it pulls the voltage down to zero.
  • 18. 18 Confidential GPIO Output Circuit Example GpioController gpio = GpioFactory.getInstance(); GpioPinDigitalOutput output = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_12, PinState.LOW); output.high(); // set to high state output.low(); // set to low state output.toggle(); // switch to other state output.pulse(1000); // set state for a duration
  • 19. 19 Confidential GPIO Input Circuit Example GpioController gpio = GpioFactory.getInstance(); GpioPinDigitalInput input = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN); input.addListener((GpioPinListenerDigital) (GpioPinDigitalStateChangeEvent event) -> { System.out.println( "State = " + event.getState() + ", Edge = " + event.getEdge() + ", Pin = " + event.getPin() + ", Pressed = " + input.isHigh() ); } );
  • 20. 20 Confidential Resources • Pi4J - https://pi4j.com/1.2/index.html • GitHub Pi4J - https://github.com/Pi4J/pi4j • Pi4J 2.0 - https://pi4j.com/ • GPIO - https://www.raspberrypi.org/documentation/usage/gpio/README.md • WiringPi - http://wiringpi.com/ • Extensive support for many devices for many languages - https://github.com/ControlEverythingCom • Hardware Vendors (SeeedStudio Grove, Adafruit – Provides Python code for most of their hardware, Texas Instruments (sold by Mouser, DigiKey, etc.) • Pi Starter and Learning Kit Vendors (CanaKit, Adeept, etc.)