Software Configuration Variant

586 words | 2018-3-17

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.

  • Install dev-java/icedtea (USE=”alsa cups gtk jbootstrap pch source sunec webstart”) both and on the Linux machine and on Raspberry Pi.
  • Download Intellij Community edition
 git clone

  • Set up our branch git checkout -b yr 1
  • Go to the official site and follow the instructions. Specify IcedTea for the JDK.
  • Run the compilation from the command line, if it requires JavaFX, then copy it from the existing Intellij.

  • Copy out/idea-ce/artifacts/ideaC-182.SNAPSHOT.tar.gz to Raspberry Pi and unpack there in some directory.

Screenshot of Intellij on Raspberry Pi


  • We get the sources of git clone
  • Apply the patch to detect Raspberry Pi in 64 bit mode:

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))

  • make
  • sudo make install
  • Check the success sudo ./x_pigpio Screenshot of pigpio test results


  • Download the sources
  • Edit JPigpio/Makefile and JPigpioC/Makefile changing LIBDIR to something like /home/user-name/local/lib2
  • Build and install with ./

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.