Skip to content

First set of tests #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Compiled Sources
###################
*.o
*.a
!atmel-samd/asf/**/*.a
*.elf
*.bin
*.map
*.hex
*.dis
*.exe
*.mpy

# Packages
############

# Logs and Databases
######################
*.log

# VIM Swap Files
######################
*.swp

# Build directory
######################
build/
bin/

# Test failure outputs
######################
tests/*.exp
tests/*.out

# Python cache files
######################
__pycache__/
*.pyc

# Customized Makefile/project overrides
######################
GNUmakefile
user.props

# Sphinx output
###############
_build

# Generated rst files
######################
genrst/

# ctags and similar
###################
TAGS

# Merge leftovers
#################
*.orig

# Emacs backup files
####################
*~

*.DS_Store

# POEdit mo files
####################
*.mo
24 changes: 24 additions & 0 deletions LICENSE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
MicroPython & CircuitPython license information
===============================================

The MIT License (MIT)

Copyright (c) 2018 Shawn Hymel for Adafruit Industries

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

57 changes: 57 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

Introduction
============

Board test suite for CircuitPython. Run these tests to ensure that a CircuitPython port was created correctly, individual pin mappings are correct, and buses (e.g. SPI) work.

Tests can be run individually. Copy code found in each *<name>_test.py* module (found in *source* directory) to main.py in your CIRCUITPYTHON device drive.

Alternatively, tests can be imported as modules. Copy the *lib* directory to CIRCUITPYTHON device drive and import the test in your own code. Each test can be run with the `run_test(pins)` function.

The *main.py* example shows how to call tests from within a script. *main.py* runs the following tests:

* LED Test
* GPIO Test
* Voltage Monitor Test
* UART Test
* SPI Test
* I2C Test

Dependencies
=============

This test suite depends on:

* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
* `SD Card <https://github.com/adafruit/Adafruit_CircuitPython_SD>`_
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_

Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.

Usage Example
=============

You will need the following components:

* Multimeter
* LED
* 1x 330 Ohm resistor
* 2x 4.7k Ohm resistor
* `Microchip 25AA040A SPI EEPROM <https://www.digikey.com/product-detail/en/microchip-technology/25AA040A-I-P/25AA040A-I-P-ND/1212469>`_
* `Microchip AT24HC04B I2C EEPROM <https://www.digikey.com/product-detail/en/microchip-technology/AT24HC04B-PU/AT24HC04B-PU-ND/1886137>`_
* Breadboard
* Wires

Connect the components as shown to your board.

.. image:: docs/test_jig.png
:alt: Test jig Fritzing diagram

Copy the *lib* folder to the CIRCUITPYTHON drive. Copy *main.py* to the root directory of your CIRCUITPYTHON drive. Open a Serial terminal and connect to the board. Follow the directions given to run through the tests.

Building
========

Individual test modules can be built with the mpy-cross cross-compiler. This is required to save RAM space if you plan to run more than one test at a time. See `the mpy-cross directory in circuitpython <https://github.com/adafruit/circuitpython/tree/master/mpy-cross>`_ to learn more.
Binary file added docs/test_jig.fzz
Binary file not shown.
Binary file added docs/test_jig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test_jig_bb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
235 changes: 235 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Shawn Hymel for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`board_test_suite`
====================================================
CircuitPython board hardware test suite

* Author(s): Shawn Hymel
* Date: December 8, 2018

Implementation Notes
--------------------
Run this to test various input/output abilities of a board. Tests the following:

* Onboard LEDs
* GPIO output
* Onboard battery voltage monitor
* SPI
* I2C

You will need the following components:

* Multimeter
* LED
* 1x 330 Ohm resistor
* 2x 4.7k Ohm resistor
* Microchip 25AA040A SPI EEPROM
* Microchip AT24HC04B I2C EEPROM
* Breadboard
* Wires

Copy lib directory to CIRCUITPYTHON drive. Copy the contents of this file to
main.py in root of CIRCUITPYTHON. Open Serial terminal to board and follow
prompts given.
"""

import board

import led_test
import gpio_test
import voltage_monitor_test
import uart_test
import spi_test
import i2c_test

# Constants
UART_TX_PIN_NAME = 'TX'
UART_RX_PIN_NAME = 'RX'
UART_BAUD_RATE = 9600
SPI_MOSI_PIN_NAME = 'MOSI'
SPI_MISO_PIN_NAME = 'MISO'
SPI_SCK_PIN_NAME = 'SCK'
SPI_CS_PIN_NAME = 'D2'
I2C_SDA_PIN_NAME = 'SDA'
I2C_SCL_PIN_NAME = 'SCL'

# Results dictionary
test_results = {}

# Save tested pins
pins_tested = []

# Print welcome message
print()
print(" .... ")
print(" #@@%%%%%%&@@/ ")
print(" (&@%%%%%%%%%%%%%@& ")
print(" .(@&%%%@* *&%%%%%%@. ")
print(" ,@@&&%%%%%%%%//@%,/ /&%%%%%%@ ")
print(" %@%%%&%%%%%%%#(@@@&&%%%%%%%%@* ")
print(" @&%%&%%%%%%%%%%%%%%%%%%%%%%@/ ")
print(" &@@&%%%%&&&%%%%%%%%%%%%%%@, ")
print(" ,/ &@&&%%%%%%%%%%%%%%%%%@ ")
print(" ,* *@&%%%%%%%%%%%%# ")
print(" ( @%%%%%%%%%%%@ ")
print(" , @%%%%%%%%%%&@ ")
print(" #&%%%%%%%%%%@. ")
print(" #@###%%%%%%%@/ ")
print(" (@##(%%%%%%%@% ")
print(" /@###(#%%%%%&@ ")
print(" #@####%%%%%%%@ ")
print(" (@###(%%%%%%%@, ")
print(" .@##(((#%%%%%&( .,,. ")
print(" ,@#####%%%%%%%@ ,%@@%%%%%%%&@% ")
print(" ,#&@####(%%%%%%%@@@@@&%%%%%%%%%%%###& ")
print(" @%%@%####(#%%%%%&@%%%%%%%%%%%%%%##/((@@@@&* ")
print(" (##@%#####%%%%%%%@(#%%%(/####(/####(%@%%%%%%@/ ")
print(" (@&%@@###(#%%%%%%@&/####(/#####/#&@@&%%%%%%%##@ ")
print(" #@%%%%@#####(#%%%%%%@@@@@@@@@@@@@&%%%%%%%%%%%%#/(@@@@@/ ")
print(" @%(/#@%######%%%%%%%@%%%%%%%%%%%%%%%%%%%%%(/(###@%%%%%%@% ")
print(" .@@#(#@#####(#%%%%%%&@###//#####/#####/(####/#%@&%%%%%%%%&& ")
print(" /@%%&@@@(#((((#%%%%%%&@###((#####/#####((##%@@&%%%%%%%%%%%/@. ")
print(" ,@%%%%%%#####%%%%%%%%@@@@&&&&&&&%&@@@@@@&%%%%%%%%%%%%%%%##@, ")
print(" %%%%%%%%@######(%%%%%%%@&%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#/(#&& ")
print(" (@###/(%@##((##(%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%%##%###/(&& ")
print(" ,@@%@%##((#%@#######%%%%%%%%@&%%%%##%%%%##%%%%#/#####((####(@* ")
print(" *&(, %@@%##%@#######(%%%%%%%%@#/#####((#####(#####(/#&@&. ")
print(" .@###((#%%%%%%%%%&@@###((#####(###%@@&, ")
print(" #@#(#######%&@@&* .*#&@@@@@@@%(, ")
print(" .,,,.. ")
print()
print("**********************************************************************")
print("* Welcome to the CircuitPython board test suite! *")
print("* Follow the directions to run each test. *")
print("**********************************************************************")
print()

# List out all the pins available to us
pins = [p for p in dir(board)]
print("All pins found:", end=' ')

# Print pins
for p in pins:
print(p, end=' ')
print('\n')

# Run LED test
print("@)}---^----- LED TEST -----^---{(@")
print()
result = led_test.run_test(pins)
test_results["LED Test"] = result[0]
pins_tested.append(result[1])
print()
print(result[0])
print()

# Run GPIO test
print("@)}---^----- GPIO TEST -----^---{(@")
print()
result = gpio_test.run_test(pins)
test_results["GPIO Test"] = result[0]
pins_tested.append(result[1])
print()
print(result[0])
print()

# Run voltage monitor test
print("@)}---^----- VOLTAGE MONITOR TEST -----^---{(@")
print()
result = voltage_monitor_test.run_test(pins)
test_results["Voltage Monitor Test"] = result[0]
pins_tested.append(result[1])
print()
print(result[0])
print()

# Run UART test
print("@)}---^----- UART TEST -----^---{(@")
print()
result = uart_test.run_test(pins, UART_TX_PIN_NAME, UART_RX_PIN_NAME, UART_BAUD_RATE)
test_results["UART Test"] = result[0]
pins_tested.append(result[1])
print()
print(result[0])
print()

# Run SPI test
print("@)}---^----- SPI TEST -----^---{(@")
print()
result = spi_test.run_test( pins,
mosi_pin=SPI_MOSI_PIN_NAME,
miso_pin=SPI_MISO_PIN_NAME,
sck_pin=SPI_SCK_PIN_NAME,
cs_pin=SPI_CS_PIN_NAME)
test_results["SPI Test"] = result[0]
pins_tested.append(result[1])
print()
print(result[0])
print()

# Run I2C test
print("@)}---^----- I2C TEST -----^---{(@")
print()
result = i2c_test.run_test(pins, sda_pin=I2C_SDA_PIN_NAME, scl_pin=I2C_SCL_PIN_NAME)
test_results["I2C Test"] = result[0]
pins_tested.append(result[1])
print()
print(result[0])
print()

# Print out test results
print("@)}---^----- TEST RESULTS -----^---{(@")
print()

# Find appropriate spaces for printing test results
num_spaces = 0
for key in test_results:
if len(key) > num_spaces:
num_spaces = len(key)

# Print test results
for key in test_results:
print(key + ":", end=' ')
for i in range(num_spaces - len(key)):
print(end=' ')
print(test_results[key])
print()

# Figure out which pins were tested and not tested
tested = []
for sublist in pins_tested:
for p in sublist:
tested.append(p)
not_tested = list(set(pins).difference(set(tested)))

# Print tested pins
print("The following pins were tested:", end=' ')
for p in tested:
print(p, end=' ')
print('\n')

# Print pins not tested
print("The following pins were NOT tested:", end=' ')
for p in not_tested:
print(p, end=' ')
print('\n')
Loading