Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Module Board has not attribute A2
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Module Board has not attribute A2

by tultalk on Fri May 22, 2020 5:38 pm

Hi:

python3.7 "busdevice_read_register_spi_simpletest.py" dist packages

Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/env python3

import busio
import board
import digitalio
from adafruit_bus_device.spi_device import SPIDevice

DEVICE_ADDRESS = 0x68  # device address of BMP280 board
A_DEVICE_REGISTER = 0xD0  # device id register on the BMP280 board

# The follow is for SPI communications
cs = digitalio.DigitalInOut(board.A2) [b]<<<<<<<<<<<<<<<<<<<[/b] Module Board has not attribute A2
comm_port = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
device = SPIDevice(comm_port, cs)


don't understand what "ContextManaged" means here?

Code: Select all | TOGGLE FULL SIZE
class DigitalInOut(ContextManaged):
    _pin = None

    def __init__(self, pin):
        self._pin = Pin(pin.id)
        self.direction = Direction.INPUT

    def switch_to_output(self, value=False, drive_mode=DriveMode.PUSH_PULL):
        self.direction = Direction.OUTPUT
        self.value = value
        self.drive_mode = drive_mode

    def switch_to_input(self, pull=None):
        self.direction = Direction.INPUT
        self.pull = pull
..........



Any help appreciated

Robert

tultalk
 
Posts: 24
Joined: Thu May 14, 2020 7:00 pm

Re: Module Board has not attribute A2

by adafruit_support_carter on Fri May 22, 2020 7:29 pm

What board are you running this on? It may not have an A2 pin defined. You can see all the pins with:
Code: Select all | TOGGLE FULL SIZE
dir(board)

(after you've imported board)

ContextManaged is a base class used by the DigitalInOut class. But in general, you shouldn't need worry about the part of the code.

adafruit_support_carter
 
Posts: 15978
Joined: Tue Nov 29, 2016 2:45 pm

Re: Module Board has not attribute A2

by tultalk on Fri May 22, 2020 8:54 pm

RB Pi 2 B

>>> import board
>>> dir(board)
['CE0', 'CE1', 'D0', 'D1', 'D10', 'D11', 'D12', 'D13', 'D14', 'D15', 'D16', 'D17', 'D18', 'D19', 'D2', 'D20', 'D21', 'D22', 'D23', 'D24', 'D25', 'D26', 'D27', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'I2C', 'MISO', 'MISO_1', 'MOSI', 'MOSI_1', 'RX', 'RXD', 'SCK', 'SCK_1', 'SCL', 'SCLK', 'SCLK_1', 'SDA', 'SPI', 'TX', 'TXD', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'ap_board', 'board_id', 'detector', 'pin', 'sys']
>>>

No A2.

tultalk
 
Posts: 24
Joined: Thu May 14, 2020 7:00 pm

Re: Module Board has not attribute A2

by tultalk on Sat May 23, 2020 8:38 am

[quote= It may not have an A2 pin defined. [/quote]

Why would this be hard coded if "a board may not have A2 defined"?

No try catch to address the issue!!

Makes no sense

tultalk
 
Posts: 24
Joined: Thu May 14, 2020 7:00 pm

Re: Module Board has not attribute A2

by tultalk on Sat May 23, 2020 9:31 am

Never mind. Did not realize what the 280 was.

Sorry

Robert

tultalk
 
Posts: 24
Joined: Thu May 14, 2020 7:00 pm

Re: Module Board has not attribute A2

by adafruit_support_carter on Tue May 26, 2020 10:42 am

The Raspberry Pi has no A2 pin.

Different boards will have different sets of pins. If you are following a guide or other information that requires use of an A2 pin, then it is limited to boards with an A2 pin. Otherwise you'll have to adapt the code for the board you are using. Also keep in mind that the Raspberry Pi has no analog inputs at all.

adafruit_support_carter
 
Posts: 15978
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.