2016년 5월 17일 화요일

Raspberry Pi - LED를 이용한 GPIO 출력 테스트

Raspberry Pi의 GPIO를 이용하여 간단한 LED를 켜는 테스트를 해 보자. 테스트에 앞서 wiringPi가 설치되어 있지 않다면 wiringPi를 먼저 설치하도록 한다.

테스트 회로는 다음과 같이 발광 다이오드의 (+)를 1번에 연결하고 (-)를 GND에 연결하였으며 (+)와 1번 사이에 250Ω의 저항을 연결하였다.

※ LED의 극성을 반대로 연결하면 LED가 고장 나므로 주의해서 연결한다. 길이가 짧은 쪽이(-), 긴 쪽이 (+)이다. 

회로 및 구성

  • Raspberry Pi 2 Model B
  • LED (동작 전압: 1.8V ~ 2.3V)
  • 저항 250Ω




테스트를 위해 다음과 같이 코드를 작성한다.
#include <wiringPi.h>

#define LED1 1

int main(void)
{
  if(wiringPiSetup() == -1)
    return 1;

  pinMode(LED1, OUTPUT);
  digitalWrite(LED1, 1);

  return 0;
}

코드를 컴파일 하고 실행 시킨다.

pi@raspberrypi ~$ gcc -o ledtest ledtest.c -lwiringPi
pi@raspberrypi ~$ sudo ./ledtest

프로그램이 실행되면 LED에 불이 들어오는 것을 확인할 수 있다.

Related Posts:

  • Raspberry Pi - GPIO input test with ButtonLet's turn on LED when a button is pushed. Before the test, wiringPi must be installed. The test circuit is shown as in figure. one leg of button is … Read More
  • Raspberry Pi - wiringPi InstallationOne method to use GPIO Port of raspberry pi is using wiringPi. Basic information and guide is in wiringPi web site. http://wiringpi.com/ wiringPi ca… Read More
  • Rasbperry Pi - wiringPi 설치Raspberry Pi에서 GPIO Port를 사용할 수 있는 방법 중 하나는 wiringPi를 이용하는 것이다. wiringPi에 대한 기본적인 사용 방법 및 wiringPi 홈페이지에서 확인할 수 있다. http://wiringpi.com/ wiringPi는 소… Read More
  • Raspberry Pi - PIR Motion Sensor 테스트PIR Motion Sensor는 적외선으로 움직임을 감지하는 센서로 일정한 범위 내에 적외선을 방출하는 물체가 움직일 경우 이를 감지하여 출력 신호로 내보낸다. 센서에 대한 자세한 사양은 다음 웹페이지에서 확인할 수 있으며 테스트를 위해서는 wiringPi가 설치되어… Read More
  • Raspberry Pi - PIR Motion Sensor testPIR motion sensor used to detect whether a object which emits infrared radiation has moved in or out the sensor range. If the sensor detect a moving o… Read More

0 개의 댓글:

댓글 쓰기