{"id":1733,"date":"2013-01-28T11:15:11","date_gmt":"2013-01-28T02:15:11","guid":{"rendered":"http:\/\/www.pinewell.jp\/wordpress\/?p=1733"},"modified":"2013-01-28T11:15:11","modified_gmt":"2013-01-28T02:15:11","slug":"raspberrypi%e3%81%ae%e3%83%aa%e3%83%a2%e3%82%b3%e3%83%b3%e5%8c%96","status":"publish","type":"post","link":"https:\/\/www.pinewell.jp\/wordpress\/?p=1733","title":{"rendered":"RaspberryPi\u306e\u30ea\u30e2\u30b3\u30f3\u5316"},"content":{"rendered":"<p>\u3055\u3066\u30011\u6708\u3082\u3082\u3046\u7d42\u308f\u308a\u3002<br \/>\nUSB\u30ab\u30e1\u30e9+motion\u3067\u306f\u5b89\u5b9a\u3057\u3066\u52d5\u4f5c\u3067\u304d\u306a\u304b\u3063\u305fRaspberryPi\u3002<br \/>\n\u4f7f\u3044\u9053\u3092\u6a21\u7d22\u3057\u3066\u3044\u305f\u306e\u3060\u304c\u3001\u30ea\u30d3\u30f3\u30b0\u306b\u7f6e\u3044\u3066\u3042\u308bLS-GL\u3092Pi\u306b\u7f6e\u304d\u63db\u3048\u3088\u3046\u304b\u3068\u3002<br \/>\n\u3055\u3089\u306b\u3069\u3046\u305b\u306a\u3089\u5916\u90e8\u30b9\u30a4\u30c3\u30c1\u3067\u306e\u52d5\u4f5c\u3082\u3055\u305b\u305f\u3044\u3002<br \/>\n\u30a6\u30c1\u306fAQUOS\u306a\u306e\u3060\u304c\u3001\u672c\u4f53\u306b\u96fb\u6e90\u30dc\u30bf\u30f3\u304c\u7121\u3044\uff08\u30ea\u30e2\u30b3\u30f3\u306e\u96fb\u6e90\uff09\u3002<br \/>\n\u51fa\u304b\u3051\u308b\u969b\uff08\u672c\u4f53\u306e\u96fb\u6e90\u3092\u30aa\u30d5\u306b\u3057\u3066\u3082\u826f\u3044\u306e\u3060\u304c\uff09\u306b\u30ea\u30e2\u30b3\u30f3\u3092\u63a2\u3057\u3066\u30aa\u30d5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<br \/>\n\u30c6\u30ec\u30d3\u8fd1\u304f\u306b\u30bf\u30af\u30c8\u30b9\u30a4\u30c3\u30c1\u3092\u7528\u610f\u3057\u3066\u304a\u3051\u3070\u3053\u308c\u3067\u89e3\u6c7a\u3002<br \/>\n\u3055\u3089\u306b\u5165\u529b\u5207\u66ff\u304c\u6c17\u306b\u5165\u3089\u306a\u3044\u3002\u30dc\u30bf\u30f3\u3092\u4f55\u5ea6\u3082\u62bc\u3055\u306a\u304f\u3066\u306f\u306a\u3089\u306a\u3044\u3002<br \/>\n\u5e78\u3044AQUOS\u306b\u306fPC\u3068\u7e4b\u3052\u308b\u305f\u3081\u306eRS-232C\u304c\u3042\u308b\u306e\u3067\u3053\u308c\u3092\u5229\u7528\u3057\u306a\u3044\u624b\u306f\u306a\u3044\u3002<br \/>\nLS-GL\uff0bKURO-RS\u306e\u5b66\u7fd2\u30ea\u30e2\u30b3\u30f3\u3067\u306f\u89e3\u6c7a\u3067\u304d\u306a\u304b\u3063\u305f\u3053\u308c\u3089\u8ab2\u984c\u3092\u30af\u30ea\u30a2\u3057\u3088\u3046\u3001\u3068\u3002<\/p>\n<p><a href=\"http:\/\/www.pinewell.jp\/wordpress\/wp-content\/uploads\/2013\/01\/GPIOs-2-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.pinewell.jp\/wordpress\/wp-content\/uploads\/2013\/01\/GPIOs-2-131x300.png\" alt=\"GPIO\u30d4\u30f3\" title=\"GPIOs\" width=\"131\" height=\"300\" class=\"alignleft size-medium wp-image-1737\" srcset=\"https:\/\/www.pinewell.jp\/wordpress\/wp-content\/uploads\/2013\/01\/GPIOs-2-131x300.png 131w, https:\/\/www.pinewell.jp\/wordpress\/wp-content\/uploads\/2013\/01\/GPIOs-2.png 254w\" sizes=\"auto, (max-width: 131px) 100vw, 131px\" \/><\/a>\u307e\u305a\u3001raspi\u306eGPIO\u30dd\u30fc\u30c8\u306e\u5185\u30013V3POWER\u3068Ground\u3001TXD\u3068RXD\u3092\u7528\u3044\u3066\u3001AQUOS\u3068\u306e\u901a\u4fe1\u3092\u53ef\u80fd\u3068\u3059\u308b\u3002<br \/>\n3.3V\u306e\u30ec\u30d9\u30eb\u306a\u306e\u3067\u3001RS-232C\u3068\u306e\u63a5\u7d9a\u306e\u305f\u3081\u306b\u624b\u5143\u306b\u3042\u3063\u305fADM3202AN\u3092\u4f7f\u7528\u3002AQUOS\u3068\u306f\u30af\u30ed\u30b9\u7d50\u7dda\u3002<br \/>\n\u3068\u308a\u3042\u3048\u305a\u3001\u30b3\u30de\u30f3\u30c9\u3092\u9001\u3063\u3066\u96fb\u6e90\u30aa\u30d5\u306a\u308a\u304c\u51fa\u304d\u308b\u3053\u3068\u3092\u78ba\u8a8d\u30021\u6bb5\u968e\u30af\u30ea\u30a2\u3002<br \/>\n\u6b21\u306b\u3001\u30bf\u30af\u30c8\u30b9\u30a4\u30c3\u30c1\u306e\u53d6\u308a\u4ed8\u3051\u3002\u3053\u308c\u306f\u5f53\u521d\u30d7\u30ec\u30b9\u30c6\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u3082GPIO\u306b\u63a5\u7d9a\u3057\u3066\u3084\u308d\u3046\u304b\u3068<br \/>\n\u601d\u3063\u305f\u306e\u3060\u304c\u3001Arduino\u3067\u306e\u5b9f\u9a13\u306f\u6210\u529f\u3057\u305f\u3082\u306e\u306e\u3001raspi\u3067\u306e\u63a5\u7d9a\u4f8b\u306f\u63a2\u3057\u304d\u308c\u305a\u65ad\u5ff5\u3002<br \/>\n\u90e8\u6750\u306f\u63c3\u3048\u305f\u306e\u3067\u3044\u3064\u304b\u3084\u3063\u3066\u3084\u308d\u3046\u3068\u601d\u3046\u3002<br \/>\n\u30bf\u30af\u30c8\u30b9\u30a4\u30c3\u30c1\u306f6\u500b\u3002\u5de6\u753b\u50cf\u306e\u4e0b\u306e\u65b9\u306e\u30d4\u30f3\u3092\u4f7f\u7528\u3057\u305f\u3002GPIO7,8,9,10,11,25\u3002<br \/>\n\u3053\u308c\u30923.3V\u300110k\u30aa\u30fc\u30e0\u306e\u62b5\u6297\u3067\u30d7\u30eb\u30a2\u30c3\u30d7\u3057\u3066\u4f7f\u7528\u3057\u305f\u3002<br \/>\n\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u90e8\u306fC library for Broadcom BCM 2835 as used in Raspberry Pi \u3092\u4f7f\u7528\u3057\u3066\u4f5c\u6210\u3002<br \/>\n\u4ee5\u4e0b\u30bd\u30fc\u30b9\u3002<\/p>\n<pre lang=\"c\" line=\"\">\n#include <stdio.h>\n#include <stdlib.h>\n#include <bcm2835.h>\n#include <signal.h>\n\n#include <string.h>\n#include <strings.h>\n#include <termios.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <stdarg.h>\n#include <unistd.h>\n#include <syslog.h>\n#include <errno.h>\n\n\/\/\u30b9\u30a4\u30c3\u30c1\u306e\u30d4\u30f3\u5b9a\u7fa9\n#define SW1 RPI_V2_GPIO_P1_26\n#define SW2 RPI_V2_GPIO_P1_24\n#define SW3 RPI_V2_GPIO_P1_21\n#define SW4 RPI_V2_GPIO_P1_19\n#define SW5 RPI_V2_GPIO_P1_22\n#define SW6 RPI_V2_GPIO_P1_23\n\n\/\/\u30b9\u30a4\u30c3\u30c1\u30b3\u30de\u30f3\u30c9\n#define SW1_CMD \"\\rPOWR0000\\r\" \/\/POWER OFF\n#define SW2_CMD \"\\rIAVD1   \\r\" \/\/\u5165\u529b\u5207\u308a\u66ff\u30481\n#define SW3_CMD \"\\rIAVD2   \\r\" \/\/                   2\n#define SW4_CMD \"\\rIAVD3   \\r\"\n#define SW5_CMD \"\\rIAVD4   \\r\"\n#define SW6_CMD \"\\rIAVD5   \\r\"\n\n#define BAUDRATE B9600           \/* \u901a\u4fe1\u901f\u5ea6\u306e\u8a2d\u5b9a *\/\n#define MODEMDEVICE \"\/dev\/ttyAMA0\" \/* \u30c7\u30d0\u30a4\u30b9\u30d5\u30a1\u30a4\u30eb\u306e\u6307\u5b9a:COM1 *\/\n\n#define FALSE 0\n#define TRUE 1\n#define MC 4 \/* \u8aad\u307f\u8fbc\u3080\u6587\u5b57\u6570 *\/\nvolatile int STOP=FALSE;\n\nstatic void log_write(char *fmt, ...);\n\n\/\/ \u5272\u308a\u8fbc\u307f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\nvoid signal_callback_handler(int signum)\n{\n\t\/\/printf(\"\\ndetect key interrupt\\n\",signum);\n\tlog_write(\"detect interrupt\",signum);\n\tbcm2835_close();\n\tprintf(\"stop daemon\",0);\n\texit(0);\n}\n\n\/\/\u30b7\u30ea\u30a2\u30eb\u3078\u306e\u30b3\u30de\u30f3\u30c9\u9001\u4fe1\nint sendcmd(int cmdno) \n{ \n  int fd, c, res, i;             \/* fd:\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf res:\u53d7\u3051\u53d6\u3063\u305f\u6587\u5b57\u6570 *\/\n  struct termios oldtio, newtio; \/* \u901a\u4fe1\u30dd\u30fc\u30c8\u3092\u5236\u5fa1\u3059\u308b\u305f\u3081\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9 *\/\n  char buf[255];                 \/* \u53d7\u4fe1\u6587\u5b57\u3092\u683c\u7d0d *\/\n\n  if((fd=open(MODEMDEVICE, O_RDWR | O_NOCTTY))== -1){\n    \/* O_RDWR:\u8aad\u307f\u66f8\u304d\u4e21\u7528 O_NOCTTY:tty\u5236\u5fa1\u3092\u3057\u306a\u3044 *\/\n    perror(MODEMDEVICE);\n    return(-1);\n  }\n\n  tcgetattr(fd, &oldtio);          \/* \u73fe\u5728\u306e\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u306e\u8a2d\u5b9a\u3092\u9000\u907f\u3055\u305b\u308b *\/\n  bzero(&newtio, sizeof(newtio));  \/* \u65b0\u3057\u3044\u30dd\u30fc\u30c8\u306e\u8a2d\u5b9a\u306e\u69cb\u9020\u4f53\u3092\u30af\u30ea\u30a2 *\/\n\n  newtio.c_cflag= (BAUDRATE | CS8 | CLOCAL | CREAD);\n   \/* CRTSCTS:\u30d5\u30ed\u30fc\u5236\u5fa1\u6709\u308a CS8:8\u30d3\u30c3\u30c8\u3001\u30ce\u30f3\u30d1\u30ea\u30c6\u30a3\u3001\u30b9\u30c8\u30c3\u30d7\u30d3\u30c3\u30c8\uff11\n *       CLOCAL:\u30e2\u30c7\u30e0\u306e\u72b6\u614b\u4fe1\u53f7\u3092\u7121\u8996 CREAD:\u53d7\u4fe1\u53ef\u80fd\u306b\u3059\u308b *\/\n\n  newtio.c_iflag=IGNPAR;          \/* IGNPAR:\u30d1\u30ea\u30c6\u30a3\u30a8\u30e9\u30fc\u306e\u6587\u5b57\u306f\u7121\u8996 *\/\n\n  newtio.c_oflag=0;               \/* raw\u30e2\u30fc\u30c9 *\/\n  newtio.c_lflag=0;               \/* \u975e\u30ab\u30ce\u30cb\u30ab\u30eb\u5165\u529b *\/\n\n  newtio.c_cc[VTIME]=0;           \/* \u30ad\u30e3\u30e9\u30af\u30bf\u9593\u30bf\u30a4\u30de\u306f\u672a\u4f7f\u7528 *\/\n  newtio.c_cc[VMIN]=MC;            \/* MC\u6587\u5b57\u53d7\u3051\u53d6\u308b\u307e\u3067\u30d6\u30ed\u30c3\u30af\u3059\u308b *\/\n\n  tcflush(fd,TCIFLUSH);           \/* \u30dd\u30fc\u30c8\u306e\u30af\u30ea\u30a2 *\/\n  tcsetattr(fd, TCSANOW, &newtio); \/* \u30dd\u30fc\u30c8\u306e\u8a2d\u5b9a\u3092\u6709\u52b9\u306b\u3059\u308b *\/\n\n\n  char strbuf[20];\n  switch (cmdno){\n\tcase 1:\n  \t\tstrcpy(strbuf,SW1_CMD);\n\t\tbreak;\n\tcase 2:\n  \t\tstrcpy(strbuf,SW2_CMD);\n\t\tbreak;\n\tcase 3:\n  \t\tstrcpy(strbuf,SW3_CMD);\n\t\tbreak;\n\tcase 4:\n  \t\tstrcpy(strbuf,SW4_CMD);\n\t\tbreak;\n\tcase 5:\n  \t\tstrcpy(strbuf,SW5_CMD);\n\t\tbreak;\n\tcase 6:\n  \t\tstrcpy(strbuf,SW6_CMD);\n\t\tbreak;\n\tdefault:\n  \t\tstrcpy(strbuf,\"\\rPOWR0000\\r\");\n  }\n\n  \/\/\u30b3\u30de\u30f3\u30c9\u9001\u4fe1\n  write(fd,strbuf,sizeof(strbuf));\n\n  tcsetattr(fd, TCSANOW, &oldtio);  \/* \u9000\u907f\u3055\u305b\u305f\u8a2d\u5b9a\u306b\u623b\u3059 *\/\n  close(fd);                       \/* COM1\u306e\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u3092\u9589\u3058\u308b *\/\n  return(0);\n }\n\nstatic void become_daemon(void)\n{\n\tint n;\n\tif (chdir(\"\/\")<0) {\n\t\tlog_write(\"chdir(2) failed: %s\",strerror(errno));\n\t\texit(0);\n\t}\n\tfreopen(\"\/dev\/null\",\"r\",stdin);\n\tfreopen(\"\/dev\/null\",\"w\",stdout);\n\tfreopen(\"\/dev\/null\",\"w\",stderr);\n\tn = fork();\n\tif (n<0) log_write(\"fork(2) failed: %s\",strerror(errno));\n\tif (n !=0) _exit(0);\n\tif (setsid() <0) {\n\t\tlog_write(\"setsid(2) failed: %s\",strerror(errno));\n\t\t_exit(0);\n\t}\n\tlog_write(\"start daemon\",0);\n}\n\nint main(int argc, char **argv)\n{\n\t\/\/\u30c7\u30fc\u30e2\u30f3\u5316\u3092\u8a66\u307f\u308b\u3002\n\topenlog(\"remoteaquos\",LOG_PID|LOG_NDELAY,LOG_DAEMON);\n\tbecome_daemon();\n\n\tif (!bcm2835_init()) return 1;\n\tbcm2835_gpio_fsel(SW1, BCM2835_GPIO_FSEL_INPT);\n\tbcm2835_gpio_fsel(SW2, BCM2835_GPIO_FSEL_INPT);\n\tbcm2835_gpio_fsel(SW3, BCM2835_GPIO_FSEL_INPT);\n\tbcm2835_gpio_fsel(SW4, BCM2835_GPIO_FSEL_INPT);\n\tbcm2835_gpio_fsel(SW5, BCM2835_GPIO_FSEL_INPT);\n\tbcm2835_gpio_fsel(SW6, BCM2835_GPIO_FSEL_INPT);\n\t\/\/ VCC\u307e\u3067\u30d7\u30eb\u30a2\u30c3\u30d7\u3059\u308b\n\tbcm2835_gpio_set_pud(SW1, BCM2835_GPIO_PUD_UP);\n\tbcm2835_gpio_set_pud(SW2, BCM2835_GPIO_PUD_UP);\n\tbcm2835_gpio_set_pud(SW3, BCM2835_GPIO_PUD_UP);\n\tbcm2835_gpio_set_pud(SW4, BCM2835_GPIO_PUD_UP);\n\tbcm2835_gpio_set_pud(SW5, BCM2835_GPIO_PUD_UP);\n\tbcm2835_gpio_set_pud(SW6, BCM2835_GPIO_PUD_UP);\n\tsignal(SIGINT, signal_callback_handler);\n\t\/\/printf(\"press ^C to exit program ...\\n\");\n\n\twhile (1)\n\t{\n\t\tuint8_t sw_val1 = bcm2835_gpio_lev(SW1);\n\t\tuint8_t sw_val2 = bcm2835_gpio_lev(SW2);\n\t\tuint8_t sw_val3 = bcm2835_gpio_lev(SW3);\n\t\tuint8_t sw_val4 = bcm2835_gpio_lev(SW4);\n\t\tuint8_t sw_val5 = bcm2835_gpio_lev(SW5);\n\t\tuint8_t sw_val6 = bcm2835_gpio_lev(SW6);\n\t\tuint8_t value = sw_val1 +sw_val2 +sw_val3 +sw_val4 +sw_val5 +sw_val6;\n\n\t\tif (value != 6) {  \/\/\u4f55\u3089\u304b\u306e\u30b9\u30a4\u30c3\u30c1\u304c\u62bc\u3055\u308c\u3066\u3044\u308b\u3002\n\t\t\tlog_write(\"read from pin: %d %d %d %d %d %d\\n\", sw_val1,sw_val2,sw_val3,sw_val4,sw_val5,sw_val6,0);\n\t\t\tif(sw_val1 == 0 ) { sendcmd(1); }\n\t\t\tif(sw_val2 == 0 ) { sendcmd(2); }\n\t\t\tif(sw_val3 == 0 ) { sendcmd(3); }\n\t\t\tif(sw_val4 == 0 ) { sendcmd(4); }\n\t\t\tif(sw_val5 == 0 ) { sendcmd(5); }\n\t\t\tif(sw_val6 == 0 ) { sendcmd(6); }\n\t\t}\n\t\tdelay(50); \/\/ 0.005\u79d2\u5f85\u3064\n\t}\n}\nstatic void\nlog_write(char *fmt, ...)\n{\n    va_list ap;\n    va_start(ap, fmt);\n    vsyslog(LOG_ERR,fmt,ap);\n    va_end(ap);\n}\n<\/pre>\n<p>gcc -o remoteaquos -l bcm2835  -lrt remoteaquos.c \/usr\/local\/lib\/libbcm2835.a<br \/>\n\u4e00\u5fdc\u3001\u30c7\u30fc\u30e2\u30f3\u5316\u3057\u3066\u30ed\u30b0\u306b\u51fa\u529b\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u3002<br \/>\n\u3053\u308c\u3067\u30bf\u30af\u30c8\u30b9\u30a4\u30c3\u30c1\u3067\u96fb\u6e90OFF\u3068\u5165\u529b\u5207\u66ff\u304c\u53ef\u80fd\u306b\u306a\u3063\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u30011\u6708\u3082\u3082\u3046\u7d42\u308f\u308a\u3002 USB\u30ab\u30e1\u30e9+motion\u3067\u306f\u5b89\u5b9a\u3057\u3066\u52d5\u4f5c\u3067\u304d\u306a\u304b\u3063\u305fRaspberryPi\u3002 \u4f7f\u3044\u9053\u3092\u6a21\u7d22\u3057\u3066\u3044\u305f\u306e\u3060\u304c\u3001\u30ea\u30d3\u30f3\u30b0\u306b\u7f6e\u3044\u3066\u3042\u308bLS-GL\u3092Pi\u306b\u7f6e\u304d\u63db\u3048\u3088\u3046\u304b\u3068\u3002 \u3055\u3089\u306b\u3069\u3046\u305b\u306a\u3089\u5916\u90e8\u30b9\u30a4\u30c3\u30c1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,1],"tags":[],"class_list":["post-1733","post","type-post","status-publish","format-standard","hentry","category-6","category-1"],"views":10816,"_links":{"self":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1733"}],"version-history":[{"count":0,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1733\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}