選單
快速瀏覽
達拉斯 1-Wire 支持
準備
- 將涵蓋一個眾所周知的溫度傳感器示例DS1820,也支持其他 1 線 IC。
1-Wire 的默認 GPIO 是引腳 #7(ODROID-N2 – GPIOA.BIT13 / ODROID-C4 – GPIOX.BIT5)
- 連接:使用外部電源
Let's calculate how many hours the battery can endure supplying to the ODROID-C4. Assume that ODROID-C4 is running while eating 200mA current. The battery has its specification output 12V and 22.2wH(watt-hour). 22.2wH / (12V x 200mA) = 9.25 Hours (In principle, but there is lots of environment out there to get decreased it in the real world)
引腳 1(左):接地 (-)
引腳 2(中間):引腳 #7 N2 (GPIOA.BIT13) / C4 (GPIOX.BIT5)
引腳 3(右):VCC (3.3V)
您還需要在引腳 2 之間添加一個 4.7k 到 10k 的電阻。
- 連接:為寄生蟲供電
引腳 1(左):接地 (-)
引腳 2(中間):引腳 #7 N2 (GPIOA.BIT13) / C4 (GPIOX.BIT5)
引腳 3(右):接地 (-)
您還需要在引腳 2 之間添加一個 4.7k 到 10k 的電阻。
啟用 1-wire 總線
啟用 1-wire 總線
- 如果您使用的內核版本高於4.9.230,您應該編輯/media/boot/config.ini文件以通過將onewire添加到overlays變量來啟用 1-wire 。
; Device Tree Overlay overlay_resize=16384 overlay_profile=myproject overlays="" [overlay_myproject] overlays="onewire"
- 要了解 Device Tree Overlay 的更多信息,請參閱此文檔。
- 要啟用 1wire 總線,您需要修改 DT(Device Tree) 文件。
- 安裝所需的軟件包。
root@odroid:~$ sudo apt-get install device-tree-compiler
- 備份 DTB 文件。
root@odroid:~$ cp / media / boot / meson64_odroidc4.dtb / media / boot / meson64_odroidc4.dtb.org
- 更改 1wire 總線的 DTB 文件
root@odroid:~$ fdtget /media/boot/meson64_odroidc4.dtb /onewire status disabled root@odroid:~$ fdtput -t s /media/boot/meson64_odroidc4.dtb /onewire status "okay" root@odroid:~$ fdtget /media/boot/meson64_odroidc4.dtb /onewire status okay root@odroid:~$
- DTB修改完成後,重啟。
root@odroid:~$ reboot
- 檢查您的傳感器是否正常工作:
root@odroid:~$ lsmod w1_therm 16384 0 w1_gpio 16384 0 wire 45056 2 w1_gpio,w1_therm root@odroid:~$ cd / sys / bus / w1 / devices root @ odroid: / sys / bus / w1 / devices # - ls 10 000802f38c57 w1_bus_master1 root@odroid:~$
如您所見,我的傳感器被檢測為10-000802f38c57,每個傳感器都有不同的 ID。所以你的會不一樣。
- 讀取溫度:
root@odroid:/sys/bus/w1/devices$ cd 10-000802f38c57 root@odroid:/sys/bus/w1/devices/10-000802f38c57# cat w1_slave 33 00 4b 46 ff ff 03 10 30 : crc=30 YES 33 00 4b 46 ff ff 03 10 30 t=25562 root@odroid:/sys/bus/w1/devices/10-000802f38c57#
溫度是 t=25562 或 25.562 攝氏度。
- 多個傳感器可以連接在如下圖所示的同一條線上。
odroid @ odroid64: / sys / bus / w1 / devices # ls 10 -000802f38c57 10 -000802f41d67 w1_bus_master1
兩個傳感器並聯。
更改 1-Wire 接口的默認 GPIO 引腳
示例)默認 GPIO 引腳更改為 GPIOX.BIT3
請參閱以下鏈接,了解與設備樹中的 gpio 映射相關的詳細信息。
root@odroid:~$ fdtget /media/boot/meson64_odroidc4.dtb /onewire gpios 25 63 0 root@odroid:~$ fdtput /media/boot/meson64_odroidc4.dtb /onewire gpios 25 69 0 root@odroid:~$ fdtget /media/boot/meson64_odroidc4.dtb /onewire gpios 25 69 0 root@odroid:~$ reboot
如果重新啟動不影響 dtb 更新,則需要硬重置(關閉/打開電源)。
運行 fdtput 命令時,請使用 fdtget 命令輸出中的第一個數字。
例如,25(0x19) 是 GPIO 組號。
DS1820 連接到引腳 #11
引腳 1(左):接地 (-)
引腳 2(中間):引腳 #11 N2 (GPIOX.BIT3) / C4 (GPIOX.BIT3)
引腳 3(右):接地 (-)
快速瀏覽