Tips & Tricks for Raspberry PI

Raspberry PI specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Tips & Tricks for Raspberry PI

Post by mk-soft »

Tips and Tricks for Raspberry PI

Purebasic IDE
- Purebasic-IDE runas sudo from desktop icon (mk-soft)
- Add PureBasic IDE to Start Menu Development from LXpanel (mk-soft)

System Info
- CPU Temperatur (mk-soft)
- Get Machine ID (Rings)
- Get Linux Version (Rings)

IO System
- Port Audio Example (idle)
Last edited by mk-soft on Sun Mar 06, 2022 2:53 pm, edited 4 times in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Tips & Tricks for Raspberry PI

Post by mk-soft »

CPU Temperatur

Code: Select all

;-TOP by mk-soft, v1.01.1, 18.12.2021

#fileTemp = "/sys/class/thermal/thermal_zone0/temp"

Procedure.f get_cpu_temp()
  Protected r1.f, file, temp.s
  
  file = ReadFile(#PB_Any, #fileTemp)
  If file
    temp = ReadString(file, #PB_UTF8)
    CloseFile(file)
    r1 = 0.001 * Val(temp)
  Else
    r1 = 99.0
  EndIf
  ProcedureReturn r1
EndProcedure

For i = 1 To 5
  Debug get_cpu_temp()
  Delay(1000)
Next
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
idle
Always Here
Always Here
Posts: 5089
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Tips & Tricks for Raspberry PI

Post by idle »

Great my pi is running at 58c
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Tips & Tricks for Raspberry PI

Post by jack »

58c, isn't it a bit high?
do you have a heat-sink/fan installed?
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Tips & Tricks for Raspberry PI

Post by mk-soft »

No,
I have a fan and it only switches the regulation on at 60°C and off at 50°C.

Small App CPU Temperature on Systray
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Kiffi
Addict
Addict
Posts: 1357
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Tips & Tricks for Raspberry PI

Post by Kiffi »

<OT>
The average temperature of my RasPi running HomeAssistant is 40°C.
</OT>
Hygge
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Tips & Tricks for Raspberry PI

Post by Marc56us »

My Pi (Model 2B V1.1) running as NAS so in console mode, no enclosure, no fan: temperature 38° c
(Electronics do not wear out, but they age faster when they are too hot. Prefer large (metal) cases with lots of (passive) ventilation(s))

For console mode of mk-soft' version: I have changed line 20 (Debug) to: PrintN(Str(get_cpu_temp()))

:wink:
User avatar
idle
Always Here
Always Here
Posts: 5089
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Tips & Tricks for Raspberry PI

Post by idle »

@Jack Yes probably is a bit high there's no heat sink and it's an a plastic box.
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Tips & Tricks for Raspberry PI

Post by Joris »

My PI3 with a HIFI-Berry board and a MIDI interface connected runs at 54°C, only VNC server (always) active.
Temperature wend to 80°C (red icon) when i ran a full screen movie in VLC and did, at the same time, a download at 1MB/sec.
This never gave any problems and only now I can see the temperature.
No heatsink and all in a plastic box.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Tips & Tricks for Raspberry PI

Post by mk-soft »

I am still a beginner, but you can run the Raspberry without a heat sink. The PI 4 says that the Tackt frequency is taken down and 90 ° C is still no problem.
Have only the Systray the Tempertur limit for red set to 80 ° C.

At Joy-IT I have seen a mini heat sink set (3 pieces). Could fit even without a fan.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Tips & Tricks for Raspberry PI

Post by mk-soft »

Purebasic-IDE runas sudo

Some needs root right for hardware access. Her now a desktop file to start direct as sudo

Save as PB_Sudo.desktop in folder Desktop
[Desktop Entry]
Type=Application
Icon=/home/pi/Apps/purebasic/logo.png
Name=PB v6.00 (sudo)
Comment=Developer Utility
Exec=sudo /home/pi/Apps/purebasic/compilers/purebasic
Path=/home/pi/Apps/purebasic/compilers
StartupNotify=false
Terminal=false
Name[de_DE]=PB v6.0 (sudo)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Rings
Moderator
Moderator
Posts: 1427
Joined: Sat Apr 26, 2003 1:11 am

get a unique id from the raspberry,

Post by Rings »

Code: Select all

;get a unique id from the raspberry, 
;S.Rings 2021-12-28

Procedure.s get_machine_id()
  Protected  file, temp.s
  
  file = ReadFile(#PB_Any, "/etc/machine-id")
  If file
    temp = ReadString(file, #PB_UTF8)
    CloseFile(file)
  Else
  EndIf
  ProcedureReturn temp
EndProcedure

Debug get_machine_id()
SPAMINATOR NR.1
User avatar
Rings
Moderator
Moderator
Posts: 1427
Joined: Sat Apr 26, 2003 1:11 am

get linux version from the raspberry

Post by Rings »

Code: Select all

;get linux version  from the raspberry, 
;S.Rings 2021-12-28

Procedure.s get_linuxversion()
  Protected  file, temp.s
  
  file = ReadFile(#PB_Any, "/etc/os-release")
  If file
    temp = ReadString(file, #PB_UTF8)
    CloseFile(file)
  Else
  EndIf
  If Len(temp)>0 
    temp=Mid(temp,14,Len(temp)-14)
  EndIf
    
  ProcedureReturn temp
EndProcedure

Debug get_linuxversion()
SPAMINATOR NR.1
User avatar
idle
Always Here
Always Here
Posts: 5089
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: get linux version from the raspberry

Post by idle »

Rings wrote: Tue Dec 28, 2021 7:26 pm
Raspbian GNU/Linux 11 (bullseye)
User avatar
idle
Always Here
Always Here
Posts: 5089
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Tips & Tricks for Raspberry PI

Post by idle »

PortAudio example (mixing c with PB)

Code: Select all

;sudo apt-get install portaudio19-dev

ImportC "-lportaudio" : EndImport 
!#include "/usr/include/portaudio.h"  

Structure paTestData
  left_phase.f;
  right_phase.f;
EndStructure

Global *stream;
Global err 
Global num_seconds= 4;
Global sample_rate = 44100;
Global *output
Global mData.PaTestData 

;** This routine will be called by the PortAudio engine when audio is needed.
;** It may called at interrupt level on some machines so don't do anything
;** that could mess up the system like calling malloc() Or free().
Procedure patestCallback(*inputBuffer,*outputBuffer,framesPerBuffer,*timeInfo,statusFlags,*userData.paTestData)
  
  *out.float = *outputBuffer;
  
  Protected i
  
  For i=0 To framesPerBuffer
    *out\f = *userData\left_phase;  /* left */
    *out+4
    *out\f = *userData\right_phase;  /* right */
    *out+4
    ;/* Generate simple sawtooth phaser that ranges between -1.0 And 1.0. */
    *userData\left_phase + 0.01
    ;/* When signal reaches top, drop back down. */
    If *userData\left_phase >= 1.0 
      *userData\left_phase - 1.0
    EndIf   
    ;higher pitch so we can distinguish left And right. */
    *userData\right_phase + 0.03
    If *userData\right_phase >= 1.0
      *userData\right_phase = -1.0;
    EndIf
    
  Next   
EndProcedure ;

Global paCallback = @patestCallback()     

Debug "PortAudio Test: output sawtooth wave."

!v_err = Pa_Initialize(); 
If err <> 0
  Goto error;
EndIf   

!v_err = Pa_OpenDefaultStream(&p_stream,0,2,paFloat32,v_sample_rate,16,v_pacallback,&v_mdata); 
If err <> 0 
  Goto error;
EndIf  

!v_err = Pa_StartStream(p_stream);
If err <> 0
  Goto error;
EndIf   

!Pa_Sleep(v_num_seconds*1000);
!v_err = Pa_StopStream(p_stream );
If err <> 0 
  Goto error;
EndIf   

!v_err = Pa_CloseStream(p_stream);
If err <> paNoError 
  Goto error;
EndIf   

!Pa_Terminate();
Debug "Test finished"
End  

error:
!Pa_Terminate();
Debug "An error occured while using the portaudio stream"
Debug "error number " + Str(err) 
!p_output = Pa_GetErrorText(v_err);
Debug PeekS(*out,-1,#PB_UTF8) 


Post Reply