Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5This example is for demonstrating how to retrieving the
6board ID from a BME280, which is stored in register 0xD0.
7It should return a result of [96]
8"""
9
10import board
11import digitalio
12import adafruit_bitbangio as bitbangio
13
14# Change these to the actual connections
15SCLK_PIN = board.D6
16MOSI_PIN = board.D17
17MISO_PIN = board.D18
18CS_PIN = board.D5
19
20cs = digitalio.DigitalInOut(CS_PIN)
21cs.switch_to_output(value=True)
22
23spi = bitbangio.SPI(SCLK_PIN, MOSI=MOSI_PIN, MISO=MISO_PIN)
24cs.value = 0
25while not spi.try_lock():
26 pass
27spi.write([0xD0])
28data = [0x00]
29spi.readinto(data)
30spi.unlock()
31cs.value = 1
32print("Result is {}".format(data))