Simple testΒΆ
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2022 Phil Underwood for Underwood Underground
3#
4# SPDX-License-Identifier: Unlicense
5import array
6import time
7
8import audiocore
9import audiopwmio
10import board
11
12from seeed_xiao_nrf52840 import IMU, Mic, Battery
13
14with Battery() as bat:
15 print(f"Charge complete: {bat.charge_status}")
16 print(f"Voltage: {bat.voltage}")
17 print(f"Charge_current high?: {bat.charge_current}")
18 print("Setting charge current to high")
19 bat.charge_current = bat.CHARGE_100MA
20 print(f"Charge_current high?: {bat.charge_current}")
21
22with IMU() as imu:
23 for i in range(5):
24 print("Acceleration:", imu.acceleration)
25 time.sleep(1)
26
27with Mic() as mic:
28 for i in range(5):
29 print(f"Start speaking in: {5-i}")
30 time.sleep(1)
31 b = array.array("H")
32 for i in range(8000):
33 b.append(0)
34 print("SPEAK!!!")
35 mic.record(b, len(b))
36 print(b)
37 for i in range(5):
38 print(f"Replaying in: {5-i}")
39 time.sleep(1)
40 with audiopwmio.PWMAudioOut(board.D0) as aud:
41 print("PWM setup")
42 sample = audiocore.RawSample(b, sample_rate=8000)
43 print("sample ready")
44 aud.play(sample, loop=True)
45 print("playing")
46 time.sleep(5)
47 aud.stop()