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
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.
dev-java/icedtea
(USE=”alsa cups gtk jbootstrap pch source sunec webstart”) both and on the Linux machine and on Raspberry Pi. git clone https://github.com/JetBrains/intellij-community.git
git checkout -b yr
1
ant -Dintellij.build.skip.build.steps=mac_artifacts,mac_dmg,mac_sign,windows_exe_installer
out/idea-ce/artifacts/ideaC-182.SNAPSHOT.tar.gz
to Raspberry Pi and unpack there in some directory.git clone https://github.com/joan2937/pigpio.git
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
sudo ./x_pigpio
https://github.com/nkolban/jpigpio.git
JPigpio/Makefile
and JPigpioC/Makefile
changing LIBDIR
to something like /home/user-name/local/lib
2
./build.sh
java.library.path
on the flyIn order to use Jpigpio, or rather libJPigpioC.so, I use a quick and dirty hack from Sun engineers:
package io.github.yrabbit.java.util;
import java.io.File;
import java.io.IOException;
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 http://forums.sun.com/thread.jspa?threadID=707176
//
Field field = ClassLoader.class.getDeclaredField("usr_paths");
field.setAccessible(true);
String[] paths = (String[])field.get(null);
for (int i = 0; i < paths.length; i++) {
if (s.equals(paths[i])) {
return;
}
}
String[] tmp = new String[paths.length+1];
System.arraycopy(paths,0,tmp,0,paths.length);
tmp[paths.length] = s;
field.set(null,tmp);
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/
package io.github.yrabbit.kotlin.led
import io.github.yrabbit.java.util.AddDir
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 libJPigpioC.so
AddDir.addDir("/usr/local/lib")
println("Kotlin Raspberry Pi gentoo64")
println("You must see a blinking universe :)")
try {
// Init lib
val pigpio = Pigpio()
pigpio.gpioInitialize()
Utils.addShutdown(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) {
e.printStackTrace()
}
pigpio.gpioSetMode(LED_PIN, PI_INPUT)
}
const val LED_PIN = 26 // GPIO26
Breadboard:
Reality:
Run the resulting JAR:
Well, isn’t it cool? I’m happy