發表文章

目前顯示的是有「pybluez」標籤的文章

[ Arduino ] 使用 PyBluez對 Arduino發送訊息

圖片
第一次學寫 Arduino,先試個水溫使用 Pybluez對 Arduino發送訊息。 Arduino的部分 #include <liquidcrystal.h> #include <softwareserial.h> LiquidCrystal lcd(12,11,5,4,3,2); SoftwareSerial BT(9, 10); void setup() { lcd.begin(16,2); BT.begin(9600); BT.setTimeout(10); lcd.print("Hello, world!"); } void loop() { if (BT.available()) // if text arrived in from BT serial... { String cod=(BT.readString()); lcd.setCursor(0,0); // choose first line of LCD lcd.print(cod); } } 安裝 PyBluez 安裝前請先參閱各平台的 Requirement 。 Windows或 Linux應該是可以直接安裝 $ pip install pybluez 我使用的是 MacOS,但 Python的 Bluetooth packages中似乎對 MacOS沒有很好的支援,甚至無法直接使用 pip安裝。 不過 GitHub上都沒有提出這類 issues,有可能我是個案 :P $ pip install git+https://github.com/pybluez/pybluez.git 安裝後會在 packages中找到 lightblue資料夾,當中會有一個檔案 _bluetoothsockets.py。 class _BluetoothSocket(object): ... def send(self, data, flags=0): # if not isinstance(data, str): # raise TypeError("data must be string...