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.
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.
- Kpi.Blinkt! - Controlling a Pimoroni Blinkt! HAT
- Kpi.Enviro - Reading sensor values from a Pimoroni Enviro pHAT
Service | Status |
---|---|
GitHub Action |
- 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
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.
- A BMP280 temperature/pressure sensor
- A TCS3472 colour sensor, for detecting the amount and colour of light
- Two white LEDs
- Python: Enviro GDocs Logger
- Python: Enviro Excel Logger
# ------------------------------------------ #
# 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
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.
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!
This is a time-by-time sparetime project for myself. That means, no contribution is necessary but welcomed.
Just me, Tobi.
- Phil for helping me to understand some "magic" numbers in the calculations
- Jo for helping me getting my bit overflows correct
This project is licensed under the MIT License - see the LICENSE file for details. Dependencies or assets maybe licensed differently.