Simple test
Ensure your device works with this simple test.
examples/bitbangio_simpletest.py
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
12
13import adafruit_bitbangio as bitbangio
14
15# Change these to the actual connections
16SCLK_PIN = board.D6
17MOSI_PIN = board.D17
18MISO_PIN = board.D18
19CS_PIN = board.D5
20
21cs = digitalio.DigitalInOut(CS_PIN)
22cs.switch_to_output(value=True)
23
24spi = bitbangio.SPI(SCLK_PIN, MOSI=MOSI_PIN, MISO=MISO_PIN)
25cs.value = 0
26while not spi.try_lock():
27 pass
28spi.write([0xD0])
29data = [0x00]
30spi.readinto(data)
31spi.unlock()
32cs.value = 1
33print(f"Result is {data}")