LoginSignup
3
1

More than 5 years have passed since last update.

IoT Python USB Relay その1

Last updated at Posted at 2018-09-27

1000円ぐらいで買えるUSB RelayをPythonでプログラムする。

リレーとは、電気的にOn Offできる装置です。Pythonからコマンドを送ると100V AC電源をOn または、Offできます。

つまり音声入力と組み合せば「電気をつけろ」といえば電気をつけます。

cap1.JPG

品名 1 x LCUS-1 5V USB Relay Module CH340 USB Intelligent Control Switch Relay Module for Smart Home (12488) = $6.28

  • トラッキング付きの送料込みで1000円でおつりくるぐらいかなぁ。
  • tracking.PNG

  • 別にこれでなくても「CH340」チップの名前だからキーワードに検索してください。

USBに差し込むと

cap1000.PNG

Windows 10 の場合、 自動的ドライバーがインストールされCOM4に接続されていることがわかる

準備

>pip install serial

コマンドモードで実験

>python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> on =bytearray(b"\xA0\x01\x01\xA2")
>>> off=bytearray(b"\xA0\x01\x00\xA1")
>>> ser = serial.Serial('COM4', 9600,timeout=0)
>>> ser.write(on)
4
>>> ser.write(off)
4
>>> ser.close()
>>>

つづく

3
1
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
3
1