Linking Python and Arduino to display IME On / Off with LED

Overview

I couldn't remember IME On / Off, so I decided to rely on the machine. Get the IME status in Python and tell Arduino via serial communication.

Python Use the additional modules below. Please install with pip etc.

python.py


from ctypes import *
from time import sleep
import win32gui
import win32con
import win32api
import serial

imm32 = WinDLL("imm32")

while True:
     hWnd1 = win32gui.GetForegroundWindow()
     hWnd2 = imm32.ImmGetDefaultIMEWnd(hWnd1)
     #0x005 below is IMC_Indicates GET OPEN STATUS.
     IMEStatus = win32api.SendMessage(hWnd2 ,  win32con.WM_IME_CONTROL, 0x005, 0)
     
     #Change COM7 according to the serial port to connect to.
     ser = serial.Serial('COM7',9600)
     if IMEStatus == 0:
          ser.write(b"b")
     else:
          ser.write(b"a")
     ser.close()
     sleep(0.05)  #Seconds (=50ms)

Arduino It receives it serially and judges whether the LED is on or off.

arduino.ino


const int PinLED = 13;

int responseDelay = 10;  //Milliseconds
char input_char;

pinMode(PinLED, OUTPUT);
Serial.begin(9600);

void loop() {
if (Serial.available() >0){
    input_char = Serial.read(); 

    if(input_char == 'a'){
      digitalWrite(PinLED, HIGH); 
    }else{
      digitalWrite(PinLED, LOW);
    }
 delay(responseDelay);
}


Recommended Posts

Linking Python and Arduino to display IME On / Off with LED
[Ev3dev] How to display bmp image on LCD with python
Robot running with Arduino and python
Python 3.6 on Windows ... and to Xamarin.
Try to display google map and geospatial information authority map with python
Calculate and display standard weight with python
Fractal to make and play with Python
A memo with Python2.7 and Python3 on CentOS
How to display python Japanese with lolipop
Linking python and JavaScript with jupyter notebook
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
Connect to VPN with your smartphone and turn off / on the server
Use python on Raspberry Pi 3 to light the LED with switch control!
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Scraping tabelog with python and outputting to CSV
MessagePack-Try to link Java and Python with RPC
Strategy on how to monetize with Python Java
Interactively display algebraic curves with Python and Jupyter
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Introduction to Python with Atom (on the way)
Connect to MySQL with Python on Raspberry Pi
Try to make BOT by linking spreadsheet and Slack with python 2/2 (python + gspread + slackbot)
Try to make BOT by linking spreadsheet and Slack with python 1/2 (python + gspread + slackbot)
[Python] Convert time display (str type) using "" "and"'" to seconds (float type) with datetime and timedelta
Procedure to load MNIST with python and output to png
Notes on HDR and RAW image processing with Python
I want to handle optimization with python and cplex
I tried to implement Minesweeper on terminal with python
Install selenium on Mac and try it with python
Yum command to access MySQL with Python 3 on Linux
Try to operate DB with Python and visualize with d3
Automatic follow on Twitter with python and selenium! (RPA)
It's too troublesome to display Japanese with Vim's python3.
Get comments on youtube Live with [python] and [pytchat]!
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
I want to AWS Lambda with Python on Mac!
Display and shoot webcam video with Python Kivy [GUI]
Email hipchat with postfix, fluentd and python on Azure
Automate Chrome with Python and Selenium on your Chromebook
Output to "7-segment LED" using python on Raspberry Pi 3!
Python> function> Docstrings> Description to display with help () / .__ doc__
Something to enjoy with Prim Pro (X-Play) and Python
Scraping with Python + Selenium to add Apple refurbished products to your cart and notify on line
Easy to use Nifty Cloud API with botocore and python
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
Try to display various information useful for debugging with python
ArcPy-Introduction to Geoprocessing with Python with Scripting Tools on ArcGIS Pro-
Application to display and search local memos (diary) in Python
[Python] Read the csv file and display the figure with matplotlib
[Python] How to play with class variables with decorator and metaclass
IP spoof using tor on macOS and check with python
Test Python with Miniconda on OS X and Linux with travis-ci
Send experiment results (text and images) to slack with Python
Display numbers and letters assigned to variables in python print
Install pyenv on MacBook Air and switch python to use
Try to bring up a subwindow with PyQt5 and Python
How to do Bulk Update with PyMySQL and notes [Python]
[Let's play with Python] Image processing to monochrome and dots
Notes on deploying pyenv with Homebrew and managing Python versions
Save images on the web to Drive with Python (Colab)
Convert video to black and white with ffmpeg + python + opencv