How to fix error 'AttributeError: module 'board' has no attribute 'D5'

1k views Asked by At

I'm using a Docker container inside a Raspberry Pi. Upon accessing the container I want to run a script that I have prepared to read a humidity and temperature sensor. I already installed the adafruit-blinka libraries to be able to use the board function; however, when I run the Python file, I have this error:

Traceback (most recent call last):
  File "/home/ZDM1YTg4/lab.py", line 16, in <module>
    CS = DigitalInOut(board.D5)
                      ^^^^^^^^
AttributeError: module 'board' has no attribute 'D5'

The part of the code that is failing is this:

from digitalio import DigitalInOut, Direction
import board
import busio
import adafruit_rfm9x
import time
import sys


FREQUENCY = 433.0  

CS = DigitalInOut(board.D5)  
RESET = DigitalInOut(board.D22) 
spi = busio.SPI(board.SCK, MOSI=board.D10, MISO=board.D9)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 433.0)
rfm9x.irq = DigitalInOut(board.D2)

I already tried running the script file directly on the Raspberry Pi (outside the Docker container) and it works correctly, with the same configuration and libraries

Also tried:

sudo pip3 install --force-reinstall adafruit-blinka
1

There are 1 answers

0
Talha Tayyab On

You are getting this error because you explicitly installed board module.

You do NOT have to install board module explicitly. This board module is different from what you need for CircuitPython.

You just need to install adafruit-blinka, board is already present in adafruit-blinka.

Uninstall board module

Related question on git : https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/issues/55

https://pypi.org/project/Adafruit-Blinka/

enter image description here