Skip to content

tscholze/kotlin-kpi-native-blinkt

Repository files navigation

Kpi.KBlinkt

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.

tl;dr

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.

Other KPi projects

  • Kpi.Blinkt! - Controlling a Pimoroni Blinkt! HAT
  • Kpi.Enviro - Reading sensor values from a Pimoroni Enviro pHAT

Build status

Service Status
GitHub Gradle build

Required Hardware

  • 64bit Raspberry Pi (Model 3B and later)
  • Pimoroni Blinkt! Raspberry Pi HAT with 8x APA102 pixels

Required Software

  • 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

How to run

Open the build_deploy.start.sh file, edit PI_HOST property and click the play symbol on the first line of the file.

Schema

Features

  • 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

Available web interface

After booting up the app, you can connect to http://pi:8080/ and control the Blinkt! HAT using your browser.

Available curl commands

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

How it looks

Please click to watch. Watch the video

Publications

Contributing

Feel free to improve the quality of the code. It would be great to learn more from experienced Kotlin and IoT developers.

Authors

Special thanks to

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.

License

This project is licensed under the MIT License - see the LICENSE file for details. Dependencies or assets maybe licensed differently.

About

Kotlin native application to control Pimoroni Blink HAT on a Raspberry

Topics

Resources

License

Stars

Watchers

Forks