Raspberry-Pi】Raspberry-Pi 4 的安裝過程
https://william-weng.github.io/2019/12/08/raspberry-pi-helloworld/
==========================================
平凡的幸福
https://blog.twtnn.com/2021/03/raspberry-pi-python.html
HomeLinuxLinux 定時刪除舊檔案
https://www.ltsplus.com/linux/linux-auto-delete-old-logs#comment-209
PyMySQL不會安裝到樹莓派
http://hk.uwenku.com/question/p-yblotkzd-qh.html
如格優雅地聞除Linux 中的垃 檔案
sudo apt install tmpreaper
https://www.gushiciku.cn/pl/px60/zh-tw
Raspberry Pi學習篝記(三):指令與功能
https://yanwei-liu.medium.com/raspberry-pi%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-%E4%B8%89-%E6%8C%87%E4%BB%A4%E8%88%87%E5%8A%9F%E8%83%BD-b9e1a7a6a14
為什麼啟動期間/etc/rc.local中的命令沒有執行
https://ubuntuqa.com/zh-tw/article/6408.html
Raspberry連接WebCam
https://sites.google.com/site/zsgititit/home/raspberry-shu-mei-pai/raspberry-lian-jiewebcam
==========================================
Modify Date & Time
sudo date --s="2021-12-08 16:26:02"
==========================================
#!/usr/bin/python3
#\u532f\u5165\u6a21\u7d44\u4e26\u6aa2\u67e5\u5b83\u662f\u5426\u6210\u529f\uff1a
import RPi.GPIO as GPIO
import time
import pymysql
from DBUtil import dbUtil
#GPIO_PIN = 4
def queryData(cursor):
# date,totalwgt,otherswgt,scrapeboxwgt,materialwgt,scapPartno,flowno,barcodeno
sqlString = """ select flag, Car_No, Car_Name, humi, Temp, Alarm, Status
from agvshipment.agv_station """
cursor.execute(sqlString)
result = cursor.fetchall()
return result
def insertData(cursor, flag, car_no, car_name, humi, temp, alarm, status):
sqlString = """ insert into agvshipment.agv_station(flag, Car_No, Car_Name, humi, Temp, Alarm, Status)
values(%s,%s,%s,%s,%s,%s,%s) """
paramList=(flag, car_no, car_name, humi, temp, alarm, status)
cursor.execute(sqlString, paramList)
# print("Insert Success.")
return 1
def updateDataByCarNo(cursor, car_no, humi, temp, alarm, status):
sqlString = """ update agvshipment.agv_station set humi=%s,Temp=%s,Alarm=%s,Status=%s where Car_No = %s """
print(humi)
print(temp)
print(alarm)
print(status)
print(car_no)
paramList=(humi, temp, alarm, status, car_no)
cursor.execute(sqlString, paramList)
print("Update Success.")
return 1
def deleteDataByCarNo(cursor, car_no):
sqlString = """ delete from agvshipment.agv_station where Car_No = %s """
paramList=(car_no)
cursor.execute(sqlString,paramList)
print("Delete Success.")
return 1
def delayMicrosecond(t): # \u5fae\u79d2\u7ea7\u5ef6\u65f6\u51fd\u6570
start,end=0,0 # \u58f0\u660e\u53d8\u91cf
start=time.time() # \u8bb0\u5f55\u5f00\u59cb\u65f6\u95f4
t=(t-3)/1000000 # \u5c06\u8f93\u5165t\u7684\u5355\u4f4d\u8f6c\u6362\u4e3a\u79d2\uff0c-3\u662f\u65f6\u95f4\u8865\u507f
while end-start<t: # \u5faa\u73af\u81f3\u65f6\u95f4\u5dee\u503c\u5927\u4e8e\u6216\u7b49\u4e8e\u8bbe\u5b9a\u503c\u65f6
end=time.time() # \u8bb0\u5f55\u7ed3\u675f\u65f6\u95f4
tmp=[] # \u7528\u6765\u5b58\u653e\u8bfb\u53d6\u5230\u7684\u6570\u636e
def delayMicrosecond(t): # \u5fae\u79d2\u7ea7\u5ef6\u65f6\u51fd\u6570
start,end=0,0 # \u58f0\u660e\u53d8\u91cf
start=time.time() # \u8bb0\u5f55\u5f00\u59cb\u65f6\u95f4
t=(t-3)/1000000 # \u5c06\u8f93\u5165t\u7684\u5355\u4f4d\u8f6c\u6362\u4e3a\u79d2\uff0c-3\u662f\u65f6\u95f4\u8865\u507f
while end-start<t: # \u5faa\u73af\u81f3\u65f6\u95f4\u5dee\u503c\u5927\u4e8e\u6216\u7b49\u4e8e\u8bbe\u5b9a\u503c\u65f6
end=time.time() # \u8bb0\u5f55\u7ed3\u675f\u65f6\u95f4
tmp=[] # \u7528\u6765\u5b58\u653e\u8bfb\u53d6\u5230\u7684\u6570\u636e
data = 18 # DHT11\u7684data\u5f15\u811a\u8fde\u63a5\u5230\u7684\u6811\u8393\u6d3e\u7684GPIO\u5f15\u811a\uff0c\u4f7f\u7528BCM\u7f16\u53f7
# https://blog.zeruns.tech
a,b=0,0
def DHT11():
GPIO.setup(data, GPIO.OUT) # \u8bbe\u7f6eGPIO\u53e3\u4e3a\u8f93\u51fa\u6a21\u5f0f
GPIO.output(data,GPIO.HIGH) # \u8bbe\u7f6eGPIO\u8f93\u51fa\u9ad8\u7535\u5e73
delayMicrosecond(10*1000) # \u5ef6\u65f610\u6beb\u79d2
GPIO.output(data,GPIO.LOW) # \u8bbe\u7f6eGPIO\u8f93\u51fa\u4f4e\u7535\u5e73
delayMicrosecond(25*1000) # \u5ef6\u65f625\u6beb\u79d2
GPIO.output(data,GPIO.HIGH) # \u8bbe\u7f6eGPIO\u8f93\u51fa\u9ad8\u7535\u5e73
GPIO.setup(data, GPIO.IN) # \u8bbe\u7f6eGPIO\u53e3\u4e3a\u8f93\u5165\u6a21\u5f0f
# https://blog.zeruns.tech
a=time.time() # \u8bb0\u5f55\u5faa\u73af\u5f00\u59cb\u65f6\u95f4
while GPIO.input(data): # \u4e00\u76f4\u5faa\u73af\u81f3\u8f93\u5165\u4e3a\u4f4e\u7535\u5e73
b=time.time() # \u8bb0\u5f55\u7ed3\u675f\u65f6\u95f4
if (b-a)>0.1: # \u5224\u65ad\u5faa\u73af\u65f6\u95f4\u662f\u5426\u8d85\u8fc70.1\u79d2\uff0c\u907f\u514d\u7a0b\u5e8f\u8fdb\u5165\u6b7b\u5faa\u73af\u5361\u6b7b
break # \u8df3\u51fa\u5faa\u73af
a=time.time()
while GPIO.input(data)==0: # \u4e00\u76f4\u5faa\u73af\u81f3\u8f93\u5165\u4e3a\u9ad8\u7535\u5e73
b=time.time()
if (b-a)>0.1:
break
a=time.time()
while GPIO.input(data): # \u4e00\u76f4\u5faa\u73af\u81f3\u8f93\u5165\u4e3a\u4f4e\u7535\u5e73
b=time.time()
if (b-a)>=0.1:
break
for i in range(40): # \u5faa\u73af40\u6b21\uff0c\u63a5\u6536\u6e29\u6e7f\u5ea6\u6570\u636e
a=time.time()
while GPIO.input(data)==0: #\u4e00\u76f4\u5faa\u73af\u81f3\u8f93\u5165\u4e3a\u9ad8\u7535\u5e73
b=time.time()
if (b-a)>0.1:
break
# https://blog.zeruns.tech
delayMicrosecond(28) # \u5ef6\u65f628\u5fae\u79d2
if GPIO.input(data): # \u8d85\u8fc728\u5fae\u79d2\u540e\u5224\u65ad\u662f\u5426\u8fd8\u5904\u4e8e\u9ad8\u7535\u5e73
tmp.append(1) # \u8bb0\u5f55\u63a5\u6536\u5230\u7684bit\u4e3a1
a=time.time()
while GPIO.input(data): # \u4e00\u76f4\u5faa\u73af\u81f3\u8f93\u5165\u4e3a\u4f4e\u7535\u5e73
b=time.time()
if (b-a)>0.1:
break
else:
tmp.append(0) # \u8bb0\u5f55\u63a5\u6536\u5230\u7684bit\u4e3a0
while True:
if __name__ == "__main__":
try:
time.sleep(1)
db = dbUtil('10.97.82.24','root','FA$admin01','agvshipment')
conn = db.getInstance()
cursor = db.getCursor(conn)
# QUERY DATA -------------------------------------------------------------------------------------------------
GPIO.setmode(GPIO.BCM)
# \u8bbe\u7f6e\u4e3aBCM\u7f16\u53f7\u6a21\u5f0f
GPIO.setwarnings(False)
del tmp[0:] # \u5220\u9664\u5217\u8868
time.sleep(1) # \u5ef6\u65f61\u79d2
# https://blog.zeruns.tech
DHT11()
humidity_bit=tmp[0:8] # \u5206\u9694\u5217\u8868\uff0c\u7b2c0\u52307\u4f4d\u662f\u6e7f\u5ea6\u6574\u6570\u6570\u636e
humidity_point_bit=tmp[8:16]# \u6e7f\u5ea6\u5c0f\u6570
temperature_bit=tmp[16:24] # \u6e29\u5ea6\u6574\u6570
temperature_point_bit=tmp[24:32] # \u6e29\u5ea6\u5c0f\u6570
check_bit=tmp[32:40] # \u6821\u9a8c\u6570\u636e
humidity_int=0
humidity_point=0
temperature_int=0
temperature_point=0
check=0
# https://blog.zeruns.tech
for i in range(8): # \u4e8c\u8fdb\u5236\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236
humidity_int+=humidity_bit[i]*2**(7-i)
humidity_point+=humidity_point_bit[i]*2**(7-i)
temperature_int+=temperature_bit[i]*2**(7-i)
temperature_point+=temperature_point_bit[i]*2**(7-i)
check+=check_bit[i]*2**(7-i)
humidity=humidity_int+humidity_point/10
temperature=temperature_int+temperature_point/10
check_tmp=humidity_int+humidity_point+temperature_int+temperature_point
if check==check_tmp and temperature!=0 and temperature!=0: # \u5224\u65ad\u6570\u636e\u662f\u5426\u6b63\u5e38
print("Temperature is ", temperature,", Humidity is ",humidity,"%")# \u6253\u5370\u6e29\u6e7f\u5ea6\u6570\u636e
print("https://blog.zeruns.tech")
else:
print("error")
GPIO.setup(21,GPIO.OUT)
GPIO.setup(20,GPIO.IN)
GPIO.output(21, 1)
flag = 1
car_no = '03'
car_name = '03\u865f\u8eca\u5145\u96fb\u7ad9'
humi = humidity
temp = temperature
if GPIO.input(20):
B = ' Smoke detecting , Input(20) was HIGH , Light ON'
alarm = 0
status = 1
else:
B = ' Alarm! Smoke detected , Input(20) was Low , Light OFF'
alarm = 'Smoke detected'
status = 'Alarm'
rtn_code = insertData(cursor, flag, car_no, car_name, humi, temp, alarm, status)
#rtn_code = updateDataByCarNo(cursor, car_no, humi, temp, alarm, status)
if rtn_code == 1:
conn.commit()
A = time.ctime()
#A = A.split()
print('db insert ok ,',car_name,' , ' ,B,' , ',A)
#print('update ok')
except Exception as e:
print('exception.....',e)
time.sleep(6)
GPIO.cleanup()
===========================
#!/usr/bin/python3
#匯入模組並檢查它是否成功:
import RPi.GPIO as GPIO
import time
def delayMicrosecond(t): # 微秒级延时函数
start,end=0,0 # 声明变量
start=time.time() # 记录开始时间
t=(t-3)/1000000 # 将输入t的单位转换为秒,-3是时间补偿
while end-start<t: # 循环至时间差值大于或等于设定值时
end=time.time() # 记录结束时间
tmp=[] # 用来存放读取到的数据
def delayMicrosecond(t): # 微秒级延时函数
start,end=0,0 # 声明变量
start=time.time() # 记录开始时间
t=(t-3)/1000000 # 将输入t的单位转换为秒,-3是时间补偿
while end-start<t: # 循环至时间差值大于或等于设定值时
end=time.time() # 记录结束时间
tmp=[] # 用来存放读取到的数据
data = 18 # DHT11的data引脚连接到的树莓派的GPIO引脚,使用BCM编号
# https://blog.zeruns.tech
a,b=0,0
def DHT11():
GPIO.setup(data, GPIO.OUT) # 设置GPIO口为输出模式
GPIO.output(data,GPIO.HIGH) # 设置GPIO输出高电平
delayMicrosecond(10*1000) # 延时10毫秒
GPIO.output(data,GPIO.LOW) # 设置GPIO输出低电平
delayMicrosecond(25*1000) # 延时25毫秒
GPIO.output(data,GPIO.HIGH) # 设置GPIO输出高电平
GPIO.setup(data, GPIO.IN) # 设置GPIO口为输入模式
# https://blog.zeruns.tech
a=time.time() # 记录循环开始时间
while GPIO.input(data): # 一直循环至输入为低电平
b=time.time() # 记录结束时间
if (b-a)>0.1: # 判断循环时间是否超过0.1秒,避免程序进入死循环卡死
break # 跳出循环
a=time.time()
while GPIO.input(data)==0: # 一直循环至输入为高电平
b=time.time()
if (b-a)>0.1:
break
a=time.time()
while GPIO.input(data): # 一直循环至输入为低电平
b=time.time()
if (b-a)>=0.1:
break
for i in range(40): # 循环40次,接收温湿度数据
a=time.time()
while GPIO.input(data)==0: #一直循环至输入为高电平
b=time.time()
if (b-a)>0.1:
break
# https://blog.zeruns.tech
delayMicrosecond(28) # 延时28微秒
if GPIO.input(data): # 超过28微秒后判断是否还处于高电平
tmp.append(1) # 记录接收到的bit为1
a=time.time()
while GPIO.input(data): # 一直循环至输入为低电平
b=time.time()
if (b-a)>0.1:
break
else:
tmp.append(0) # 记录接收到的bit为0
while True:
GPIO.setmode(GPIO.BCM) # 设置为BCM编号模式
GPIO.setwarnings(False)
del tmp[0:] # 删除列表
time.sleep(1) # 延时1秒
# https://blog.zeruns.tech
DHT11()
humidity_bit=tmp[0:8] # 分隔列表,第0到7位是湿度整数数据
humidity_point_bit=tmp[8:16]# 湿度小数
temperature_bit=tmp[16:24] # 温度整数
temperature_point_bit=tmp[24:32] # 温度小数
check_bit=tmp[32:40] # 校验数据
humidity_int=0
humidity_point=0
temperature_int=0
temperature_point=0
check=0
# https://blog.zeruns.tech
for i in range(8): # 二进制转换为十进制
humidity_int+=humidity_bit[i]*2**(7-i)
humidity_point+=humidity_point_bit[i]*2**(7-i)
temperature_int+=temperature_bit[i]*2**(7-i)
temperature_point+=temperature_point_bit[i]*2**(7-i)
check+=check_bit[i]*2**(7-i)
humidity=humidity_int+humidity_point/10
temperature=temperature_int+temperature_point/10
check_tmp=humidity_int+humidity_point+temperature_int+temperature_point
if check==check_tmp and temperature!=0 and temperature!=0: # 判断数据是否正常
print("Temperature is ", temperature,"C\nHumidity is ",humidity,"%")# 打印温湿度数据
print("https://blog.zeruns.tech")
else:
print("error")
time.sleep(1)
GPIO.cleanup()
=============================
#!/usr/bin/python3
#匯入模組並檢查它是否成功:
try:
import RPi.GPIO as GPIO
import time
except RuntimeError:
print("匯入RPi.GPIO時出錯,可能是許可權問題")
GPIO.setmode(GPIO.BCM)#指定為BCM編號
GPIO.setup(21,GPIO.OUT)
GPIO.setup(20,GPIO.IN)
GPIO.output(21, 1)
if GPIO.input(20):
print('Input was HIGH')
else:
print('Input was LOW')
time.sleep(3)
GPIO.cleanup()
==========================
附加
開啟3306埠遠端訪問(如果不用防火牆,這一步可以忽略)
這裡的iptable命令和centos中命令不一樣,所以參考了一下文件,使用ufw軟體來開啟3306埠
(1)安裝 ufwsudo apt-get install ufw
(2)啟用 ufwsudo ufw enable
sudo ufw default deny
(3)開啟3306、22(ssh埠)埠sudo ufw allow 3306
sudo apt-get install ufw
sudo ufw enable
sudo ufw default deny
sudo ufw allow 3306
!==================================================
安裝 MySQL
pip install PyMySQL
pi@raspberrypi:~/PyMySQL-1.0.2 $ pip install PyMySQL
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting PyMySQL
Downloading https://www.piwheels.org/simple/pymysql/PyMySQL-1.0.2-py3-none-any.whl (43 kB)
|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 43 kB 74 kB/s
Installing collected packages: PyMySQL
Successfully installed PyMySQL-1.0.2
!==================================================
!==================================================
Camara Motion Setting
sudo lsusb
sudo apt-get -y install fswebcam bison v4l-utils motion
sudo chown motion:motion /var/lib/motion
Raspberry連接WebCam
Step1)查看usb的web cam是否成功安裝驅動程式
#lsusb
Step2)利用web cam拍照,安裝fswebcam
#sudo apt-get install fswebcam
使用fswebcam進行拍照
#fswebcam my.jpg
Step3)安裝motion將web cam的拍攝影片轉成串流影片
#sudo apt-get install motion
Step4) 修改motion設定檔
#sudo geany /etc/motion/motion.conf
#修改daemon的off改成on
daemon on
#修改可以遠端使用瀏覽器連進web cam,將stream_localhost改成off
stream_localhost off
#修改影片的寬度為640與高度為480
width 640
height 480
1280 x 720 is good
# 預設網頁瀏覽監視畫面使用8081 Port
stream_port 8081
# 預設管理motion程式使用8080 Port
webcontrol_port 8080
#預設影片格式mpeg4
ffmpeg_video_codec mpeg4
maybe mkv is ok, mkv is a kind of video format wich any player can read it.
# The quality (in percent) to be used by the jpeg and webp compression (default: 75)
quality 95
# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
target_dir /var/lib/motion (chane video files location)
movie_filename %v-%Y%m%d%H%M%S
framerate 20
# Quality of the jpeg (in percent) images produced (default: 50)
stream_quality 95
Step5)啟動motion
#sudo motion
!==================================================
設定重開機執行MOTION程式
sudo geany /etc/rc.local
在程式空白處加一行 motion
如何優雅地刪除 Linux 中的垃圾檔案
在 Debian 及其衍生版本(如 Ubuntu )上, tmpwatch 又叫 tmpreaper :
$ sudo apt install tmpreaper
設定固定日期某時間刪掉固定日期前的檔案
crontab -e
0 11 * * * /usr/sbin/tmpreaper 45d /home/pi/Desktop/Videos
取得溫度資訊
vcgencmd measure_temp
取得電壓資訊
pi@raspberrypi:~ $ vcgencmd measure_volts core
取得當前運作時脈
vcgencmd measure_clock arm
for src in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi ; do echo -e "$src:\t$(vcgencmd measure_clock $src)" ; done
https://shumeipai.nxez.com/2019/05/29/make-the-raspberry-pi-speak-its-own-ip-address.html
sudo raspi-config
https://www.raspberrypi.org/documentation/configuration/audio-config.md
sudo geany /boot/config.txt
编辑 config.txt ,添加:
hdmi_drive=2 #hdmi 2 output sound
# hdmi_drive=1 #hdmi 1 output sound
如果无效,添加:
hdmi_group=1
hdmi_mode=4
如果还无效,参考 https://www.raspberrypi.org/forums/viewtopic.php?t=5062
如果还无法解决,请点击 https://lmgtfy.app/?q=raspberry+pi+hdmi+no+sound
Raspberry Pi學習筆記(三):指令與功能
Yanwei Liu
Yanwei Liu
May 13, 2019·4 min read
開關機
sudo reboot #重開機
sudo halt #關機(比sudo poweroff安全)
套件管理
sudo apt-get update #更新軟體列表
sudo apt-get upgrade #更新軟體包
sudo apt-get install <軟體名稱> #安裝套件
sudo apt-get remove <軟體名稱> #移除套件
查看SD卡空間狀況
df -h
設定樹莓派系統參數
sudo raspi-config
查看溫度
vcgencmd measure_temp
查看CPU和GPU記憶體
vcgencmd get_mem arm #CPU
vcgencmd get_mem gpu #GPU
查看韌體版本
vcgencmd version
執行Python程式
sudo python abc.py
安裝軟體
例如:
sudo apt-get install GIMP
sudo apt-get install VLC
sudo apt-get install thunderbird
移除軟體
dpkg --list #顯示已安裝的軟體
sudo apt-get --purge remove XXX #刪除上面指令清單中的XXX軟體
使用pip安裝Python套件
sudo pip install <套件名稱>
安裝Python常用套件
sudo apt-get install zip unzip (壓縮解壓縮)
pip3 install ipython (Python Shell)
pip3 install requests (網頁擷取)
pip3 install beautifulsoup4 (網頁解析)
pip3 install selenium (自動化工具)
pip3 install django (網頁開發框架)
sudo apt-get install sqlite3 (SQLite 資料庫)
sudo apt-get install r-base (R 語言)
sudo apt-get install nginx (Web 伺服器)
sudo pip3 install uWSGI (WSGI 伺服器)
pip3 install numpy (科學計算)
pip3 install scipy (科學計算)
pip3 install matplotlib (2D 繪圖)
pip3 install pandas (數據處理)
pip3 install scikit-learn (機器學習)
安裝截圖軟體scrot
sudo apt-get install scrot
預設抓取的目錄在 /home/pi/ 中
使用
終端機輸入
scrot #抓取整個桌面
scrot -s #滑鼠選取範圍
scrot -u #抓目前視窗
安裝Vim編輯器
sudo apt-get install vim
安裝PIP套件管理
sudo apt-get install python-pip
安裝Node.js
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs
node -v
!==================================================
DHT11
Step1)硬體與接線如下圖
DHT11左邊第一個pin接5V,第二個pin接10K電阻接5V,再接到Raspberry的pin7(GPIO4),第4個pin接地。
Step2)安裝build-essential與python-dev
#sudo apt-get update
#sudo apt-get install build-essential python-dev
Step3)下載與安裝Adafruit_Python_DHT
#git clone https://github.com/adafruit/Adafruit_Python_DHT
#cd Adafruit_Python_DHT
#sudo python setup.py install
Step4)執行監控程式
#cd examples
#sudo ./AdafruitDHT.py 11 4 //11使用表示使用DHT11模組,4表示DHT11的Data接線在GPIO4(Raspberry Pi 3 pin 7)
!==================================================
fe附錄 - 如何設定本機時間
◦查詢日期/時間
登入文字模式後,如果要查看系統時間,請輸入date查詢目前時間。
date
◦修改預設時區
登入文字模式後,顯示時區UTC似乎不正確,輸入tzselect修改時區。
tzselect
接著在#? 之後輸入 5 選擇亞洲5)Asia
接著在#? 之後輸入 43 選擇台灣 43) Taiwan 或是 9)China
最後在#? 之後輸入 1 確定存檔。完成!!
!==================================================
Setup Keyborad
1. 安裝所需軟體matchbox-keyboard
sudo apt update
sudo apt install matchbox-keyboard
2. 開啟編輯toggle-matchbox-keyboard.sh腳本
sudo nano /usr/bin/toggle-matchbox-keyboard.sh
3. 複製以下內容至toggle-matchbox-keyboard.sh腳本,存檔後退出
#!/bin/bash
#This script toggle the virtual keyboard
PID=`pidof matchbox-keyboard`
if [ ! -e $PID ]; then
killall matchbox-keyboard
else
matchbox-keyboard &
fi
4. 新增執行權限
sudo chmod +x /usr/bin/toggle-matchbox-keyboard.sh
5. 開啟編輯toggle-matchbox-keyboard.desktop桌面捷徑
sudo mkdir /usr/local/share/applications
sudo nano /usr/local/share/applications/toggle-matchbox-keyboard.desktop
6. 複製以下内容至toggle-matchbox-keyboard.desktop,存檔後退出
[Desktop Entry]
Name=Toggle Matchbox Keyboard
Comment=Toggle Matchbox Keyboard`
Exec=toggle-matchbox-keyboard.sh
Type=Application
Icon=matchbox-keyboard.png
Categories=Panel;Utility;MB
X-MB-INPUT-MECHANSIM=True
7. 使用”pi”用戶權限開啟編輯panel文件,注意此處不可以用管理員權限執行,否則會找不到檔案
sudo nano /etc/xdg/lxpanel/LXDE-pi/panels/panel
8. 在panel文件中找到類似以下區塊,注意不同版本圖示可能會有些微差異
Plugin {
type = launchbar
Config {
Button {
id=lxde-screenlock.desktop
}
Button {
id=lxde-logout.desktop
}
}
9. 新增以下內容至Button區塊,以新增虛擬鍵盤按鍵
Button {
id=/usr/local/share/applications/toggle-matchbox-keyboard.desktop
}
10. 完成後檔案內容大致如下,存檔後退出
留言列表