Skip to content

Commit 8f50586

Browse files
authored
Merge pull request #1 from ShawnHymel/master
First set of tests
2 parents a618dea + 525c209 commit 8f50586

16 files changed

+1603
-2
lines changed

.gitignore

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Compiled Sources
2+
###################
3+
*.o
4+
*.a
5+
!atmel-samd/asf/**/*.a
6+
*.elf
7+
*.bin
8+
*.map
9+
*.hex
10+
*.dis
11+
*.exe
12+
*.mpy
13+
14+
# Packages
15+
############
16+
17+
# Logs and Databases
18+
######################
19+
*.log
20+
21+
# VIM Swap Files
22+
######################
23+
*.swp
24+
25+
# Build directory
26+
######################
27+
build/
28+
bin/
29+
30+
# Test failure outputs
31+
######################
32+
tests/*.exp
33+
tests/*.out
34+
35+
# Python cache files
36+
######################
37+
__pycache__/
38+
*.pyc
39+
40+
# Customized Makefile/project overrides
41+
######################
42+
GNUmakefile
43+
user.props
44+
45+
# Sphinx output
46+
###############
47+
_build
48+
49+
# Generated rst files
50+
######################
51+
genrst/
52+
53+
# ctags and similar
54+
###################
55+
TAGS
56+
57+
# Merge leftovers
58+
#################
59+
*.orig
60+
61+
# Emacs backup files
62+
####################
63+
*~
64+
65+
*.DS_Store
66+
67+
# POEdit mo files
68+
####################
69+
*.mo

LICENSE.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
MicroPython & CircuitPython license information
2+
===============================================
3+
4+
The MIT License (MIT)
5+
6+
Copyright (c) 2018 Shawn Hymel for Adafruit Industries
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in
16+
all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.

README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
Introduction
3+
============
4+
5+
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.
6+
7+
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.
8+
9+
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.
10+
11+
The *main.py* example shows how to call tests from within a script. *main.py* runs the following tests:
12+
13+
* LED Test
14+
* GPIO Test
15+
* Voltage Monitor Test
16+
* UART Test
17+
* SPI Test
18+
* I2C Test
19+
20+
Dependencies
21+
=============
22+
23+
This test suite depends on:
24+
25+
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
26+
* `SD Card <https://github.com/adafruit/Adafruit_CircuitPython_SD>`_
27+
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
28+
29+
Please ensure all dependencies are available on the CircuitPython filesystem.
30+
This is easily achieved by downloading
31+
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
32+
33+
Usage Example
34+
=============
35+
36+
You will need the following components:
37+
38+
* Multimeter
39+
* LED
40+
* 1x 330 Ohm resistor
41+
* 2x 4.7k Ohm resistor
42+
* `Microchip 25AA040A SPI EEPROM <https://www.digikey.com/product-detail/en/microchip-technology/25AA040A-I-P/25AA040A-I-P-ND/1212469>`_
43+
* `Microchip AT24HC04B I2C EEPROM <https://www.digikey.com/product-detail/en/microchip-technology/AT24HC04B-PU/AT24HC04B-PU-ND/1886137>`_
44+
* Breadboard
45+
* Wires
46+
47+
Connect the components as shown to your board.
48+
49+
.. image:: docs/test_jig.png
50+
:alt: Test jig Fritzing diagram
51+
52+
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.
53+
54+
Building
55+
========
56+
57+
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.

docs/test_jig.fzz

7.41 KB
Binary file not shown.

docs/test_jig.png

164 KB
Loading

docs/test_jig_bb.png

146 KB
Loading

main.py

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2018 Shawn Hymel for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`board_test_suite`
24+
====================================================
25+
CircuitPython board hardware test suite
26+
27+
* Author(s): Shawn Hymel
28+
* Date: December 8, 2018
29+
30+
Implementation Notes
31+
--------------------
32+
Run this to test various input/output abilities of a board. Tests the following:
33+
34+
* Onboard LEDs
35+
* GPIO output
36+
* Onboard battery voltage monitor
37+
* SPI
38+
* I2C
39+
40+
You will need the following components:
41+
42+
* Multimeter
43+
* LED
44+
* 1x 330 Ohm resistor
45+
* 2x 4.7k Ohm resistor
46+
* Microchip 25AA040A SPI EEPROM
47+
* Microchip AT24HC04B I2C EEPROM
48+
* Breadboard
49+
* Wires
50+
51+
Copy lib directory to CIRCUITPYTHON drive. Copy the contents of this file to
52+
main.py in root of CIRCUITPYTHON. Open Serial terminal to board and follow
53+
prompts given.
54+
"""
55+
56+
import board
57+
58+
import led_test
59+
import gpio_test
60+
import voltage_monitor_test
61+
import uart_test
62+
import spi_test
63+
import i2c_test
64+
65+
# Constants
66+
UART_TX_PIN_NAME = 'TX'
67+
UART_RX_PIN_NAME = 'RX'
68+
UART_BAUD_RATE = 9600
69+
SPI_MOSI_PIN_NAME = 'MOSI'
70+
SPI_MISO_PIN_NAME = 'MISO'
71+
SPI_SCK_PIN_NAME = 'SCK'
72+
SPI_CS_PIN_NAME = 'D2'
73+
I2C_SDA_PIN_NAME = 'SDA'
74+
I2C_SCL_PIN_NAME = 'SCL'
75+
76+
# Results dictionary
77+
test_results = {}
78+
79+
# Save tested pins
80+
pins_tested = []
81+
82+
# Print welcome message
83+
print()
84+
print(" .... ")
85+
print(" #@@%%%%%%&@@/ ")
86+
print(" (&@%%%%%%%%%%%%%@& ")
87+
print(" .(@&%%%@* *&%%%%%%@. ")
88+
print(" ,@@&&%%%%%%%%//@%,/ /&%%%%%%@ ")
89+
print(" %@%%%&%%%%%%%#(@@@&&%%%%%%%%@* ")
90+
print(" @&%%&%%%%%%%%%%%%%%%%%%%%%%@/ ")
91+
print(" &@@&%%%%&&&%%%%%%%%%%%%%%@, ")
92+
print(" ,/ &@&&%%%%%%%%%%%%%%%%%@ ")
93+
print(" ,* *@&%%%%%%%%%%%%# ")
94+
print(" ( @%%%%%%%%%%%@ ")
95+
print(" , @%%%%%%%%%%&@ ")
96+
print(" #&%%%%%%%%%%@. ")
97+
print(" #@###%%%%%%%@/ ")
98+
print(" (@##(%%%%%%%@% ")
99+
print(" /@###(#%%%%%&@ ")
100+
print(" #@####%%%%%%%@ ")
101+
print(" (@###(%%%%%%%@, ")
102+
print(" .@##(((#%%%%%&( .,,. ")
103+
print(" ,@#####%%%%%%%@ ,%@@%%%%%%%&@% ")
104+
print(" ,#&@####(%%%%%%%@@@@@&%%%%%%%%%%%###& ")
105+
print(" @%%@%####(#%%%%%&@%%%%%%%%%%%%%%##/((@@@@&* ")
106+
print(" (##@%#####%%%%%%%@(#%%%(/####(/####(%@%%%%%%@/ ")
107+
print(" (@&%@@###(#%%%%%%@&/####(/#####/#&@@&%%%%%%%##@ ")
108+
print(" #@%%%%@#####(#%%%%%%@@@@@@@@@@@@@&%%%%%%%%%%%%#/(@@@@@/ ")
109+
print(" @%(/#@%######%%%%%%%@%%%%%%%%%%%%%%%%%%%%%(/(###@%%%%%%@% ")
110+
print(" .@@#(#@#####(#%%%%%%&@###//#####/#####/(####/#%@&%%%%%%%%&& ")
111+
print(" /@%%&@@@(#((((#%%%%%%&@###((#####/#####((##%@@&%%%%%%%%%%%/@. ")
112+
print(" ,@%%%%%%#####%%%%%%%%@@@@&&&&&&&%&@@@@@@&%%%%%%%%%%%%%%%##@, ")
113+
print(" %%%%%%%%@######(%%%%%%%@&%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#/(#&& ")
114+
print(" (@###/(%@##((##(%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%%##%###/(&& ")
115+
print(" ,@@%@%##((#%@#######%%%%%%%%@&%%%%##%%%%##%%%%#/#####((####(@* ")
116+
print(" *&(, %@@%##%@#######(%%%%%%%%@#/#####((#####(#####(/#&@&. ")
117+
print(" .@###((#%%%%%%%%%&@@###((#####(###%@@&, ")
118+
print(" #@#(#######%&@@&* .*#&@@@@@@@%(, ")
119+
print(" .,,,.. ")
120+
print()
121+
print("**********************************************************************")
122+
print("* Welcome to the CircuitPython board test suite! *")
123+
print("* Follow the directions to run each test. *")
124+
print("**********************************************************************")
125+
print()
126+
127+
# List out all the pins available to us
128+
pins = [p for p in dir(board)]
129+
print("All pins found:", end=' ')
130+
131+
# Print pins
132+
for p in pins:
133+
print(p, end=' ')
134+
print('\n')
135+
136+
# Run LED test
137+
print("@)}---^----- LED TEST -----^---{(@")
138+
print()
139+
result = led_test.run_test(pins)
140+
test_results["LED Test"] = result[0]
141+
pins_tested.append(result[1])
142+
print()
143+
print(result[0])
144+
print()
145+
146+
# Run GPIO test
147+
print("@)}---^----- GPIO TEST -----^---{(@")
148+
print()
149+
result = gpio_test.run_test(pins)
150+
test_results["GPIO Test"] = result[0]
151+
pins_tested.append(result[1])
152+
print()
153+
print(result[0])
154+
print()
155+
156+
# Run voltage monitor test
157+
print("@)}---^----- VOLTAGE MONITOR TEST -----^---{(@")
158+
print()
159+
result = voltage_monitor_test.run_test(pins)
160+
test_results["Voltage Monitor Test"] = result[0]
161+
pins_tested.append(result[1])
162+
print()
163+
print(result[0])
164+
print()
165+
166+
# Run UART test
167+
print("@)}---^----- UART TEST -----^---{(@")
168+
print()
169+
result = uart_test.run_test(pins, UART_TX_PIN_NAME, UART_RX_PIN_NAME, UART_BAUD_RATE)
170+
test_results["UART Test"] = result[0]
171+
pins_tested.append(result[1])
172+
print()
173+
print(result[0])
174+
print()
175+
176+
# Run SPI test
177+
print("@)}---^----- SPI TEST -----^---{(@")
178+
print()
179+
result = spi_test.run_test( pins,
180+
mosi_pin=SPI_MOSI_PIN_NAME,
181+
miso_pin=SPI_MISO_PIN_NAME,
182+
sck_pin=SPI_SCK_PIN_NAME,
183+
cs_pin=SPI_CS_PIN_NAME)
184+
test_results["SPI Test"] = result[0]
185+
pins_tested.append(result[1])
186+
print()
187+
print(result[0])
188+
print()
189+
190+
# Run I2C test
191+
print("@)}---^----- I2C TEST -----^---{(@")
192+
print()
193+
result = i2c_test.run_test(pins, sda_pin=I2C_SDA_PIN_NAME, scl_pin=I2C_SCL_PIN_NAME)
194+
test_results["I2C Test"] = result[0]
195+
pins_tested.append(result[1])
196+
print()
197+
print(result[0])
198+
print()
199+
200+
# Print out test results
201+
print("@)}---^----- TEST RESULTS -----^---{(@")
202+
print()
203+
204+
# Find appropriate spaces for printing test results
205+
num_spaces = 0
206+
for key in test_results:
207+
if len(key) > num_spaces:
208+
num_spaces = len(key)
209+
210+
# Print test results
211+
for key in test_results:
212+
print(key + ":", end=' ')
213+
for i in range(num_spaces - len(key)):
214+
print(end=' ')
215+
print(test_results[key])
216+
print()
217+
218+
# Figure out which pins were tested and not tested
219+
tested = []
220+
for sublist in pins_tested:
221+
for p in sublist:
222+
tested.append(p)
223+
not_tested = list(set(pins).difference(set(tested)))
224+
225+
# Print tested pins
226+
print("The following pins were tested:", end=' ')
227+
for p in tested:
228+
print(p, end=' ')
229+
print('\n')
230+
231+
# Print pins not tested
232+
print("The following pins were NOT tested:", end=' ')
233+
for p in not_tested:
234+
print(p, end=' ')
235+
print('\n')

0 commit comments

Comments
 (0)