使用 Pixetto.py 類別,以讀取感測器數據。

步驟一,權限設定。Linux用戶可參考以下指令,取得硬體存取權限。

$ ls -l /dev/ttyACM0 
crw-rw---- 1 root dialout 166, 0 Apr 24 10:08 /dev/ttyACM0

$ sudo adduser user1 dialout
Adding user `user1' to group `dialout' ...
Adding user user1 to group dialout
Done.

步驟二、安裝序列埠(串口)工具

$ pip3 install pyserial

步驟三、下載 Pixetto library for Python。

https://learn.pixetto.ai/wp-content/uploads/pixetto-files/python3-pixetto-1.4.0.zip

步驟四,執行範例程式。

from pixetto import Pixetto
pix = Pixetto()

# Windows
#pix.open("COM3")   # com port id of Pixetto

# Linux
pix.open("/dev/ttyACM0")   # com port id of Pixetto

while True:
    if pix.is_detected() == True:
        print(pix.get_raw_data())
        fid, num, objs = pix.get_data_list()
        for i in range(num):
            print(' - [{}:{}] type:{} at x:{}, y:{}, w:{}, h:{}'.format(fid, i,
                  objs[i]['type'], objs[i]['x'], objs[i]['y'],
                  objs[i]['w'], objs[i]['h']))
pix.close()