Search code examples
javascriptnode.jsraspberry-pigpio

What does setup() do in JS working with PI's GPIO pins


Every time you work with the Raspberry Pi's GPIO pins with JavaScript / NodeJS, you have to use x.setup('something'), with x being your imported library or packet. I know your application does not work without it, but what does setup() do and what is the parameter you give with it?


Solution

  • Setup documentation (github):

    setup(mode) .>= 0.1.1 An handy function to setup wiringPi mode can be one of the following values:

    wpi: sets up pin numbering with wiringPiSetup >= 0.1.1
    gpio: sets up pin numbering with wiringPiSetupGpio >= 0.1.1
    sys: sets up pin numbering with wiringPiSetupSys >= 0.1.1
    phys: sets up pin numbering with wiringPiSetupPhys >= 1.0.0
    

    More info about pin numbering systems here

    NOTE: >= 2.0.0 no longer accept calling setup without mode specified. (defaulting to wpi in < 2.0.0)

    Given by @Roland Starke.