Troubleshoot Raspberry Pi GPIO Pins

Error Using raspi/writeDigitalPin

Writing a logical value to a pin produces the following error:

writeDigitalPin(mypi,7,1)
writeDigitalPin(mypi,4,1)
Error using raspi/writeDigitalPin (line 451)
Digital pin 4 was previously configured for input. 
Set the digital pin configuration to 'output' in order to write to it.

The pin is configured as an input. To solve this issue:

  • Use a different pin number.

  • Use configureDigitalPin to reconfigure the pin as an output.

For more information, see Use the Raspberry Pi GPIO Pins as Digital Inputs and Outputs.

Error Using raspi/readDigitalPin

Reading the logical value of a pin produces an error.

readDigitalPin(mypi,4)
Error using raspi/readDigitalPin (line 433)
Digital pin 4 was previously configured for output. Set the digital pin
configuration to 'input' in order to read from it.

The pin is configured as an output.

To solve this issue, do either of the following:

  • Use a different pin number.

  • Use configureDigitalPin to reconfigure the pin as an input.

For more information, see Use the Raspberry Pi GPIO Pins as Digital Inputs and Outputs.

Unexpected Digital Pin Number

Using a specific pin number produces an error.

writeDigitalPin(mypi,7,1)
writeDigitalPin(mypi,7,1)
Error using raspi/checkDigitalPin (line 688)
Unexpected digital pin number. 
Use AvailableDigitalPins property for a list of digital
pin numbers you can use.

Error in raspi/writeDigitalPin (line 444)
            obj.checkDigitalPin(pinNumber)

The pin is unavailable for use as a digital pin. The I2C interface or the SPI interface might be using the pin.

To solve this issue, do either of the following:

  • Use the AvailableDigitalPins property to identify which pins are available, and then use a different pin number.

  • Disable the I2C or SPI interface that is using the pin. For more information, see disableSPI and disableI2C.

For more information, see Use the Raspberry Pi GPIO Pins as Digital Inputs and Outputs.