Option to get a LCD display on every DietPi device

Guides and tutorials for various stuff. Posted by DietPi users.
Post Reply
User avatar
k-plan
Posts: 416
Joined: Sun Feb 28, 2016 4:28 pm

Option to get a LCD display on every DietPi device

Post by k-plan »

Hi,

I stumble across a solution, to get a working LCD display for system status messages on every DietPi device with a free USB slot.

You only need a Odroid-Show2 and one script.
No driver installation, no pin header, no extra PSU.
NanoPi-Neo with Odroid-Show2
NanoPi-Neo with Odroid-Show2
Credits go to Igor Kromin. Nice job, thanks!
Here is the description on his website:
https://www.igorkromin.net/index.php/20 ... oid-show2/

You can find the code and script on his github page: https://github.com/ikromin/misc/tree/ma ... roid_show2

Have playing around a little bit with this script and customise it for my test devices (e.g. NanoPi Neo).


Here is my script example from NanoPi Neo which is shown on screen above:

Code: Select all

#!/bin/bash

# Updates the status of the DietPi OS on the odroid-show2
# based on https://github.com/Fourdee/DietPi/blob/master/dietpi/dietpi-cloudshell
# ANSI codes from: http://odroid.com/dokuwiki/doku.php?id=en:show_using&s[]=ansi
# Code by Igor Kromin - https://github.com/ikromin/misc/tree/master/dietpi/odroid_show2


#Force en_GB Locale for whole script. Prevents incorrect parsing with non-english locales.
LANG=en_GB.UTF-8


TTY_V2="/dev/ttyUSB0"
TMP_FILE="/tmp/status"
COLOR_HEADING="[32m"
COLOR_TEXT="[37m"
COLOR_VERSION="[33m"
BG_COL="[41m"
BG_DEF="[49m"

function tty_echo2 {
        printf "%s" "$1" >> $TMP_FILE
}

function tty_echo {
        printf "%s\n" "$1" >> $TMP_FILE
}

function tty_cmd {
        echo -ne "\e$1" >> $TMP_FILE
}

# reset tmp file
rm -f $TMP_FILE

# init TTY
stty -F $TTY_V2 500000
sleep 0.2

# reset screen and turn display output
tty_cmd [2J
tty_cmd [40m
tty_cmd [2s
tty_cmd [3r

HW_MODEL=$(sed -n 1p /DietPi/dietpi/.hw_model)


# cpu frequency (average frequency)
CPU_FREQ_1=$(( $(cat /sys/devices/system/cpu/cpu[0-3]/cpufreq/scaling_cur_freq|awk '{s+=$1} END {print s}') / 4000 ))
CPU_FREQ_2=$(( $(cat /sys/devices/system/cpu/cpu[0-3]/cpufreq/cpuinfo_max_freq|awk '{s+=$1} END {print s}') / 4000  ))
#CPU_FREQ_2="N/A"
if (( $HW_MODEL == 11 )); then
        CPU_FREQ_2=$(( $(cat /sys/devices/system/cpu/cpu[4-7]/cpufreq/scaling_cur_freq|awk '{s+=$1} END {print s}') / 4000 ))
fi

# DietPi Version
# tty_cmd $BG_COL
tty_cmd $COLOR_VERSION
tty_echo "*  DietPi - V`cat /DietPi/dietpi/.version`  *"
# tty_cmd $BG_DEF
tty_echo

# host name
tty_cmd $COLOR_HEADING
#tty_echo "`sed -n 2p /DietPi/dietpi/.hw_model `"
tty_echo "`hostname`"

# IP Address IPv4
tty_cmd $COLOR_TEXT
tty_echo "IP: `/sbin/ifconfig -a|grep \"inet addr\"|grep -v \"127.0.0.1\"|grep -v \"10.8.0.1\"|awk -F: '{print $2}'|cut -d\  -f1`"
tty_echo

# CPU Information
tty_cmd $COLOR_HEADING
tty_echo "CPU Information"
tty_cmd $COLOR_TEXT

# CPU Temperature
CPU_TEMP=$(/DietPi/dietpi/dietpi-cpuinfo 1)

if [[ $CPU_TEMP =~ ^-?[0-9]+$ ]]; then

        #Obtain colour for temps
        if (( $CPU_TEMP >= 60 )); then
                C_CPUTEMP="[31m"
        elif (( $CPU_TEMP >= 50 )); then
                C_CPUTEMP="[33m"
        elif (( $CPU_TEMP >= 40 )); then
                C_CPUTEMP="[33m"
        else
                C_CPUTEMP="[36m"
        fi
fi

tty_cmd $C_CPUTEMP
tty_echo2 "${CPU_TEMP} C"
tty_cmd [37m

# CPU usage
tty_echo2 " `top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 | awk '{print $2+$4+$6}'`% "
tty_echo "@ ${CPU_FREQ_1}|${CPU_FREQ_2} Mhz"
tty_echo

# Disks usage
tty_cmd $COLOR_HEADING
tty_echo "Disk Usage"
tty_cmd $COLOR_TEXT
tty_echo "`df -h -x tmpfs|sort -r|grep /dev/|awk '{printf \"%-4s of %-5s %s\n\", $5, $2, $1}'|sed -e \"s|/dev/||\"`"
tty_echo

# Time and Uptime
tty_cmd $COLOR_HEADING
tty_echo "`date +\"%d-%b-%Y   %R\"`"
tty_cmd $COLOR_TEXT
tty_echo "`uptime -p`"

# send output to odroid-show2
while read in; do echo -ne "$in\n" > $TTY_V2; sleep 0.2; done < $TMP_FILE

If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal and Bitcoin.

User avatar
Fourdee
Site Admin
Posts: 2789
Joined: Tue Feb 06, 2007 12:36 pm

Re: Option to get a LCD display on every DietPi device

Post by Fourdee »

k-plan wrote:Hi,

I stumble across a solution, to get a working LCD display for system status messages on every DietPi device with a free USB slot.

You only need a Odroid-Show2 and one script.
No driver installation, no pin header, no extra PSU.

Credits go to Igor Kromin. Nice job, thanks!
Here is the description on his website:
https://www.igorkromin.net/index.php/20 ... oid-show2/

You can find the code and script on his github page: https://github.com/ikromin/misc/tree/ma ... roid_show2

Have playing around a little bit with this script and customise it for my test devices (e.g. NanoPi Neo).
Looks awesome, great find! :)

EDIT: Sticked thread
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal, Bitcoin or become a DietPi patron.

User avatar
k-plan
Posts: 416
Joined: Sun Feb 28, 2016 4:28 pm

Update: Option to get a LCD display on every DietPi device

Post by k-plan »

.
Update:
- Picture from working device and script example added to first posting

Post Reply