Pi4J Kotlin DSL

Pi4J-Kotlin (aka Pi4K) is an implementation on top of Pi4J to facilitate the development of Kotlin applications for the Raspberry Pi that can interact with the GPIOs.

Kotlin makes extensive use of Domain Specific Language (DSL) to provide APIs that are cleaner, easier to read, and more structured. The DSLs provided here on top of Pi4J make it very easy to use this library in a Kotlin application. These Kotlin DSLs don’t introduce added runtime overhead of a new layer when used. DSL builders are always inlined on Compile-Time.


Install the Pi4J dependency and pi4j-ktx in your app’s build.gradle.ktx file:

dependencies {
    implementation("com.pi4j:pi4j-ktx:2.4.0") // Kotlin DSL

If you want to use the Console DSL to log with SLF4J, add the dependency:


GitHub projects:

  • Kotlin Interface & DSL for Pi4J V2: Pi4J-Kotlin
  • For Pi4J V1 Kotlin Bindings, check Pi4K