LoginSignup
6
2

More than 5 years have passed since last update.

python の pyserial で 自動でarduino unoに接続する

Posted at

arduinoを接続したら、自動で検出して接続させる

接続したらシリアルポートの選択とかしないで、スタートさせたい。
ちなみにarduino nanoとかは応用すればできます。

環境

macbook pro
macOS High sierra
python 3.6.5

やり方

とりあえずインストール

bash
pip install pyserial

コード

*.py
import serial
import serial.tools.list_ports

ser = serial.Serial()
ser.baudrate = 115200
devices = serial.tools.list_ports.comports()
for device in devices:
    if device.usb_description()=='Arduino Uno':
        ser.port=device[0]
ser.open()
while True:
    line = ser.readline().decode('utf8').rstrip()
    print(line)
6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2