2019年12月1日 星期日

test

  1. #加window icon
  2. import sys #只是為了使用在釋放程式的記憶體
  3. from PyQt5.QtWidgets import QApplication #qt的應用程式
  4. from PyQt5.QtWidgets import QLabel #qt的Label
  5. from PyQt5.QtWidgets import QWidget #qt的部件,就是我們要的視窗
  6. ##目錄中要有icon.png
  7. from PyQt5 import QtGui  ##為了加一個window icon
  8. app QApplication(sys.argv#建立主程式的實體 app ,參數是一個list,如果不需要sys.argv,可以改成[]
  9. #以下一一建立程式中的顯示部件
  10. window QWidget() #建立視窗實體
  11. window.setWindowTitle('第一個視窗程式'#視窗的抬頭
  12. window.setGeometry(20020028080#視窗的位置和大小(x,y,,)
  13. #window.move(6015#重新將視窗移到電腦螢幕的(60,15)位置
  14. helloMsg QLabel('<h1>Hello World!</h1>'parent=window#建立標籤實體
  15. helloMsg.move(6015#標籤移到視窗中的某位置
  16. window.setWindowIcon(QtGui.QIcon('icon.png'))  ##這行將icon放上去。
  17. window.show() #將視窗設定為顯示
  18. sys.exit(app.exec()) #開始執行應用程式,並在結束後,釋放記憶體。如果是python2,要用app.exec_()

2018年8月8日 星期三

用一片sd卡建立media center


原來是早就有的東西,
手機,電腦各作業系統都有,但連網速度很慢,連看youtube都連不上,
我看是不要用好了。

參考網址
https://learn.adafruit.com/raspberry-pi-as-a-media-center/overview

燒錄好sd卡後開機,有參數要先設訂,選單點的方法和windows的操作不一樣,慢慢適應。

語言先選English(US)才好,因為選了中文,

結果進入後的選單都是亂碼,不知如何操作。
勉強一個個選單查看,才找到語言設定,改成英語。

後續操作還在摸索。(2018009)

2018年8月3日 星期五

作業系統(SD卡)燒錄

參考:
http://yhhuang1966.blogspot.com/2017/02/raspbian.html

因為不明原因,網路完全不通了,所以要將這張SD卡重新燒image檔,但因被分割了,所以燒不成,來此網站,參考將SD卡重新格式化,就可以了。

2018年7月21日 星期六

raspberry-gpio-python雜記

★GPIO.RISING  正緣觸發參數   GPIO.FALLING 負緣觸發參數

中斷  軟體中斷才會耗用CPU資源,又叫做系統呼叫。
到底是raspberry Pi 板子本身就有硬體中斷,還是GPIO做出軟體中斷?

有關input 上/下拉電阻,event_detect,debouce...

★參考https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/

GPIO.setmode(GPIO.BOARD)
  # or
GPIO.setmode(GPIO.BCM)
mode = GPIO.getmode()
GPIO.setwarnings(False)
GPIO.setup(channel, GPIO.IN)
GPIO.setup(channel, GPIO.OUT)
GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)
----------------------------
chan_list = [11,12]    # add as many channels as you want!
                       # you can tuples instead i.e.:
                       #   chan_list = (11,12)
GPIO.setup(chan_list, GPIO.OUT)
-----------------------------
取得值GPIO.input(channel)
設定值GPIO.output(channel, state)
多組設定
chan_list = [11,12]                             # also works with tuples
GPIO.output(chan_list, GPIO.LOW)                # sets all to GPIO.LOW
GPIO.output(chan_list, (GPIO.HIGH, GPIO.LOW))   # sets first HIGH and second LOW
清除所有腳位,恢復初始狀態GPIO.cleanup()
也可以只清部份
GPIO.cleanup(channel)
GPIO.cleanup( (channel1, channel2) )
GPIO.cleanup( [channel1, channel2] )
取得軟硬體資訊
GPIO.RPI_INFO
GPIO.RPI_INFO['P1_REVISION']
GPIO.RPI_REVISION
GPIO.VERSION

★def mycallback(channel):
     print("Button pressed")
在上面中參數channel沒有作用,但不可以除去,否則會有runtime error,一定至少要有一個參數,在這裡至於給什麼,都可以。
有提示的輸入
pitch_s = raw_input("Enter Pitch 200 to 2000): ") duration_s = raw_input("Enter Duration second): ")

★def buzz(pitch, duration) :    頻率  時間
 period = 1.0 / pitch            period 是週期,振動一次花的時間
 half_period = period / 2
 cycles = int(duration * pitch)  頻率 X 時間  = 總共振動的次數
 for i in xrange(cycles) :
     GPIO.output(buzzer_pin, GPIO.HIGH)
     time.sleep(half_period)
     GPIO.output(buzzer_pin, GPIO.LOW)
     time.sleep(half_period)




linux 指令筆記


  • python abc.py &     會使程式背景執行