0

I am a Python newbie. I am following a tutorial to run an SPI 1.8" TFT display. A term (or is it a module?) InitIO() is defined as follows:

def InitIO():  
    GPIO.setmode(GPIO,BOARD)
    GPIO.setwarnings(false)
    for pin in pins:
        GPIO.setup(pin,GPIO.OUT)
    GPIO.output(SCLK,0)           #start with clock low

I understand the purpose of the module as follows: It sets up three GPIO pins as SPI clock, data and data command. However, when InitIO() is called it produces an error:

NameError: name 'BOARD' is not defined

There is no mention in the tutorial about identifying BOARD. I have also tried substituting BCM instead of BOARD and I get the same error, with BCM substituted for BOARD in the error.

Any ideas on where I've gone wrong would be appreciated.

  • 3
    It's GPIO.BOARD (dot instead of comma) – Dirk Nov 19 '18 at 16:22
  • Avoid answering in comments, @Dirk, care to post an answer instead? – Ghanima Nov 19 '18 at 20:04
  • 1
    @Ghanima In these cases, I find it almost embarrassing to make it a proper answer. Done it anyway. – Dirk Nov 19 '18 at 20:30
  • 1
    Well, there certainly is an amount of discussion about the topic, e.g. here but as of now it is standing policy of StackExchange to avoid answering questions in comments as it circumvents the mechanisms that are supposed to ensure quality of the Q&A, i.e. voting. Short answers, btw, are not necessarily embarrassing. – Ghanima Nov 19 '18 at 21:00
4

It's a constant defined in the RPi.GPIO module, so it has the same prefix as the RPi.GPIO functions.

In your case that's GPIO, so the correct value is GPIO.BOARD (using a dot instead of comma). The full function call is

GPIO.setmode(GPIO.BOARD)

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.