A simple program to understand how to work with Kotlin Native to access GPIO pins on a Raspberry Pi. It also features a Ktor-based web interface in addition to just using
curl
. Developed using JetBrains Fleet.
KPi.Blinkt is a sample how to use Kotlin Native on a Raspberry Pi to access and control attached Blinkt HATs using the GPIO connector. It's build on top of the ktgpio library.
In many parts, this is a port of my HomeBear.Blinkt Windows 10 IoT C# app I wrote times ago. I used in a few cases ChatGPD to convert my C# code into Kotlin one which worked very well.
- Kpi.Blinkt! - Controlling a Pimoroni Blinkt! HAT
- Kpi.Enviro - Reading sensor values from a Pimoroni Enviro pHAT
Service | Status |
---|---|
GitHub |
- 64bit Raspberry Pi (Model 3B and later)
- Pimoroni Blinkt! Raspberry Pi HAT with 8x APA102 pixels
- Windows, Mac or Linux host
- Installed SSH client, mostly build into the host OS
- Raspbian 64bit or other Raspberry Pi OS with GPIO libaries
- JetBrains Fleet, IntelliJ (Community) or similar to edit Kotlin code
Open the build_deploy.start.sh
file, edit PI_HOST
property and click the play symbol on the first line of the file.
- Project setup
- Deployment to a Pi using a convenient shell script
- Control APA102 based LEDs using Kotlin functions
- Add "plugin"-system for light modes
- Control LEDs using remote computer's
curl
commands - Control LEDs using a simple web interface
After booting up the app, you can connect to http://pi:8080/
and control the Blinkt! HAT using your browser.
After the server has been started, the following commands are available:
# Turn off all the things
curl -X POST http://pi:8080/on
curl -X POST http://pi:8080/off
# Light mode sample
# See `turnLightMode` for more supported ids
curl -X POST http://pi:8080/lightmode -d "red"
curl -X POST http://pi:8080/lightmode -d "rainbow"
curl -X POST http://pi:8080/lightmode -d "cycle"
# Morse word
curl -X POST http://pi:8080/morse -d "hello"
# System shutdown
curl -X POST http://pi:8080/shutdown
- Hackster.io: KBlinkt! - Kotlin Native program to control a Blinkt! HAT
- Dr. Windows: Wir basteln blinkende Lichter mit dem Raspberry Pi und Kotlin Native
Feel free to improve the quality of the code. It would be great to learn more from experienced Kotlin and IoT developers.
- Me (Tobi) as main developer
- Sebastian Aigner from JetBrains for fixing his own name
BitSpittle, CharLEE, Clovis and TheDome from the Kobweb Discord to support Kotlin beginners like me. As well as Sebastian Aigner from JetBrains to get me back into Kotlin with his Twitch Streams.
This project is licensed under the MIT License - see the LICENSE file for details. Dependencies or assets maybe licensed differently.