安裝完成HA後,接著就是要進行設定的工作
在左邊選單列中,選擇Supervisor,再到右邊畫面,上方選擇附加元件商店,安裝我們需要的套件包
點選 MQTT broker ,並於上方選擇[設定]
這邊有變動到的就只有使用者帳號與密碼,都修改為tester,可依自己需要做修改
在在最後面加入
mqtt: discovery: true broker: 127.0.0.1 username: tester password: tester
MQTT broker設定就算完成了
/* 自定義代碼塊樣式 */
安裝完成HA後,接著就是要進行設定的工作
mqtt: discovery: true broker: 127.0.0.1 username: tester password: tester
markdown
Home Assistant 我是用官方的映象檔安裝在樹莓派上使用,下載的檔案就直接燒錄在SD卡即可,這邊我使用的燒錄軟體是Rufus。
但別急著插進樹莓派開機,還要設定WiFi連線,才能讓樹莓派連上網路
在SD卡根目錄下,新增一個CONFIG的目錄,裡面再新增一個network目錄
在network目錄內,增加一個文字檔案 my-network
[connection] id=resin-wifi type=wifi [wifi] hidden=true mode=infrastructure ssid=你的SSID名稱 [ipv4] method=auto [ipv6] addr-gen-mode=stable-privacy method=auto [wifi-security] auth-alg=open key-mgmt=wpa-psk psk=你的Wifi密碼
把ssid與wifi密碼修改完後,就可以插入樹莓派開機了
插入電源開機。第一次開機HA會自動下載最新版的 Home Assistant 並執行,耗時約 20 分鐘。
在等待更新的過程中,也可以打開瀏覽器輸入 http://hassio.local:8123 或是http://homeassistant.local:8123 看到HA的畫面
等待更新結束後,會看到建立帳號的畫面,就依照畫面指示,完成資料填寫即可
手邊有兩個USB to Uart 的傳輸線都不能使用,可能是PL2303又掛了,所以這次不使用2303的IC,想要改裝成CH340的試試
從官網上查到有一個CH340N type,封裝只有8 pin,又不用外加振盪器,就入手了幾顆進行測試
首先當然是把PL2303從板子上移開,振盪器也卸除掉,如下圖
接著找看看有沒有相關的Pin 腳可以直接焊接就好
MEASure:VOLTage:DC?;:MEASure:CURRent:AC?當然首先要先安裝電腦端的驅動程式,因為電表是使用Keysight的,所以就上Keysight網站找驅動程式了,下載網址
'--- General define ---
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'declare to use "sleep"
Dim ioMgr As VisaComLib.ResourceManager
Dim instrument As VisaComLib.FormattedIO488
'--- function define ---
Dim ioMgr As VisaComLib.ResourceManagerDim instrument As VisaComLib.FormattedIO488
Dim sndBuffer As String
Dim rcvBuffer As String
Set ioMgr = New VisaComLib.ResourceManager
Set instrument = New VisaComLib.FormattedIO488
Set instrument.IO = ioMgr.Open("USB0::10893::4865::MY59022278::0::INSTR")
instrument.SetBufferSize IO_IN_AND_OUT_BUFS, 64instrument.WriteString "*IDN?" Debug.Print instrument.ReadString讀取電壓與電流的程式如下
'--------------------------
' Volt
'--------------------------
status = commSend(instrument, "SENSe:VOLTage:DC:NULL:VALue:AUTO 1")
status = commSend(instrument, "CONFigure:VOLTage:DC 10,0.001") ' mV resolution
status = commSend(instrument, "SAMPle:COUNt 1")
status = commSend(instrument, "*WAI")
rcvBuffer = commQuery(instrument, "READ?")
'--------------------------
' Current
'--------------------------
status = commSend(instrument, "SENSe:CURRent:DC:NULL:VALue:AUTO 1")
status = commSend(instrument, "CONFigure:CURRent:DC 1E-6")
status = commSend(instrument, "CURRent:DC:RES 1E-6") ' uA resolution
status = commSend(instrument, "SAMPle:COUNt 1")
status = commSend(instrument, "*WAI")
rcvBuffer = commQuery(instrument, "READ?")
電表是使用USB連接,後來要控制R&S示波器,就想改用TCP/IP的方式試試,也是OK的喔,下面列出幾個範例,讀取波形電壓平均值、上升時間及波形的各點電壓資料'==================================
' R&S RTM3004 波形平均值
'==================================
instrument.WriteString "TRIGger:A:EDGE:SLOpe NEGative"
instrument.WriteString "MEASurement1:SOURce CH2"
instrument.WriteString "MEASurement1:MAIN MEAN"
instrument.WriteString "MEASurement1:RESult? MEAN"
'==================================
'Measure rise time
'==================================
instrument.WriteString "TRIGger:A:EDGE:SLOpe NEGative"
instrument.WriteString "MEASurement1:SOURce CH2"
instrument.WriteString "REFLevel:RELative:MODE TEN" ' 10% - 90%
instrument.WriteString "MEASurement1:MAIN RTIMe"
instrument.WriteString "MEASurement1:RESult?"
'==================================
' Wave RAW data
'==================================
instrument.WriteString "TRIGger:A:MODE NORMal" ' Normal trigger
instrument.WriteString "TRIGger:A:EDGE:SLOpe NEGative" ' Negative edge
instrument.WriteString "FORM ASC" ' output format ASCii
instrument.WriteString "FORM:BORD LSBF"
instrument.WriteString "CHAN1:DATA:POIN DEF"
instrument.WriteString "SINGle" ' Single trigger
instrument.WriteString "CHANnel1:DATA:HEAD?"
Debug.Print instrument.ReadString
instrument.WriteString "CHANnel1:DATA?"
Debug.Print instrument.ReadString
下面是UART、USB與TCP/IP的宣告方式'=========
'UART
'=========
Set instrument.IO = ioMgr.Open("ASRL6::INSTR") ' COM6
Dim serInfc As VisaComLib.ISerial
Set serInfc = instrument.IO
serInfc.BaudRate = 9600 ' 9600bps baud rate
serInfc.FlowControl = ASRL_FLOW_NONE
serInfc.Timeout = 10000
instrument.IO.SendEndEnabled = True
instrument.IO.TerminationCharacter = 10 ' could be 10 (line feed) or 13 (carriage return)
instrument.IO.TerminationCharacterEnabled = True
instrument.IO.Timeout = 10000
'=========
'USB
'=========
Set instrument.IO = ioMgr.Open("USB0::0x0AAD::0x01D6::104068::INSTR")
instrument.SetBufferSize IO_IN_AND_OUT_BUFS, 64
Set serInfc = instrument.IO
'=========
'TCP/IP
'=========
Set instrument.IO = ioMgr.Open("tcpip0::192.168.0.13::instr") ' ip addr 192.168.0.13
instrument.SetBufferSize IO_IN_AND_OUT_BUFS, 64
Set serInfc = instrument.IO
下面是用Arduino與ADS1015做的4通道電表,解析度至小數第二位,使用VBA透過UART讀取電表至Excel表格中Adafruit_USBD_HID usb_hid; #define USB_VID 0xCafe #define USB_PID 0x4011 #define USB_MANUFACTURER "ESP32S3" #define USB_PRODUCT ...