I have some strange behaviour when trying to read gpio output pin. I get that the first read return 1 (1 bytes read), but all next read from same gpio return 0. I would assume that it should always read 1, because there is always something to read from input pin.
gpio = 8;
fd = open("/sys/class/gpio/export", O_WRONLY);
sprintf(buf, "%d", gpio);
rc = write(fd, buf, strlen(buf));
if (rc == -1)
printf("failed in write 17\n");
close(fd);
sprintf(buf, "/sys/class/gpio/gpio%d/direction", gpio);
fd = open(buf, O_WRONLY);
rc = write(fd, "in", 2);
if (rc == -1)
printf("failed in write 18\n");
close(fd);
sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
gpio_tdo = open(buf, O_RDWR);
rc = read(gpio_tdo, &value, 1); <-- rc here is 1
rc = read(gpio_tdo, &value, 1); <-- rc here is 0
rc = read(gpio_tdo, &value, 1); <-- rc here is 0
Should the read of one byte from the gpio input always return 1 ?