Resource-friendly NanoHat OLED and GPIO button control for Armbian.
Displays YouTube channel statistics (views, subs, videos) on a small SSD1306 OLED.
This project uses ideas and code from:
- https://github.com/crouchingtigerhiddenadam/nano-hat-oled-armbian
- https://github.com/Digilent/linux-userspace-examples
- https://github.com/OnionIoT/i2c-exp-driver
- https://github.com/Narukara/SSD1306
- https://android.googlesource.com/kernel/common/+/refs/heads/upstream-master/tools/gpio
- https://www.asciiart.eu
Edit:
sudo nano /boot/armbianEnv.txt
Add i2c0 to the overlays= line, e.g.:
overlays=i2c0 usbhost1 usbhost2
Save (ctrl+x, ctrl+y and enter) and reboot:
sudo reboot now
Install the dependencies from APT:
sudo apt -y install \
gcc \
git \
libssl-dev \
make \
python3
Clone from Github:
cd /tmp
git clone https://github.com/corazgrubszy/nanohat-oled.git
cd nanohat-oled/src
Do not edit yt.c. Generate src/yt_config.h with your own values:
./tools/gen_yt_config.py \
--channel-id "YOUR_CHANNEL_ID" \
--api-key "YOUR_API_KEY" \
--out src/yt_config.h \
--key 0x5A
Notes:
src/yt_config.his git-ignored (kept local).- Obfuscation key can be changed:
--key 0x5A. - See
src/yt_config.h.templatefor what gets generated. - If you don’t know your key/ID:
How to fetch statistics from YouTube API
make
Create the runtime directory:
sudo mkdir -p /usr/share/nanohatoled
Create the service unit:
sudo nano /etc/systemd/system/ytstats.service
Paste the following content:
[Unit]
Description=YouTube stats OLED display
After=network.target
[Service]
ExecStart=/usr/bin/nice -n 10 /usr/share/nanohatoled/ytstats
Restart=on-failure
User=root
[Install]
WantedBy=multi-user.target
Save the file and enable the service to start on boot:
sudo systemctl daemon-reexec
sudo systemctl enable ytstats.service
sudo systemctl start ytstats.service
The Makefile automates updates. It stops the service, copies the new binary, sets permissions, and starts the service again:
sudo make install
sudo make uninstall
make clean
sudo systemctl status ytstats.service
journalctl -u ytstats.service
This project does not use FriendlyElec's BakeBit / NanoHatOLED software. If it's installed, disable it:
sudo nano /etc/rc.local
Comment out the line:
# /usr/local/bin/oled-start
exit 0
Save and reboot:
sudo reboot now
- Service won’t start: run the binary by hand to see stderr:
/usr/share/nanohatoled/ytstats - No I²C device: confirm overlay and bus:
ls /dev/i2c-* # expect /dev/i2c-0 on NanoPi (after enabling i2c0) - TLS errors: ensure
libssl-devinstalled at build time; device has correct time (NTP) for TLS validation.
- Build:
make - Update service with new build:
sudo make install - Remove:
sudo make uninstall - Clean:
make clean
PRs welcome. Keep comments in English to help others reuse the code.