Skip to content

A program to understand how to work with Kotlin/Native to access GPIO and I2c pins on a Raspberry Pi with the Enviro pHAT attached. It also features a Ktor-based web interface.

License

Notifications You must be signed in to change notification settings

tscholze/kotlin-kpi-native-enviro

Repository files navigation

Logo

Kpi.Enviro

A program to understand how to work with Kotlin Native to access GPIO and I2c pins on a Raspberry Pi with the Enviro pHAT attached. It also features a Ktor-based web interface.

tl;dr

KPi.Enviro is part of the "K on Raspberry Pi" family and a sample how to use Kotlin Native on a Raspberry Pi (64bit) to access and control attached Pimoroni Enviro pHAT using the GPIO and IC2 pins. It's build on top of the ktgpio library. Not all sensors are used. The app accesses information of the BMP280 and TCS3472 chips.

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 Action Java CI with Gradle

Requirements

  • Pimoroni Enviro pHAT
  • Raspberry Pi 3B, 4, 5
  • Raspian or other 64bit Linux systems
  • Run sudo apt-get install libgpiod2 libi2c0
  • SSH connection to Raspberry Pi
  • Shell host for running toolchain *.sh scripts

Enviro pHAT information

The Pimoroni Enviro pHAT for Raspberry Pis is an environmental sensing board that lets you measure temperature, pressure, light, color and many more. Pimoroni provides a Python library for reference and checks if the Kotlin Native calculations are equal to these from the vendor.

Supported sensors and periphery

  • A BMP280 temperature/pressure sensor
  • A TCS3472 colour sensor, for detecting the amount and colour of light
  • Two white LEDs

My former Enviro pHAT projects

How it looks

Web

Web screenshot

Shell output

# ------------------------------------------ #
# Kotlin Native + Raspberry Pi + Enviro pHAT #
# ------------------------------------------ #

--- Environment reading START --
Temperature (C°): 26.891849822597578
Pressure (hPa): 963.1150683186409
Altitude (m): 489.22244179802976
--- Sample reading END ----

--- Ambient reading START --
Values in range of 0 to 255
Red: 124
Blue: 49
Green: 918.0
--- Ambient reading END ----

Press any key to quit server

Scheme

Scheme

Keep in mind

Calculations may be incorrect

In fact, the temperature will be incorrect in the means of that the sensor sits more or less directly on top of the CPU that warms the environment. The altitude is based on the QNH of Munich. If you are outside of Germany, the altitude calculation could be way off. Besides the placement, all values are tested but could be nevertheless incorrect. Please check algorithms and do never use these values for more than playing around with sensors.

Not production ready

This app is purely build for educational usage! All features have room for improvements or could be done more elegant. This app was and will be never meant to run in production-like environments. Learning is fun!

Contributing

This is a time-by-time sparetime project for myself. That means, no contribution is necessary but welcomed.

Authors

Just me, Tobi.

Special thanks to

  • Phil for helping me to understand some "magic" numbers in the calculations
  • Jo for helping me getting my bit overflows correct

License

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

About

A program to understand how to work with Kotlin/Native to access GPIO and I2c pins on a Raspberry Pi with the Enviro pHAT attached. It also features a Ktor-based web interface.

Topics

Resources

License

Stars

Watchers

Forks