참고 사이트 : https://roboindia.com/tutorials/python-with-arduino
Arduino
- 변수 선언
data
- Setup
Serial.begin(speed) ; speed = baud rate (초당 얼마나 많은 심볼(Symbol, 의미 있는 데이터 묶음)을 전송할 수 있는가, 초당 신호(Signal) 요소의 수)
More detail about function :
https://www.arduino.cc/reference/ko/language/functions/communication/serial/begin/
Bit Rate와 Baud Rate의 정의 참고 :
pinmode(pin, mode) ; 특정핀을 입력 또는 출력으로 동작하도록 설정
more detail : https://www.arduino.cc/reference/ko/language/functions/digital-io/pinmode/
digitalWrite(pin, value) ; high 또는 low 값을 디지털 핀에 출력합니다.
핀이 pinMode()에서 OUTPUT -> 핀의 전압은 5V(HIGH) / 0V (LOW ;ground)
INPUT -> 입력 핀의 내부 풀업 저항을 활성화 (HIGH) / 비활성화 (LOW)
내장 풀업 저항을 활성화하기 위해서는 pinMode() 를 INPUT_PULLUP 으로 설정
pinMode() 를 OUTPUT 으로 설정하지 않고 LED를 핀에 연결하면, digitalWrite(HIGH) 가 불릴 때 LED 불빛이 흐리게 나타날 수 있습니다. 명시적으로 pinMode() 를 설정하지 않으면 digitalWrite() 는 내부 풀업 저항을 활성화시킬 것이고, 그것은 마치 전류를 제한하는 큰 저항처럼 동작할 것입니다.
More detail about function :
https://www.arduino.cc/reference/ko/language/functions/digital-io/digitalwrite/
Serial.println() ; serial에 글자 또는 숫자 출력 + 줄바꿈
Serial.print()와 Serial.println() 함수 :
- Loop
While 내부 ; Serial.available() ; 결과값 = 시리얼 통신으로 수신한 데이터의 길이(바이트 단위)
코드 의미 = 수신한 데이터가 있으면 읽어와라
python

Error
- Invalid syntax

Please note that 64-bit version or updated versions of python are not provide support for our Arduino Libraries. Even if your Computer is 64-bit machine. And this installation is applicable only for windows 32-bit or 64-bit OS.
Solution : Download 32-bit version python.
You may download it here :
http://www.python.org/ftp/python/2.7.9/python-2.7.9.msi

- No module ‘arduino’
pyserial is python API module to read and write serial data.
Solution : Download pyserial.
You may download it here :
Result

Python 입력으로 LED control 가능
Time delay 내에 입력하면 반짝반짝도 가능 (0101010)
cf )
python은 idle로 실행 (다운로드 받은 코드도 idle로 실행)
Arduino down (https://www.arduino.cc/en/Main/Donate) just download
Arduino 컴퓨터에 연결하고 툴 – 포트 체크
Arduino 내장 blink (파일 – 예제 – 1. Basics – blink)
Serial monitor : 아두이노와 컴퓨터간에 메세지를 주고 받는 장치, 실행창 (단축키 Ctrl + Shift + M)
