3

When I try to add pin 4 to the export by "sudo echo 4 >/sys/class/gpio/export" I will get this error message.

echo: write error: Device or resource busy

It works fine for all other pin numbers though.

Also when attempting the code a kernel module, when I try to change the gpio pin 4 value to 1 (by "gpio_direction_output(4,1);", it will automatically revert back to 0 after a few seconds.

1
  • The other answer did not work for me, but you can run sudo echo 4 > /sys/class/gpio/unexport to free the resource and use it.
    – jakobinn
    Dec 29, 2021 at 14:31

1 Answer 1

5

It is likely you have the 1-wire bus enabled. The bus is typically used with the DS18B20 temperature sensor. By default the bus uses GPIO4 when enabled.

If you don't use the 1-wire bus then comment out all the entries starting with w1 in /boot/config.txt and reboot.

If you do use the 1-wire bus you can pick another GPIO by modifying the w1 entry. See /boot/overlays/README for details.

1
  • Thanks a lot. You are right. Removing the "dtoverlay=w1-gpio" from the /boot/config.txt helps fixed it. Nov 9, 2017 at 0:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.