레이블이 pi인 게시물을 표시합니다. 모든 게시물 표시
레이블이 pi인 게시물을 표시합니다. 모든 게시물 표시

2016년 5월 24일 화요일

Raspberry Pi - PIR Motion Sensor test

PIR 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 object, it make output signal. More infromation about the sensor can be found in the following web page. In order to test, the wiringPi must be installed.

http://www.dfrobot.com/wiki/index.php/PIR_Motion_Sensor_V1.0_SKU:SEN0171

The test circuit is shown as in figure.

Component

  • Raspberry Pi 2 Model B
  • PIR Motion Sensor (DFROBOT SEN0171)


In order to test, make a simple code which is pirTest.c

#include <stdio.h>
#include <wiringPi.h>

#define PIR 1

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

  pinMode(PIR, INPUT);

  int input = 0;

  for(;;)
  {
    if(digitalRead(PIR))
      printf("Motion Detected!\n");

    delay(100);
  }

  return 0;
}

Compile and run the program.

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

When a moving object is detected, "Motion Detected" message will be printed.

2016년 5월 20일 금요일

Raspberry Pi - wiringPi Installation

One method to use GPIO Port of raspberry pi is using wiringPi. Basic information and guide is in wiringPi web site.

http://wiringpi.com/

wiringPi can be downloaded form git. So git must be installed first.

pi@raspberrypi ~$ sudo su -
root@raspberrypi:~# aptitude install git
root@raspberrypi:~# exit
pi@raspberrypi ~$ git clone git://git.drogon.net/wiringPi
Cloning into 'wiringPi'...
remote: Counting objects: 657, done.
remote: Compressing objects: 100% (599/599), done.
remote: Total 657 (delta 476), reused 95 (delta 58)
Receiving objects: 100% (657/657), 247.61 KiB | 94 KiB/s, done.
Resolving deltas: 100% (476/476), done.

Build from source code.

pi@raspberrypi ~$ cd wiringPi
pi@raspberrypi ~/wiringPi$ ./build

Pin Layout can be checked by gpio readall command.



Rasbperry Pi - wiringPi 설치

Raspberry Pi에서 GPIO Port를 사용할 수 있는 방법 중 하나는 wiringPi를 이용하는 것이다. wiringPi에 대한 기본적인 사용 방법 및 wiringPi 홈페이지에서 확인할 수 있다.

http://wiringpi.com/

wiringPi는 소스 코드는 git에서 받을 수 있으며, 코드를 빌드 하는것으로 설치는 끝난다. git이 설치되어 있지 않다면 git을 먼저 설치한다.

pi@raspberrypi ~$ sudo su -
root@raspberrypi:~# aptitude install git
root@raspberrypi:~# exit
pi@raspberrypi ~$ git clone git://git.drogon.net/wiringPi
Cloning into 'wiringPi'...
remote: Counting objects: 657, done.
remote: Compressing objects: 100% (599/599), done.
remote: Total 657 (delta 476), reused 95 (delta 58)
Receiving objects: 100% (657/657), 247.61 KiB | 94 KiB/s, done.
Resolving deltas: 100% (476/476), done.

받은 코드를 빌드한다.

pi@raspberrypi ~$ cd wiringPi
pi@raspberrypi ~/wiringPi$ ./build

Pin Layout은 gpio readall 명령으로 확인 할 수 있다. wiringPi는 자체 Pin Map을 사용하는데 wPi로 표시된 부분은 wiringPi에서 사용하는 GPIO 핀 번호이다.

pi@raspberrypi ~$ gpio readall

다음은 Raspberry Pi Model B+ 기준의 Pin Map이다.








2016년 5월 19일 목요일

Raspberry Pi - PIR Motion Sensor 테스트

PIR Motion Sensor는 적외선으로 움직임을 감지하는 센서로 일정한 범위 내에 적외선을 방출하는 물체가 움직일 경우 이를 감지하여 출력 신호로 내보낸다. 센서에 대한 자세한 사양은 다음 웹페이지에서 확인할 수 있으며 테스트를 위해서는 wiringPi가 설치되어 있어야 한다.

