Page 1 of 1

Simple Temp monitor example using LCDLabel

Posted: Thursday 17th September 2020 8:09pm
by BruceSteers
This is a simple text based temperature display using LCDLabel
Made as an example it is simple and has many descriptive comments.

Gets temperature in one of 3 ways,
Either runs a command and uses it's direct output or
loads a temp file that stores the temperature as a simple number being the temperature X 1000

For raspberry pi many other systems simply give it the file path...
'/sys/class/thermal/thermal_zone0/temp'

Auto-detect checks ALL /sys/class/thermal zones and reports the hottest one found.

or it can use a shell command like sensors (from package lm-sensors) with grep and awk to get the temperature text.
Use 'sudo apt-get install lm-sensors' or use your package manager to install.

Command Example...

Code: Select all

sensors|grep 'Core 0'|awk '{print $3}'
The above command runs 'sensors', uses grep to find the line with 'Core 0' in it that for me looks like this...
Core 0: +45.0°C (high = +82.0°C, crit = +100.0°C)

and then uses awk to get the 3rd bit of text '+45.0°C' (space separation makes 'Core 0:' 2 words)

Written in Gambas basic
Code has FULL comments explaining everything.
Has a minimum-requirement-installer to install required gambas components.

Other features...
Change background / text and highlight colour
Set Time delay between checks.
Show/Hide Window border/titlebar
Drag-Move/resize window

Bruce

(Note this is version 1.2 , scroll down for updated version 1.4)

Re: Simple Temp monitor example using LCDLabel

Posted: Monday 19th September 2022 2:03pm
by BruceSteers
updated this to auto-detect temp reading and resize window is possible.

Re: Simple Temp monitor example using LCDLabel

Posted: Tuesday 20th September 2022 9:19am
by cogier
I am looking at the program and I think an option to display what the temperature relates to would be helpful. The display shows 52.0 then 44.0 and that's it. What is 52 or 44?

The program icon is missing.

Image

EDIT: -

I thought this might be fun, so I have made a simple version of this: -
' Gambas class file

'' Needs lm-sensors
'' sudo apt-get -y install lm-sensors

Timer1 As Timer
LCDLabel1 As LCDLabel
HBox1 As HBox
Label1 As Label
Button1 As Button
iCount As Integer
sCmd As String = "sensors"

Public Sub Form_Open()

  BuildForm
  Timer1.Trigger

End

Public Sub Timer1_Timer()

  Dim iStart, iLen As Integer
  Dim sSensors As String
  Dim iLoop As Integer
  Dim sValues As String[]

  Shell sCmd To sSensors
  sValues = Split(sSensors, gb.NewLine, "", True)

  For iLoop = sValues.Max To 0 Step -1
    If InStr(sValues[iLoop], "Core") = 0 Then sValues.Delete(iLoop, 1)
  Next

  iStart = InStr(sValues[iCount], "+") + 1
  iLen = InStr(sValues[iCount], " ", iStart) - iStart

  Label1.Text = Split(sValues[iCount], ":")[0]
  LCDLabel1.Text = Mid(sValues[iCount], iStart, iLen)

  Inc iCount
  If iCount > sValues.Max Then iCount = 0

End

Public Sub Button1_Click()

  If sCmd = "sensors" Then
    sCmd = "sensors -f"
  Else
    sCmd = "sensors"
  Endif
  Timer1.Trigger

End

Public Sub BuildForm()

  With Me
    .Height = 400
    .Width = 875
    .Padding = 5
    .Arrangement = Arrange.Vertical
    .Center
    .Icon = Picture["icon:/24/hue"]
  End With

  With HBox1 = New HBox(Me) As "HBox1"
    .Height = 35
    .Width = 100
  End With

  With Label1 = New Label(HBox1) As "Label1"
    .Height = 35
    .Alignment = Align.Center
    .Font.Size = 16
    .Font.Bold = True
    .Expand = True
    .Border = Border.Plain
  End With

  With Button1 = New Button(HBox1) As "Button1"
    .Height = 35
    .Width = 35
    .Text = "F/C°"
  End With

  With LCDLabel1 = New LCDLabel(Me) As "LCDLabel1"
    .Padding = 20
    .Sheared = True
    .Background = Color.Black
    .Foreground = Color.Black
    .HighlightColor = Color.Green
    .Expand = True
  End With

  With Timer1 = New Timer As "Timer1"
    .Delay = 3000
    .Enabled = True
  End With

End

Re: Simple Temp monitor example using LCDLabel

Posted: Tuesday 27th September 2022 1:02pm
by BruceSteers
I've updated the program in the first post to have a settings window to select sensor method
also updated the tooltips to show details about the sensor reading (as shown in pic)


hehe yeah a simple version is simple enough but i had to have some features ,
like i had to import and edit the LCDLabel.class just so i could adjust the LCD base colour (the not lit up bits)

This started as a simple example but went a bit past that over time :roll:

Re: Simple Temp monitor example using LCDLabel

Posted: Wednesday 4th October 2023 3:35pm
by BruceSteers
Updates.....

Option to show on 2 screens. opens another window so you can have one on each screen.

As well as the temp you can set a Date Format string https://gambaswiki.org/edit/lang/format and set the font/size/color

optional colour mode , you can set a cold/warm/hot colour and the main lcd colour blends according to temperature. (there is a test slider on the colour settings page)

enable/disable autostart with system on boot

Screenshot shows both screens.
Untitled.jpg
Untitled.jpg (241.38 KiB) Viewed 3614 times

Re: Simple Temp monitor example using LCDLabel

Posted: Thursday 5th October 2023 10:59am
by cogier
It works well, nice job. My computer runs a lot hotter than yours, showing at around 60.00°.