Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tricks about Raspberry Pi #65

Open
AllanChain opened this issue Jan 21, 2020 · 0 comments
Open

Tricks about Raspberry Pi #65

AllanChain opened this issue Jan 21, 2020 · 0 comments
Labels
blog: programming @post This is a blog post tag: raspi |185748696-94767831-83ec-48fe-9bbb-5c7f89d4e9f8.png

Comments

@AllanChain
Copy link
Owner

AllanChain commented Jan 21, 2020

View Post on Blog

Handy tricks when playing with raspberry pi. You should know them.


Get the Temperature

cat /sys/class/thermal/thermal_zone0/temp

Outputs:

29482

And here is bash script to create temperature PS1

if [ -e /sys/class/thermal/thermal_zone0/temp ]; then
    temp=$(cat /sys/class/thermal/thermal_zone0/temp)
    if [ $temp -lt 30000 ]; then color=2
    elif [ $temp -lt 50000 ]; then color=3
    else color=1
    fi
    prompt_section $color "${temp::${#temp}-3}.${temp:${#temp}-3}"
fi

Adding a dot is just mixing bash substrings (${string:offset[:length]}) with bash string lengths (${#string})

vcgencmd

From https://www.raspberrypi.org/documentation/raspbian/applications/vcgencmd.md

To get all commands, use:

vcgencmd commands

Voltage

vcgencmd get_throttled

If voltage is okay, you will get 0x0

Else, say 0x50000, convert it to binary, and see each bit:

19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
 0  1  0  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
Bit Meaning
0 Under-voltage detected
1 Arm frequency capped
2 Currently throttled
3 Soft temperature limit active
16 Under-voltage has occurred
17 Arm frequency capping has occurred
18 Throttling has occurred
19 Soft temperature limit has occurred

Generally, the 3 0s in the middle do not have specific meaning. Just need to care about the first 5 and the last 0.

Screen on / off

When you start the Raspberry Pi with display / monitor / screen on, it will automatically turn on display power. If not, display power will never turn on even if you later connect it to a screen. So it is necessary to control the display power.

vcgencmd display_power 1

1 for on and 0 for off. bare vcgencmd display_power shows current state.

It is possible to specify a certain display ID. For more info, visit the doc above.

@AllanChain AllanChain changed the title General Tricks about Raspberry Pi | AC's Blog Tricks about Raspberry Pi Jun 24, 2020
@AllanChain AllanChain added blog: programming tag: raspi |185748696-94767831-83ec-48fe-9bbb-5c7f89d4e9f8.png labels Jun 24, 2020
@AllanChain AllanChain added the @post This is a blog post label Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog: programming @post This is a blog post tag: raspi |185748696-94767831-83ec-48fe-9bbb-5c7f89d4e9f8.png
Projects
None yet
Development

No branches or pull requests

1 participant