2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PATLITE PHU-3 をPythonから操作する

Last updated at Posted at 2022-02-06

image.png
これをPythonから制御してみます。

1.ドライバをインストール(Windowsのみ)
 こちらからドライバをダウンロードしてインストールします

2.ポートを調べる

port_check.py
import sys
import glob
import serial
 
 
def serial_ports():
    """ Lists serial port names
 
        :raises EnvironmentError:
            On unsupported or unknown platforms
        :returns:
            A list of the serial ports available on the system
    """
    if sys.platform.startswith('win'):
        ports = ['COM%s' % (i + 1) for i in range(256)]
    elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
        # this excludes your current terminal "/dev/tty"
        ports = glob.glob('/dev/tty[A-Za-z]*')
    elif sys.platform.startswith('darwin'):
        ports = glob.glob('/dev/tty.*')
    else:
        raise EnvironmentError('Unsupported platform')
 
    result = []
    for port in ports:
        try:
            s = serial.Serial(port)
            s.close()
            result.append(port)
        except (OSError, serial.SerialException):
            pass
    return result
 
 
if __name__ == '__main__':
    print(serial_ports())

3.調べたポートにバイナリを送る

 image.png
調べたポート(下記ではCOM6)に0-7のバイナリを送ります。

send_data.py
import serial
import time

ser = serial.Serial('COM6', 19200)
for num in range(9):
    ser.write(bytes([num]))
    time.sleep(1)
ser.close()

動画

おまけ
PHU-3-RYG(青LEDなし)でも青への信号は出ているようです。

1 9
5V R Y - - G B - -

IMG_0762.jpg

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?