Simple Temp monitor example using LCDLabel

So you have written that new, must have program. Let us see it here.
Post Reply
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Simple Temp monitor example using LCDLabel

Post 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)
Attachments
MyTemp-1.2.tar.gz
(17.86 KiB) Downloaded 216 times
MyTemp.png
MyTemp.png (262.38 KiB) Viewed 6234 times
Last edited by BruceSteers on Tuesday 27th September 2022 12:53pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Simple Temp monitor example using LCDLabel

Post by BruceSteers »

updated this to auto-detect temp reading and resize window is possible.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Simple Temp monitor example using LCDLabel

Post 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
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Simple Temp monitor example using LCDLabel

Post 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:
Attachments
Untitled.png
Untitled.png (702.91 KiB) Viewed 6159 times
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Simple Temp monitor example using LCDLabel

Post 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 3617 times
Attachments
MyTemp-1.4.tar.gz
(90.83 KiB) Downloaded 104 times
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Simple Temp monitor example using LCDLabel

Post by cogier »

It works well, nice job. My computer runs a lot hotter than yours, showing at around 60.00°.
Post Reply