├── .travis.yml ├── LICENSE ├── README.md ├── changelog.txt ├── rpiv3tweak.sh ├── update.sh └── version.txt /.travis.yml: -------------------------------------------------------------------------------- 1 | language: bash 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Constantin Busuioceanu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raspberry Pi v3 Tweaker [![Build Status](https://travis-ci.org/cbusuioceanu/Raspberry-Pi-v3-Tweaker.svg?branch=master)](https://travis-ci.org/cbusuioceanu/Raspberry-Pi-v3-Tweaker) 2 | View Raspberry Pi 3 CPU Info - Clock speed - Temperatures - Voltage - Overclock you RPi - Change Governor & more 3 | 4 | ### How to use? 5 | 6 | ```git clone https://github.com/cbusuioceanu/Raspberry-Pi-v3-Tweaker.git && cd Raspberry-Pi-v3-Tweaker && sudo bash rpiv3tweak.sh ``` 7 | 8 | #### Smart Raspberry Pi 3 CPU Tweaker is a script written exclusively on a Raspberry Pi 3 device. 9 | 10 | #### In case of overclocking, we recommend using a Raspberry Pi cooling kit (heatsinks). 11 | 12 | #### With this script, you can do / watch / monitor the following: 13 | 14 | ##### -> CPU temperature 15 | ##### -> CPU Voltage 16 | ##### -> Minimum CPU speed 17 | ##### -> Maximum CPU speed 18 | ##### -> Current CPU speed 19 | ##### -> Sampling rate> if the CPU governor is "ondemand" 20 | ##### -> Sampling rate min (minimum sampling rate)> if the CPU governor is "ondemand" 21 | ##### -> Upper threshold (maximum CPU load threshold for recommended frequency increase, 50%)> if the CPU governor is "ondemand" 22 | ##### -> Transition latency (CPU speed change is done in x nano seconds) 23 | ##### -> CPU governor change (governor: performance, powersave, userspace, ondemand, conservative) 24 | ##### -> Overclocking 25 | ##### -> Change SWAP size 26 | ##### -> Check script updates from the main menu or update it from Git 27 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | 09032016 2 | - Initial version 3 | 09032016 4 | - Updated dependencies function 5 | 16072017 6 | - Code beautify 7 | - Added Informational VARS 8 | - Fixed error for sampling_rate_min VAR 9 | 04052019 10 | - Updated code 11 | - Added SWAP change functionality 12 | 25092020 13 | - Code cleaned 14 | - Small improvements 15 | -------------------------------------------------------------------------------- /rpiv3tweak.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Built on 9th March 2016 4 | # RPiv3Tweak - for Raspberry Pi 3 5 | # View Raspberry Pi 3 CPU Info - Clock speed - Temperatures - Voltage - Overclock you RPi - Change Governor & more 6 | # Run script with sudo bash raspiv3cputweak.sh 7 | # 8 | # Have fun tweaking your RPi 9 | # 10 | # Warning: by using this software (script), you understand that I can't be held 11 | # responsible for anything that may happen. 12 | # If you OC you RPi, I recommend using heatsinks!!! 13 | # NOTE: You MUST USE a good power supply with min 2.5A !!! 14 | 15 | # MIT License 16 | # Copyright (c) 2020 CONSTANTIN BUSUIOCEANU 17 | 18 | # Permission is hereby granted, free of charge, to any person obtaining a copy 19 | # of this software and associated documentation files (the "Software"), to deal 20 | # in the Software without restriction, including without limitation the rights 21 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 22 | # copies of the Software, and to permit persons to whom the Software is 23 | # furnished to do so, subject to the following conditions: 24 | 25 | # The above copyright notice and this permission notice shall be included in all 26 | # copies or substantial portions of the Software. 27 | 28 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 33 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 34 | # SOFTWARE. 35 | 36 | ### 37 | if [[ $EUID -ne 0 ]]; then 38 | echo "This script must be run with sudo" 39 | exit 1 40 | fi 41 | ### 42 | 43 | #### COLOR SETTINGS #### 44 | #BLACK=$(tput setaf 0 && tput bold) 45 | RED=$(tput setaf 1 && tput bold) 46 | GREEN=$(tput setaf 2 && tput bold) 47 | YELLOW=$(tput setaf 3 && tput bold) 48 | #BLUE=$(tput setaf 4 && tput bold) 49 | MAGENTA=$(tput setaf 5 && tput bold) 50 | CYAN=$(tput setaf 6 && tput bold) 51 | WHITE=$(tput setaf 7 && tput bold) 52 | #BLACKbg=$(tput setab 0 && tput bold) 53 | REDbg=$(tput setab 1 && tput bold) 54 | #GREENbg=$(tput setab 2 && tput bold) 55 | #YELLOWbg=$(tput setab 3 && tput bold) 56 | #BLUEbg=$(tput setab 4 && tput dim) 57 | #MAGENTAbg=$(tput setab 5 && tput bold) 58 | #CYANbg=$(tput setab 6 && tput bold) 59 | #WHITEbg=$(tput setab 7 && tput bold) 60 | STAND=$(tput sgr0) 61 | 62 | ### System dialog VARS 63 | show_info="${GREEN}[info]$STAND" 64 | show_error="${RED}[error]$STAND" 65 | show_execute="${YELLOW}[running]$STAND" 66 | show_ok="${MAGENTA}[OK]$STAND" 67 | show_input="${CYAN}[input]$STAND" 68 | show_warning="${RED}[warning]$STAND" 69 | ## 70 | 71 | version="09/25/2020" 72 | unixtime=$(date --date="$version" +"%s") 73 | #time=$(date +"%T") 74 | 75 | #### pause function 76 | function pause(){ 77 | read -r -e -p "$show_info Press enter to continue..." 78 | } 79 | 80 | #### Dependencies check 81 | 82 | function checkdependencies(){ 83 | 84 | if [[ -e /tmp/rpiv3tweak ]]; then 85 | echo "$show_info Checking dependencies: $show_ok" 86 | else 87 | echo "dependencies_OK" > /tmp/rpiv3tweak 88 | echo "$show_execute Checking dependencies..." 89 | 90 | #### check if xterm installation exists 91 | if command -v xterm > /dev/null; then 92 | echo "$show_ok [xterm]:$WHITE installation found..." 93 | else 94 | echo "$show_warning: This script requires xterm to work" 95 | echo "$show_execute Downloading from network..." 96 | apt-get install -y xterm 97 | fi 98 | #### 99 | 100 | #### check if vcgencmd installation exists 101 | if command -v vcgencmd > /dev/null; then 102 | echo "$show_ok [vcgencmd]:$WHITE installation found..." 103 | else 104 | echo "$show_warning: This script requires vcgencmd to work" 105 | echo "$show_execute Downloading from network..." 106 | apt-get update && apt-get upgrade && apt-get dist-upgrade 107 | fi 108 | ### 109 | echo "$show_info All dependencies ok..." 110 | fi 111 | } 112 | 113 | ### Check Frequency, Temp, Voltage, Governor 114 | function freqtempvolt() { 115 | 116 | function mhz_convert() { 117 | #let value=$1/1000 118 | #echo "$value" 119 | echo $(( $1 / 1000 )) 120 | } 121 | 122 | function overvoltdecimals() { 123 | #let overvolts=${1#*.}-20 124 | #echo "$overvolts" 125 | echo $(( ${1#*.} - 20 )) 126 | } 127 | 128 | temp=$(vcgencmd measure_temp) 129 | temp=${temp:5:4} 130 | 131 | volts=$(vcgencmd measure_volts) 132 | volts=${volts:5:4} 133 | 134 | if [[ $volts != "1.20" ]]; then 135 | overvolts=$(overvoltdecimals "$volts") 136 | fi 137 | 138 | ### VARS 139 | minFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq) 140 | minFreq=$(mhz_convert "$minFreq") 141 | maxFreq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) 142 | maxFreq=$(mhz_convert "$maxFreq") 143 | freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) 144 | freq=$(mhz_convert "$freq") 145 | governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) 146 | transitionlatency=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_transition_latency) 147 | ### 148 | 149 | if [[ $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) == ondemand ]]; 150 | then 151 | ### VARS 152 | samplingrate=$(cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate) 153 | upthreshold=$(cat /sys/devices/system/cpu/cpufreq/ondemand/up_threshold) 154 | ### 155 | 156 | echo "+------------------------------+" 157 | echo "| CPU Details |" 158 | echo "+------------------------------+" 159 | echo "Temperature: $temp C" 160 | 161 | if [[ $volts == "1.20" ]]; then 162 | echo "Voltage: $volts V" 163 | else 164 | echo -n "Voltage: $volts V" 165 | [ "$overvolts" ] && echo " (+0.$overvolts overvolt)" || echo -e "\\n" 166 | fi 167 | 168 | echo "Min speed: $minFreq MHz" 169 | echo "Max speed: $maxFreq MHz" 170 | echo "Current speed: $freq MHz" 171 | echo "Governor: $governor" 172 | echo "Sampling rate: $samplingrate" 173 | echo "Up threshold: $upthreshold" 174 | echo "Transition latency: $transitionlatency" 175 | echo "+------------------------------+" 176 | else 177 | echo "+------------------------------+" 178 | echo "| CPU Details |" 179 | echo "+------------------------------+" 180 | echo "Temperature: $temp C" 181 | 182 | if [[ $volts == "1.20" ]]; then 183 | echo "Voltage: $volts V" 184 | else 185 | echo -n "Voltage: $volts V" 186 | [ "$overvolts" ] && echo " (+0.$overvolts overvolt)" || echo -e "\\n" 187 | fi 188 | 189 | echo "Min speed: $minFreq MHz" 190 | echo "Max speed: $maxFreq MHz" 191 | echo "Current speed: $freq MHz" 192 | echo "Governor: $governor" 193 | echo "Transition latency: $transitionlatency" 194 | echo "+------------------------------+" 195 | fi 196 | pause 197 | } 198 | 199 | ### Change GOVERNOR settings 200 | function changegovernor() { 201 | 202 | ### VARS 203 | affected_cpus=$(cat /sys/devices/system/cpu/cpu0/cpufreq/affected_cpus) 204 | available_governors=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors) 205 | current_governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) 206 | ### 207 | 208 | echo -e "\\n$show_info Current CPU governor is:$GREEN $current_governor $STAND" 209 | echo "$show_info Affected cpus:$GREEN $affected_cpus $STAND" 210 | echo "$show_info Available CPU governors:$RED $available_governors $STAND" 211 | read -r -e -p "$show_input Enter desired governor (x to cancel): " ch_governor 212 | 213 | if [[ $ch_governor == "x" ]]; 214 | then 215 | echo "$show_execute Going back to main menu." && sleep 1 216 | else 217 | sudo sh -c "echo $ch_governor > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" 218 | echo -e "$show_info Governor changed to:$RED $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)\\n${STAND}" 219 | 220 | if [[ $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) == ondemand ]]; 221 | then 222 | echo "Ondemand governor set. You can change sampling_rate and up_threshold for better performance." 223 | echo "Current sampling_rate=$GREEN $(cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate)${STAND}" 224 | 225 | echo "According to Kernel Documentation, sampling_rate should get adjusted considering the transition latency." 226 | echo "The default model looks like this: cpuinfo_transition_latency * 1000 / 1000 = sampling_rate" 227 | 228 | echo "The next operation will do this for you. For example, we can choose 750" 229 | read -r -e -p "$show_input Enter value: " sampling_rate_value 230 | sudo sh -c "echo $(($(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_transition_latency) * sampling_rate_value / 1000)) > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate" 231 | echo "sampling_rate changed to:$RED $(cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate)${STAND}" 232 | 233 | echo -e "Current up_threshold=$GREEN $(cat /sys/devices/system/cpu/cpufreq/ondemand/up_threshold)\\n${STAND}" 234 | read -r -e -p "$show_input Enter new up_threshold value: " up_threshold 235 | sudo sh -c "echo $up_threshold > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold" 236 | echo -e "up_threshold changed to:$RED $(cat /sys/devices/system/cpu/cpufreq/ondemand/up_threshold)\\n${STAND}" 237 | pause 238 | else 239 | pause 240 | fi 241 | fi 242 | } 243 | 244 | ### Overclocking settings 245 | function rpioverclock() { 246 | 247 | read -r -e -p "$show_input Write$GREEN overclock$STAND to continue or$RED x$STAND to cancel: " oc_accept 248 | 249 | if [[ $oc_accept == overclock ]]; 250 | then 251 | echo "$show_execute Creating backup for config.txt in /boot" 252 | echo "$show_info You will have an option to post-edit/review your config.txt and add personal settings before restarting." 253 | sleep 1 254 | sudo cp /boot/config.txt /boot/config.txt.rpiv3tweak_backup 255 | echo "hdmi_force_hotplug=1 #set by RPiv3Tweak 256 | $(if grep -aq "Raspberry Pi 3 Model B Plus" /proc/device-tree/model; then echo "arm_freq=1500 #set by RPiv3Tweak"; elif grep -aq "Raspberry Pi 3 Model B" /proc/device-tree/model; then echo "arm_freq=1300 #set by RPiv3Tweak"; fi) 257 | core_freq=500 #set by RPiv3Tweak 258 | sdram_freq=500 #set by RPiv3Tweak 259 | over_voltage=6 #set by RPiv3Tweak 260 | boot_delay=1 #set by RPiv3Tweak" >> /boot/config.txt 261 | 262 | echo "$show_ok Mods written." 263 | echo "$show_info Please review mods..." && sleep 1 264 | nano /boot/config.txt 265 | echo -e "\\n$show_info All $show_ok" 266 | pause 267 | else 268 | echo -e "\\n$show_info Going back to main menu." && sleep 1 269 | fi 270 | } 271 | ### 272 | 273 | 274 | ### 275 | function change_swap() { 276 | 277 | get_current_swap=$(grep "CONF_SWAPSIZE=" /etc/dphys-swapfile | cut -d '=' -f2) 278 | echo -e "\\n::: SWAP SIZE CHANGE :::\\n" 279 | 280 | function swap_change() { 281 | 282 | read -r -e -p "$show_input Would you like to change the SWAP size? (y or n): " read_swap_change 283 | 284 | if [[ $read_swap_change == y ]]; then 285 | 286 | read -r -e -p "$show_input Enter size (recommended size is 2 * current RAM size): " read_swap_size 287 | 288 | if [[ $read_swap_size =~ ^[0-9][0-9][0-9][0-9]$ ]]; then 289 | 290 | echo "$show_execute Setting SWAP size to ${GREEN}$read_swap_size" 291 | if sed -i -- "s/CONF_SWAPSIZE=$get_current_swap/CONF_SWAPSIZE=$read_swap_size/g" /etc/dphys-swapfile; then echo "$show_info SWAP size changed successfully!"; else "$show_error Couldn't change SWAP size!"; fi 292 | if dphys-swapfile swapoff; then echo "$show_execute Stopping SWAP...$show_ok"; else echo "$show_error Couldn't stop SWAP..."; fi 293 | if dphys-swapfile setup; then echo "$show_execute Setting new SWAP...$show_ok"; else echo "$show_error Couldn't set up new SWAP..."; fi 294 | if dphys-swapfile swapon; then echo "$show_execute Starting new SWAP...$show_ok"; else echo "$show_error Couldn't start new SWAP..."; fi 295 | else 296 | echo "$show_error Wrong size entered...try again" 297 | fi 298 | 299 | elif [[ $read_swap_change == n ]]; then 300 | 301 | echo "$show_info We won't change SWAP.." 302 | 303 | elif [[ $read_swap_change == * ]]; then 304 | 305 | echo "$show_error Wrong option. Available options are y or n." && swap_change 306 | fi 307 | } 308 | swap_change 309 | } 310 | ### 311 | 312 | ### Raspiv3CPUtweak CHANGELOG 313 | function raspitweakchangelog(){ 314 | 315 | ### VARS 316 | checknet=$(ping -q -w 1 -c 1 google.com 2>&1 > /dev/null && echo Internet OK.) 317 | ### 318 | 319 | if [[ "$checknet" == "Internet OK." ]]; then 320 | ### VARS 321 | changelog=$(curl --silent --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" -q https://raw.githubusercontent.com/cbusuioceanu/Raspberry-Pi-v3-Tweaker/master/changelog.txt) 322 | last_version=$(curl --silent --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" -q https://raw.githubusercontent.com/cbusuioceanu/Raspberry-Pi-v3-Tweaker/master/version.txt) 323 | ### 324 | 325 | if [[ $last_version > $unixtime ]]; then 326 | echo -e "\\n$show_info Checking for update: $REDbg${WHITE}New version available!\\n$STAND" 327 | echo "${YELLOW}Changelog:${MAGENTA} 328 | $changelog $STAND" 329 | function update() { 330 | read -r -e -p "$show_input Press y to update now via update.sh script (y or n): " option 331 | case $option in 332 | y) bash update.sh;; 333 | n) echo "$show_info Ok, we'll update later." ;; 334 | *) echo "$show_error $option is not a valid option..."; update ;; 335 | esac 336 | } 337 | update 338 | else 339 | echo -e "\\n$show_info Checking for update:${YELLOW} You already have the latest version!" 340 | fi 341 | else 342 | echo -e "\\n$show_error No Internet connection." && sleep 1 343 | fi 344 | } 345 | 346 | #### Exit Raspiv3CPUtweak 347 | function expit_tweaker () { 348 | echo "Bye!" && exit 0 349 | } 350 | 351 | ### 352 | mainmenu(){ 353 | #### Infinite Loop To Show Menu Until Exit 354 | #trap '{ echo "CTRL C Detected. Closing script..."; exit 0; }' SIGINT 355 | 356 | while : 357 | do 358 | echo "${YELLOW}+------------------------------+" 359 | echo "| Raspberry Pi 3 Tweaker |" 360 | echo "| Script version: $version |" 361 | echo "+------------------------------+$STAND${WHITE}" 362 | echo "+------------------------------+" 363 | echo "| 1. Show CPU details |" 364 | echo "| 2. Change CPU Govenor |" 365 | echo "| 3. Overclock |" 366 | echo "| 4. Change SWAP |" 367 | echo "| 5. Updates |" 368 | echo "| 6. EXIT |" 369 | echo "+------------------------------+${STAND}" 370 | read -r -e -p "$show_input Choose an option: " menuoption 371 | 372 | case $menuoption in 373 | 1) freqtempvolt ;; 374 | 2) changegovernor ;; 375 | 3) rpioverclock ;; 376 | 4) change_swap ;; 377 | 5) raspitweakchangelog ;; 378 | 6|q) expit_tweaker ;; 379 | *) echo "'$menuoption' Is not a valid option!" && sleep 1;; 380 | esac 381 | done 382 | } 383 | #End 384 | 385 | checkdependencies 386 | mainmenu 387 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | git reset --hard origin/master 2 | git pull origin master 3 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 1600981200 2 | --------------------------------------------------------------------------------