[問題] 對ArduinoUNO的serial寫入資料
大家好
最近被實驗室要求組裝OpenDAC(http://opendacs.com/seekat-homepage/)
(將幾塊板子和電子材料裝起來,用Arduino控制的DAC)
雖然之前沒碰過Arduino和Python,好在網站有範例程式碼
現在問題是實驗室超級控Python,要求將所有用的的程式都轉成Python
原始的程式是Matlab的
其他部分我都沒問題,只有fwrite一行解決的東西我不知道如何轉換至python
原始Matlab程式碼:http://opendacs.com/seekat-homepage/seekat-write-voltage/
a = serial(‘/dev/tty.usbmodem1431′,’BaudRate’,115200); fopen(a)
...中間省略,可得出n1,n2,d1,d2,m1,m2,六個整數
fwrite(a,[255,254,253,n1,d1*m1,d2*m1,n2,d1*m2,d2*m2]);
[255,254,....] =>為一串小於256的整數,數量為九
我Python的程式碼:
Ser = serial.Serial(port='/dev/cu.usbmodem1411', baudrate=115200)
data = [255, 254, 254.....]
以下都試過無效:
1. Ser.write(data))
2. for 1 in range(0,9): Ser.write(data[i])
3. for 1 in range(0,9): Ser.write(bin(data[i]))
...ord(),一個一個位元送等等都試過了
想請問一下要如何達成Matlab內,fwrite 的效果
謝謝
ps.Arduino控制碼http://opendacs.com/seekat-homepage/seekat-code/
電路:http://goo.gl/acBhdi
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 128.135.29.158
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1468350920.A.C85.html
→
07/13 07:32, , 1F
07/13 07:32, 1F
→
07/13 07:35, , 2F
07/13 07:35, 2F
→
07/13 07:36, , 3F
07/13 07:36, 3F
→
07/13 08:19, , 4F
07/13 08:19, 4F
→
07/13 08:21, , 5F
07/13 08:21, 5F
→
07/13 10:14, , 6F
07/13 10:14, 6F
→
07/13 23:54, , 7F
07/13 23:54, 7F
→
07/14 07:25, , 8F
07/14 07:25, 8F
→
07/14 23:24, , 9F
07/14 23:24, 9F
→
07/15 01:14, , 10F
07/15 01:14, 10F
→
07/15 07:03, , 11F
07/15 07:03, 11F
→
07/15 08:40, , 12F
07/15 08:40, 12F
Python 近期熱門文章
PTT數位生活區 即時熱門文章