Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

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)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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