전체 40개 핀중 26개만 GPIO(general purpose input output) 포트로 사용할 수 있음.
14개 핀은 3.3V GND 등 사전 지정된 핀임.
GPIO 14(UART_TXD) 이런건 둘다 기능이 가능한것.
GPIO 18번과 저항하고 연결해야함.
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include <stdlib.h>
#include <unistd.h>
int ledControl(int gpio)
{
int fd;
char buf[BUFSIZ];
fd = open("/sys/class/gpio/export", O_WRONLY);
sprintf(buf, "%d", gpio);
write(fd, buf, strlen(buf));
close(fd);
sprintf(buf, “/sys/class/gpio/ gpio%d/direction”, gpio);
fd = open(buf, O_WRONLY);
write(fd, “out”, 3);
close(fd);
sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
fd = open(buf, O_WRONLY);
write(fd, "1", 1);
close(fd);
getchar();
fd = open("/sys/class/gpio/unexport", O_WRONLY); //GPIO 18
sprintf(buf, "%d", gpio);
write(fd, buf, strlen(buf));
close(fd);
return 0;
}
int main(int argc, char **argv[])
{
int gno;
if(argc < 2)
{
printf(“input error \n”);
return -1;
}
gno = atoi(argv[1]);
ledControl(gno);
return 0;
}
듀티 사이클을 사용함.
한 주기 내에서 ON/OFF
13번 핀 주기는 0.5초 dutycycle 은 50%
10-2 R3 라즈베리파이 센서 제어 및 원격제어
시리얼 통신 = 한번에 한비트만 보내는.
아날로그 신호를 ADC 칩으로 디지털로 변환해서 라즈베리 파이로 보내줌.
SPI
26 번에서 초기화 29 번에서 핀세팅
77~80 이 추가된것. 나머지는 채팅서버와 동일.