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