Yellow Rabbit

Software Configuration Variant

Kotlin and GPIO in Raspberry Pi

Last time we calculated the electrical circuit and checked it on the breadboard. I had such an LED that we need to provide 4mA on any GPIO. Now it’s up to the software.

I have to say that I’m going to light the LED from Kotlin:smiley:


I specify USE flags just for reference, in most cases they are already so. We build Intellij for Raspberry Pi on a Linux machine, where Intellij is already installed.

 git clone


Screenshot of Intellij on Raspberry Pi


diff --git a/pigpio.c b/pigpio.c
index 710d20f..7e38063 100644
--- a/pigpio.c
+++ b/pigpio.c
@@ -13296,6 +13296,13 @@ unsigned gpioHardwareRevision(void)
                   pi_mem_flag  = 0x04;
+           // arm64 /proc/cpuinfo does not contain "model name"
+           if (!strncasecmp("CPU architecture: 8", buf, 19)) {
+                  piCores = 4;
+                  pi_peri_phys = 0x3F000000;
+                  pi_dram_bus  = 0xC0000000;
+                  pi_mem_flag  = 0x04;
+           }
          if (!strncasecmp("revision\t:", buf, 10))


Changing java.library.path on the fly

In order to use Jpigpio, or rather, I use a quick and dirty hack from Sun engineers:


import java.lang.reflect.Field;

public class AddDir {
    public static void addDir(String s) throws IOException {
        try {
            // This enables the java.library.path to be modified at runtime
            // From a Sun engineer at
            Field field = ClassLoader.class.getDeclaredField("usr_paths");
            String[] paths = (String[])field.get(null);
            for (int i = 0; i < paths.length; i++) {
                if (s.equals(paths[i])) {
            String[] tmp = new String[paths.length+1];
            tmp[paths.length] = s;
            System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + s);
        } catch (IllegalAccessException e) {
            throw new IOException("Failed to get permissions to set library path");
        } catch (NoSuchFieldException e) {
            throw new IOException("Failed to get field handle to set library path");


The actual creation of the project in Intellij is quite straightforward. I do not think there will be any difficulties, but just in case I took a few screenshots. What could I forget? A couple of commands in the console:

mkdir -p src/main/kotlin src/main/java libs
ln -s ~/local/lib/Pigpio.jar libs/

First program for Raspberry Pi

package io.github.yrabbit.kotlin.led

import jpigpio.JPigpio.*
import jpigpio.Pigpio
import jpigpio.PigpioException
import jpigpio.Utils

fun main(args: Array<String>) {
    // dirty hack: need to point java.library.path to the location of

    println("Kotlin Raspberry Pi gentoo64")
    println("You must see a blinking universe :)")
    try {
        // Init lib
        val pigpio = Pigpio()

        // Mode output
        pigpio.gpioSetMode(LED_PIN, PI_OUTPUT)

        repeat(3) {
            // ON
            pigpio.gpioWrite(LED_PIN, PI_HIGH)
            pigpio.gpioDelay(500 * 1000)
            // OFF
            pigpio.gpioWrite(LED_PIN, PI_LOW)
            pigpio.gpioDelay(500 * 1000)
    } catch(e: PigpioException) {
    pigpio.gpioSetMode(LED_PIN, PI_INPUT)

const val LED_PIN = 26 // GPIO26

Connect to Raspberry Pi

Breadboard: Breadboard

Reality: Real Raspberry Pi connection and breadboard


Run the resulting JAR: Start

Well, isn’t it cool? I’m happy :smile:

  1. This is necessary to add fast indexing of files to Idea. About this after. 

  2. The directory must exist.