0

I'm learning how to code Raspberry pi in javascript (shouldn't matter for this question) and using the onoff library and i2c-bus libraries.

The GPIO (onoff) library shows how to 'close' a pin, which is aliased to unexport, and the i2c library has a 'close' method. What I fail to understand is when I should use these methods?

Should it be called each time I'm finished using the sensor or actuator attached to the address or pin? Or only when exiting a program completely.

As an example, I have an accelerometer that has a sequence to turn it on, would closing the i2c bus mean the next time I want to call the accelerometer I would need to go through the on sequence again?

1

Normally you would use a close method when you are no longer going to use the device, so typically just before you exit the script.

Of course this answer assumes that the close method being talked about has been sensibly named and implemented.

  • I assume that also means in the event of an error in communicating with a device so a reconnection can be tried? Probably more relevant to i2c than gpio. – pedalpete May 17 '16 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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