Page 1 of 2
Tips & Tricks for Raspberry PI
Posted: Sat Dec 18, 2021 8:45 pm
by mk-soft
Re: Tips & Tricks for Raspberry PI
Posted: Sat Dec 18, 2021 8:46 pm
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
Re: Tips & Tricks for Raspberry PI
Posted: Mon Dec 20, 2021 9:30 am
by idle
Great my pi is running at 58c
Re: Tips & Tricks for Raspberry PI
Posted: Mon Dec 20, 2021 12:56 pm
by jack
58c, isn't it a bit high?
do you have a heat-sink/fan installed?
Re: Tips & Tricks for Raspberry PI
Posted: Mon Dec 20, 2021 1:29 pm
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
Re: Tips & Tricks for Raspberry PI
Posted: Mon Dec 20, 2021 1:42 pm
by Kiffi
<OT>
The average temperature of my RasPi running HomeAssistant is 40°C.
</OT>
Re: Tips & Tricks for Raspberry PI
Posted: Mon Dec 20, 2021 2:39 pm
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()))

Re: Tips & Tricks for Raspberry PI
Posted: Mon Dec 20, 2021 7:18 pm
by idle
@Jack Yes probably is a bit high there's no heat sink and it's an a plastic box.
Re: Tips & Tricks for Raspberry PI
Posted: Wed Dec 22, 2021 12:13 pm
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.
Re: Tips & Tricks for Raspberry PI
Posted: Wed Dec 22, 2021 1:18 pm
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.
Re: Tips & Tricks for Raspberry PI
Posted: Wed Dec 22, 2021 1:31 pm
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)
get a unique id from the raspberry,
Posted: Tue Dec 28, 2021 6:48 pm
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()
get linux version from the raspberry
Posted: Tue Dec 28, 2021 7:26 pm
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()
Re: get linux version from the raspberry
Posted: Tue Dec 28, 2021 9:51 pm
by idle
Rings wrote: Tue Dec 28, 2021 7:26 pm
Raspbian GNU/Linux 11 (bullseye)
Re: Tips & Tricks for Raspberry PI
Posted: Thu Jan 06, 2022 1:20 am
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)