一、jetson nano 風扇降溫
2020-5-10 0:23 風雨敲窗櫺
1. 手動設定風扇轉速終端命令
- 全速
sudo sh -c 'echo 255 > /sys/devices/pwm-fan/target_pwm'
- 停止(注意,是從當前速度緩慢降到0,減速過程爲1分鐘)
sudo sh -c 'echo 20 > /sys/devices/pwm-fan/target_pwm'
2. 根據CPU溫度自動調節風扇轉速
注意:以下程序的條件可根據需要自行更改。
# 源地址:https://blog.csdn.net/bornfree5511/article/details/103076414
#!/usr/bin/python
#~/fan_control.py
import time
while True:
fo = open("/sys/class/thermal/thermal_zone0/temp","r")
#thermal_zone1是cpu的溫度,thermal_zone2是gpu的溫度,thermal_zone0的溫度一直是最高的,可能
#是封裝的溫度,可用jtop查看具體的信息
thermal = int(fo.read(10))
fo.close()
thermal = thermal / 1000
if thermal < 30:
thermal = 0
elif thermal >= 30 and thermal < 70:
thermal = thermal - 30
else:
thermal = thermal
thermal = str(thermal)
print thermal
fw=open("/sys/devices/pwm-fan/target_pwm","w")
fw.write(thermal)
fw.close()
time.sleep(60)
3. 開機自啓動
1.建立rc-local.service文件
sudo gedit /etc/systemd/system/rc-local.service
2.將下列內容替換rc-local.service文件
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
3.創建文件rc.local
sudo gedit /etc/rc.local
4.將下列內容複製進rc.local文件
#!/bin/sh -e
# rc.local
nohup sudo python ~/fan_control.py > /usr/local/out.log 2>&1 &
exit 0
sudo gedit /etc/sudoers
將 %sudo ALL=(ALL:ALL) ALL
修改爲%sudo ALL=(ALL) NOPASSWD:ALL
請仔細操作!
6.給rc.local加上權限
sudo chmod +x /etc/rc.local
7.啓用服務
sudo systemctl enable rc-local
8.啓動服務並檢查狀態
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
9.重啓並檢查是否成功
reboot
如果風扇自動轉了起來,說明成功。
二、I2C總線之OLED屏顯示
1. jetracer擴展板
在某寶上找到基於jetson nano的小車,有兩款:1)jetbot;2)jetracer。jetbot利用差速驅動轉向,jetracer則是迷你版的無人車(幾何運動學模型爲阿克曼輪轉向模型)。後者是我想要的。jetracer很好,唯一不足的是,電機不帶編碼器,在之後的功能上有所缺失(無法得到較準確的里程計信息)。於是:我只購買了jetracer擴展板、鋰電池組。
2.I2C總線
jetson nano總共有2組I2C總線,分別爲(I2C BUS 1: 3,5)(I2C BUS 2: 27,28)。I2C總線的引腳在J41,也即那兩排密集的引腳區。
查看總線1的設備
sudo i2cdetect -y -r 1
其中,3c就是OLED的I2C設備地址。
OLED顯示
由於jetracer擴展板上使用的是SSD1306的0.91inch OLED屏幕,所以需要先安裝Adafruit_SSD1306
sudo pip3 install Adafruit_SSD1306
由於OLED顯示的示例程序在jetbot上,所以先安裝jetbot.
git clone https://github.com/NVIDIA-AI-IOT/jetbot.git
cd jetbot
python3 setup.py build
sudo python3 setup.py install --record jetbot.uninstall.txt
如果需要卸載jetbot,可以在jetbot根目錄下執行:
sudo cat jetbot.uninstall.txt | sudo xargs rm -rf
所以,最好保留jetbot.uninstall.txt
文件。
運行程序:
cd jetbot/jetbot/apps/
sudo python3 stats.py
會看到OLED顯示了以太網,wlan,內存與存儲等信息。
在另一家店裏挑了一款不帶控制器的迷你小車(帶編碼的電機,舵機)。那家店裏,也有帶控制器的(買來直接能用遊戲手柄控制運動的那種)。由於,車本來就很小,211 x 191 x 65mm。如果系統用兩個計算板子,車體肯定很臃腫。我想把所有的全集中在jetson nano上,就像jetracer一樣。
Jetson Nano I2C說明及Python案例:MPU6050