[예제] python Arduino LED blinking

참고 사이트 : 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 :

https://pypi.python.org/packages/47/c9/7802e11ab388ad1539de716649add8bb8ca8bdff660364b3a404f79c27b7/pyserial-2.7.win32.exe#md5=21555387937eeb79126cde25abee4b35

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)

광고

답글 남기기

아래 항목을 채우거나 오른쪽 아이콘 중 하나를 클릭하여 로그 인 하세요:

WordPress.com 로고

WordPress.com의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Twitter 사진

Twitter의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

Facebook 사진

Facebook의 계정을 사용하여 댓글을 남깁니다. 로그아웃 /  변경 )

%s에 연결하는 중