chore(swan_r5):tests used to smoke test the board functionality

This commit is contained in:
Matthew McGowan 2021-09-27 13:40:36 -07:00
parent 2a05b22f42
commit 9d27d249cf
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
count = 0
# Wait for I2C lock
while not i2c.try_lock():
pass
# Scan for devices on the I2C bus
print("Scanning I2C bus")
for x in i2c.scan():
print(hex(x))
count += 1
print("%d device(s) found on I2C bus" % count)
# Release the I2C bus
i2c.unlock()

View File

@ -0,0 +1,56 @@
import board
import busio
import digitalio
cs = digitalio.DigitalInOut(board.SS)
cs.direction = digitalio.Direction.OUTPUT
cs.value = True
BME680_SPI_REGISTER = 0x73
BME680_CHIPID_REGISTER = 0xD0
BME680_CHIPID = 0x61
SPI_HERZ = 0x500000
spi = busio.SPI(board.SCK, MISO=board.MISO, MOSI=board.MOSI)
def readByte(addr):
value = -1
while not spi.try_lock():
pass
try:
spi.configure(baudrate=500000, phase=0, polarity=0)
cs.value = False
result = bytearray(1)
result[0] = addr | 0x80
spi.write(result)
spi.readinto(result)
value = result[0]
return value
finally:
spi.unlock()
cs.value = True
def writeByte(addr, value):
while not spi.try_lock():
pass
try:
spi.configure(baudrate=500000, phase=0, polarity=0)
cs.value = False
result = bytearray(2)
result[0] = addr & ~0x80
result[1] = value
spi.write(result)
finally:
spi.unlock()
# put the device in the correct mode to read the ID
reg = readByte(BME680_SPI_REGISTER)
if (reg & 16)!=0:
writeByte(BME680_SPI_REGISTER, reg & ~16)
id = readByte(BME680_CHIPID_REGISTER)
print(f"id is {id}, expected {BME680_CHIPID}")

View File

@ -0,0 +1,37 @@
import board
import busio
import digitalio
import usb_cdc
import time
while not usb_cdc.console.in_waiting:
time.sleep(0.1)
print("USART test")
# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.LED)
# For QT Py M0:
# led = digitalio.DigitalInOut(board.SCK)
led.direction = digitalio.Direction.OUTPUT
uart = busio.UART(board.TX, board.RX, baudrate=9600)
while True:
data = uart.read(32) # read up to 32 bytes
# print(data) # this is a bytearray type
if data is not None:
led.value = True
# convert bytearray to string
data_string = '*'.join([chr(b) for b in data])
print(data_string, end="")
led.value = False
if usb_cdc.console.in_waiting:
data = usb_cdc.console.read()
data_string = '*'.join([chr(b) for b in data])
print("writing "+data_string)
uart.write(data)

View File

@ -0,0 +1,9 @@
import os
def main():
print("Random number test")
r = os.urandom(32)
print(f"urandom TRNG string is {r}")
main()