http://www.dfrobot.com/wiki/index.php/PIR_Motion_Sensor_V1.0_SKU:SEN0171

테스트 회로는 그림과 같이 PIR Motion Sensor에 5V의 입력 전압을 연결하고 움직임이 감지되었을 때 나오는 출력 전압을 GPIO의 1번에 연결하였다.

회로 및 구성

  • Raspberry Pi 2 Model B
  • PIR Motion Sensor (입력 전압: 3.3 ~ 5V, 출력 전압: High 3V, Low 0V)




테스트를 위해 pir.c 코드를 다음과 같이 작성한다.

#include <stdio.h>
#include <wiringPi.h>

#define PIR 1

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

  pinMode(PIR, INPUT);

  int input = 0;

  for(;;)
  {
    if(digitalRead(PIR))
      printf("Motion Detected!\n");

    delay(100);
  }

  return 0;
}

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

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

Raspberry Pi - GPIO input test with Button

Let'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 connect to 5V output pin and another leg is connect to #1 pin of GPIO and 10kΩ pull-down resistor is used to prevent floating state.  In order to monitor button state, LED is used.

※ Be careful!!. If LED is connected to reverse polarity, it will be broken. Long leg is positive(+) and short leg is negative(-).

Component
  • Raspberry Pi 2 Model B
  • Push Button
  • LED(Operating Voltage: 1.8V ~ 2.3V)
  • Resistor 250Ω, 10kΩ 


In order to test, make a simple code which is buttonTest.c

#include <wiringPi.h>

#define LED 4
#define BUTTON 1

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

  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);

  digitalWrite(LED, 0);
  int input = 0;

  for(;;)
  {
    if(digitalRead(BUTTON))
      digitalWrite(LED, 1);
    else
      digitalWrite(LED, 0); 

    delay(100);
  }

  return 0;
}

Compile and run the program.

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

When the button is pushed, LED will be turned on.

2016년 5월 18일 수요일

Raspberry Pi - Button을 이용한 GPIO 입력 테스트

Raspberry Pi의 GPIO를 이용하여 버튼이 눌러졌을 때 LED를 켜는 테스트를 해 보자. 테스트를 위해서는 기본적으로 wiringPi가 설치되어 있어야 한다.

테스트 회로는 그림과 같이 Push Button을 눌렀을 때 1번 Pin에 High가 인가 되도록 5V를 연결하였으며 10kΩ의 Pull-down 저항을 연결하였다. LED는 버튼이 눌러진 것을 확인하기 위해 연결하였다.

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

회로 및 구성

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




테스트를 위해 buttonTest.c 코드를 다음과 같이 작성한다.

#include <wiringPi.h>

#define LED 4
#define BUTTON 1

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

  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);

  digitalWrite(LED, 0);
  int input = 0;

  for(;;)
  {
    if(digitalRead(BUTTON))
      digitalWrite(LED, 1);
    else
      digitalWrite(LED, 0); 

    delay(100);
  }

  return 0;
}

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

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


버튼을 누르면 LED에 불이 들어오는 것을 확인할 수 있다.

Raspberry Pi - GPIO output test with LED

Let's turn on LED using a Raspberry Pi GPIO port. Before the test, wiringPi must be installed. 

※ Be careful!!. If LED is connected to reverse polarity, it will be broken. Long leg is positive(+) and short leg is negative(-).

Component
  • Raspberry Pi 2 Model B
  • LED (Operating Voltage: 1.8V ~ 2.3V)
  • Resistor 250Ω





In order to test, make a simple code which is ledtest.c

#include <wiringPi.h>

#define LED1 1

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

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

  return 0;
}

Complie and run the program.

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


After run the program, LED will be turned on.

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에 불이 들어오는 것을 확인할 수 있다.