xref: /aosp_15_r20/external/pigweed/docs/showcases/sense/tutorial/factory.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1.. _showcase-sense-tutorial-factory:
2
3======================================
412. Run factory workflows at your desk
5======================================
6.. caution::
7
8   This section and the ones after it require a Pimoroni Enviro+ Pack. See
9   :ref:`showcase-sense-tutorial-hardware` for a review of the hardware
10   setup options. If you don't have an Enviro+, skip ahead to
11   :ref:`showcase-sense-tutorial-outro` to wrap up your tutorial experience.
12
13Bringing a consumer electronics product from concept to mass market
14requires a lot more than just good firmware. The new hardware also
15needs to be easy to test in factories. A lot of the Pigweed primitives
16that you tried earlier such as :ref:`module-pw_rpc` also make
17manufacturing workflows easier. Try flashing a factory app to your
18Pico now and running through a Python script that exercises all of the
19Enviro+ sensors.
20
21.. _showcase-sense-tutorial-factory-flash:
22
23----------------------------------
24Flash the factory app to your Pico
25----------------------------------
26#. Flash the ``factory`` binary to your Pico.
27
28   .. tab-set::
29
30      .. tab-item:: VS Code
31         :sync: vsc
32
33         In **Bazel Build Targets** expand **//apps/factory**, then right-click
34         **:flash (native_binary)**, then select **Run target**.
35
36      .. tab-item:: CLI
37         :sync: cli
38
39         Run the flashing command:
40
41         .. code-block:: console
42
43            $ bazelisk run //apps/factory:flash
44
45.. _showcase-sense-tutorial-factory-tests:
46
47--------------------
48Exercise the sensors
49--------------------
50#. Run through the factory testing script.
51
52   .. tab-set::
53
54      .. tab-item:: VS Code
55         :sync: vsc
56
57         In **Bazel Build Targets** expand **//tools**, then right-click
58         **:factory (py_binary)**, then select **Run target**.
59
60         The factory testing script launches in a VS Code terminal tab.
61
62      .. tab-item:: CLI
63         :sync: cli
64
65         Run the factory script.
66
67         .. code-block:: console
68
69            $ bazelisk run //tools:factory
70
71   .. admonition:: Troubleshooting
72
73      ``serial.serialutil.SerialException: [Errno 16] could not open port ...
74      [Errno 16] Device or resource busy``. Close the browser tab running the
75      web app. The factory script couldn't connect to your Pico because the
76      web app is still connected to the Pico.
77
78#. Follow the prompts in the factory testing script. It's OK if some
79   tests don't pass. This is just an example factory-at-your-desk
80   workflow.
81
82   See :ref:`showcase-sense-tutorial-factory-appendix` for an
83   example of a successful walkthrough of the factory script.
84
85   .. tip::
86
87      One easy way to do the gas resistance test is to dip a cotton
88      swab in rubbing alcohol and then hold the cotton swab close to
89      the **BME688** sensor.
90
91      .. figure:: https://storage.googleapis.com/pigweed-media/sense/alcohol.jpg
92
93.. _showcase-sense-tutorial-factory-summary:
94
95-------
96Summary
97-------
98For low-volume products a workflow like what you just tried can sometimes
99be good enough for verifying that every newly manufactured product works
100as expected. For high-volume products you usually need to integrate into
101the manufacturer's workflows, so the script we demonstrated here won't
102suffice. But Pigweed's abstractions, primitives, and tools often make that
103easier high-volume production easier, too. These factory-at-your-desk
104scripts can also help development teams quickly prototype and iterate
105on the basic workflows that will be expanded upon during the real
106high-volume manufacturing process.
107
108Next, head over to :ref:`showcase-sense-tutorial-bazel_cloud` to learn about
109Bazel's cloud features.
110
111.. _showcase-sense-tutorial-factory-appendix:
112
113-----------------
114Appendix: Example
115-----------------
116Here's an example of a successful walkthrough of the factory
117testing workflow.
118
119.. code-block:: text
120
121   ===========================
122   Pigweed Sense Factory Tests
123   ===========================
124   Operator: kayce
125   Date: 2024/08/06 19:01:08
126   Device flash ID: 2a4b9643086461e6
127
128   4 tests will be performed:
129     - LedTest
130     - ButtonsTest
131     - Ltr559Test
132     - Bme688Test
133
134   >>> Press Enter when you are ready to begin
135   Starting hardware tests.
136
137   ==========================
138   [1/4] Running test LedTest
139   ==========================
140
141   >>> Is the Enviro+ LED white? [Y/n] y
142   PASS: led_white
143
144   >>> Is the Enviro+ LED red? [Y/n] y
145   PASS: led_red
146
147   >>> Is the Enviro+ LED green? [Y/n] y
148   PASS: led_green
149
150   >>> Is the Enviro+ LED blue? [Y/n] y
151   PASS: led_blue
152
153   >>> Is the Enviro+ LED off? [Y/n] y
154   PASS: led_off
155
156   ==============================
157   [2/4] Running test ButtonsTest
158   ==============================
159   >>> Press Button A
160   PASS: button_a
161   >>> Press Button B
162   PASS: button_b
163   >>> Press Button X
164   PASS: button_x
165   >>> Press Button Y
166   PASS: button_y
167
168   =============================
169   [3/4] Running test Ltr559Test
170   =============================
171
172   Setting LTR559 sensor to proximity mode.
173
174   >>> Place your Enviro+ pack in a well-lit area
175   Press Enter to continue...
176   Getting initial sensor readings
177    100.0% [==============================================================================================================>]   5/  5 eta [00:00]
178    DONE
179       Samples   5
180       Min       0.00
181       Max       0.00
182       Mean      0.00
183
184
185   >>> Fully cover the LIGHT sensor
186   Press Enter to continue...
187   Reading sensor - 28992.00, 29440.00, 29248.00, 29088.00, 29056.00
188     10.0% [===========>                                                                                                   ]   5/ 50 eta [00:00]
189       Samples   6
190       Min       28992.00
191       Max       29440.00
192       Mean      29440.00
193   PASS: ltr559_prox_near
194
195
196   >>> Fully uncover the LIGHT sensor
197   Press Enter to continue...
198   Reading
199     10.0% [===========>                                                                                                   ]   5/ 50 eta [00:00]
200       Samples   6
201       Min       0.00
202       Max       0.00
203       Mean      0.00
204   PASS: ltr559_prox_far
205
206   Setting LTR559 sensor to ambient mode.
207
208   >>> Place your Enviro+ pack in an area with neutral light
209   Press Enter to continue...
210   Getting initial sensor readings
211    100.0% [==============================================================================================================>]   5/  5 eta [00:00]
212    DONE
213       Samples   5
214       Min       116.34lux
215       Max       116.34lux
216       Mean      116.34lux
217
218
219   >>> Cover the LIGHT sensor with your finger
220   Press Enter to continue...
221   Reading - 7.34, 7.34, 7.34, 7.34, 7.34
222    100.0% [==============================================================================================================>] 100/100 eta [00:00]
223       Samples   100
224       Min       5.39lux
225       Max       11.62lux
226       Mean      11.62lux
227   FAIL: ltr559_light_dark
228
229   =============================
230   [4/4] Running test Bme688Test
231   =============================
232
233   Testing gas resistance in the BME688 sensor.
234   To test the BME688's gas sensor, you need an alcohol-based
235   solution. E.g. dip a cotton swab in rubbing alcohol.
236
237   >>> Are you able to continue this test? [Y/n] y
238   Getting initial sensor readings - 5684.85, 5684.85, 5684.85, 5684.85, 5684.85
239    100.0% [==============================================================================================================>]  10/ 10 eta [00:00]
240    DONE
241       Samples   10
242       Min       5684.85
243       Max       1173639.00
244       Mean      1173639.00
245
246   >>> Move the alcohol close to the BME688 sensor.
247   Press Enter to begin measuring...
248   Reading sensor - 5684.85, 5684.85, 5684.85, 5684.85, 5684.85
249     10.0% [===========>                                                                                                   ]   5/ 50 eta [00:00]
250       Samples   6
251       Min       5684.85
252       Max       5684.85
253       Mean      5684.85
254   PASS: bme688_gas_resistance_poor
255
256   >>> Move the alcohol away from the BME688 sensor
257   Press Enter to continue...
258   Reading sensor - 30468.94, 31067.96, 31573.75, 31928.16, 32290.62
259    100.0% [==============================================================================================================>]  50/ 50 eta [00:00]
260       Samples   50
261       Min       5684.85
262       Max       32290.62
263       Mean      32290.62
264   FAIL: bme688_gas_resistance_normal
265
266   Testing BME688's temperature sensor.
267   Getting initial sensor readings - 28.11, 28.11, 28.12, 28.12, 28.11
268    100.0% [==============================================================================================================>]  10/ 10 eta [00:00]
269    DONE
270       Samples   10
271       Min       27.86C
272       Max       28.12C
273       Mean      28.12C
274
275   >>> Put your finger on the BME688 sensor to increase its temperature
276   Press Enter to begin measuring...
277   Reading sensor - 30.62, 30.53, 31.27, 31.78, 32.02
278     88.0% [================================================================================================>              ]  44/ 50 eta [00:00]
279       Samples   45
280       Min       29.70C
281       Max       32.02C
282       Mean      32.02C
283   PASS: bme688_temperature_hot
284
285   >>> Remove your finger from the BME688 sensor
286   Press Enter to begin measuring...
287   Reading sensor - 29.86, 30.11, 30.05, 29.99, 29.93
288      5.0% [=====>                                                                                                         ]   5/100 eta [00:00]
289       Samples   6
290       Min       29.81C
291       Max       30.11C
292       Mean      30.11C
293   PASS: bme688_temperature_normal
294
295   ============
296   Test Summary
297   ============
298   Operator: kayce
299   Date: 2024/08/06 19:01:08
300   Device flash ID: 2a4b9643086461e6
301
302   LedTest
303     PASS | led_white
304     PASS | led_red
305     PASS | led_green
306     PASS | led_blue
307     PASS | led_off
308
309   ButtonsTest
310     PASS | button_a
311     PASS | button_b
312     PASS | button_x
313     PASS | button_y
314
315   Ltr559Test
316     PASS | ltr559_prox_near
317     PASS | ltr559_prox_far
318     FAIL | ltr559_light_dark
319
320   Bme688Test
321     PASS | bme688_gas_resistance_poor
322     FAIL | bme688_gas_resistance_normal
323     PASS | bme688_temperature_hot
324     PASS | bme688_temperature_normal
325
326   14 tests passed, 2 tests failed.
327   ========================================
328   Device logs written to /home/kayce/tmp/cli/sense/factory-logs-20240806190108-device.txt
329   Factory logs written to /home/kayce/tmp/cli/sense/factory-logs-20240806190108-operator.txt
330