I got a new raspberry-pi and I am playing with LED's. I am trying to understand how the gpio-pin value is set. Does it read somewhere from the file system?

I was going through a node.js module which sets the value in /sys/devices/virtual/gpio/gpio18/value. On the other hand, I went through the source of RPi.GPIO python module which doesn't use the same fs path.

I would love to understand how the value is set and read.

1 Answer 1


Programmatically there is only one way of using the GPIO pins, that is writing and reading to a piece of memory in the processor. But because it's a unix type OS we're using mostly, and unix maps everything to files, the kernel driver that is loaded to use the GPIO pins maps pins to these files that you're talking about. But internally this driver does the exact same thing, use this piece of memory to get the required result. This is called memory mapped I/O.

So the RPi.GPIO code you're talking about uses the memory direct, the node.js uses the kernel driver (and thus is a little slower), based on the file you're writing to (or reading from) the kernel driver 'knows' what address to write to / read from in memory. Because this node.js application is unaware of 'how' to use the GPIO pins itself, it is better portable then the RPi.GPIO code (but that is a little background and for the current status of the RPi totally irrelevant)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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