---
tags: Raspberry
---
# Rspberry Pi Study
---
官網:
https://www.raspberrypi.org/
image 檔安裝:
https://www.raspberrypi.org/software/
網路上有很多不用螢幕就可設定wifi與ssh的文章,不知為何,設定都失敗 :cry:
## FTP server(vsftpd)
sudo apt install vsftpd



Create FTP directory

-p argument instructs mkdir to create the entire path
Modift Perminissons

remove the write permission from the FTP dircetory to prevent other users from adding files to it
Restart Vsftpd Daemon
sudo serive vsftpd restart
可以查看status:Service vsftpd status
FTP sever Test
ifConfig

FileZilla on another machine

if the connection is successful

on the remote machine,drag and drop some files from a source to the destination directory in FileZilla to make sue the connection is working

[How to Set up FTP Server on Your Raspberry Pi](https://phoenixnap.com/kb/raspberry-pi-ftp-server)
## Motion
### 基礎
Respberry內查看自己的IP address:
ifconfig
Host(windows)內查看自己的 ip address:
ipconfig
Windoows 上可使用Advanced IP scanner,掃描連接的裝置
Window 上使用ssh與Raspberry 連線:
ssh login_name@ip_addres (ex: pi@192.16.0.100)
Raspberry Pi 關機:
sudo halt,sudo power off,sudo init 0,sudo shutdown -h now
Raspberry pi 重啟:
sudo reboot,sudo shutdown -r now
dmesg:顯示內核輸出
[Using a standard USB webcam](https://www.raspberrypi.org/documentation/usage/webcams/)
### 安裝影像軟體 motion
#### 檢查 usb camera 是否驅動
使用lsusb指令
#### 安裝 motion 軟體
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install motion
#### 參數設定
開啟montion daemon 守護程序,讓他一直在後台執行:
sudo nano /etc/default/motion
start_motion_daemon=no --> start_motion_daemon=yes
修改設定檔 motion.conf :
sudo nano /etc/motion/motion.conf
自動啟動motion:
daemon off --> deamon on
不從raspberry 連線至 webcam:
stream_localhost on --> stream_localhost_off
Web連線:
stream_port 8081
管理用的連線:
webcontrol_port 8080
完整參數說明:
https://motion-project.github.io/motion_config.html#Configuration_OptionsAlpha
sudo motion
用網路連線 http://ip address:8081 可以看到畫面,成功了 :laughing:
#### 問題
當重新開機後,用網路連線上去都失敗,上網查詢好像是沒寫入motion.log的權限,要先做如下設定:
sudo chmod 777 /var/log/motion/motion.log
sudo chmod 777 /var/lib/motion
解決問題:
https://www.raspberrypi.org/forums/viewtopic.php?t=218465
https://raspberrypi.stackexchange.com/questions/78715/motion-daemon-var-log-motion-motion-log-permission-denied
---
sudo motion -b -->run in daemon mode (用 man motion 查詢)
ps -ef|grep motion -->process status
sudo serive motion start
sudo serive montion stop
sudo service motion restart
sudo serive motion status
---
### 外網連線
使用 ngrok
(視頻中後段有操作連線 ngrok,照著操作就可以了)
https://www.youtube.com/watch?v=9u6n45gaXWY
外網連線,顯示webcam視頻 ok :laughing: :laughing:
## GPIO
[官網介紹 GPIO](https://www.raspberrypi.org/documentation/hardware/raspberrypi/gpio/README.md)
### 基礎
/proc/interruptts ->當前系統使用的中斷
/proc/stat ->所有CPU活動訊息
/proc/irq
/proc/iomem ->IO裝置對應的記憶體位址
/proc/ioports ->IO裝置對應的名稱
[Linux file – /proc/interrupts,iomem,ioports](https://benjr.tw/97838)
[/proc/stat解析](http://gityuan.com/2017/08/12/proc_stat/)
[dtc -device tree compiler](http://manpages.ubuntu.com/manpages/bionic/man1/dtc.1.html)
[Raspberry Pi GPIO Interrupts Tutorial-python](https://roboticsbackend.com/raspberry-pi-gpio-interrupts-tutorial/)
[GPIO Descriptor Consumer Interface](
https://www.kernel.org/doc/html/latest/driver-api/gpio/consumer.html#gpios-mapped-to-irqs)
### 使用 GPIO utility
gpio -h ->help
gpio readall ->output a pins values table
gpio export 24 out (24指的是BCM欄的24)
gpio -g write 24 1
gpio -g write 24 0
gpio -g toggle 24
gpio -g blink 24
### 使用 sysfs
不錯的文章: https://www.ics.com/blog/gpio-programming-using-sysfs-interface

echo 24 > /sys/class/gpio/export ->從 ls /sys/class/gpio 可以發現 gpio24被 export
ls /sys/class/gpio/gpio24/ ->查看pin state
echo out > /sys/class/gpio/gpio24/direction
echo 0 > /sys/class/gpio/gpio24/value
echo 1 > /sys/class/gpio/gpio24/value
echo in > /sys/class/gpio/gpio24/direction
cat /sys/class/gpio/gpio24/value ->讀值
### 亂亂學
cat /proc/interrupts

tree /proc/device-tree


cat /proc/device-tree/aliases/i2c1 -->/soc/i2c@7e804000
cat /proc/device-tree/aliases/i2c2 --> /soc/i2c@7e805000
dtc -I fs /proc/device-tree

沒找到 0x7e805000 ???
dtc -I fs /proc/device-tree

位址 0x7e200000 代表
