Atomic Echo Pyramid Base

支持以下产品:

Atomic Echo Pyramid Base

以下是主机对 Atomic Echo Pyramid 底座的详细支持:

控制器

Atomic Echo Pyramid Base

Atom Echo

Atom Lite

Atom Matrix

AtomS3

AtomS3 Lite

AtomS3R

AtomS3R-CAM

AtomS3R-Ext

AtomicEchoPyramidBase 类用于控制 Atom 系列的 Echo Pyramid 底座,提供音频播放/录音、触摸输入及双路 RGB 灯带。

备注

Echo Pyramid 底座与 Atom 控制器均需单独供电。

UiFlow2 应用示例

灯带效果

在 UiFlow2 中打开 atoms3r_echopyramid_led_strip_example.m5f2 项目。

本示例演示两条 RGB 灯带的呼吸与流水效果。

UiFlow2 代码块:

led_strip_example.png

示例输出:

触摸控制

在 UiFlow2 中打开 atoms3r_echopyramid_touch_example.m5f2 项目。

本示例通过电容触摸键点亮不同侧 LED。

UiFlow2 代码块:

touch_example.png

示例输出:

录音与播放

在 UiFlow2 中打开 atoms3r_echopyramid_audio_example.m5f2 项目。

本示例录制一段短 WAV 后回放。

UiFlow2 代码块:

audio_example.png

示例输出:

蜂鸣音

在 UiFlow2 中打开 atoms3r_echopyramid_audio_beep_example.m5f2 项目。

本示例在每次触摸时播放随机蜂鸣音。

UiFlow2 代码块:

audio_beep_example.png

示例输出:

USB 电压

在 UiFlow2 中打开 atoms3r_echopyramid_usb_voltage_example.m5f2 项目。

本示例从底座读取 USB 输入电压(毫伏)并显示。

UiFlow2 代码块:

usb_voltage_example.png

示例输出:

MicroPython 示例

灯带效果

本示例演示两条 RGB 灯带的呼吸与流水效果。

MicroPython 代码块:

  1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
  2#
  3# SPDX-License-Identifier: MIT
  4import os, sys, io
  5import M5
  6from M5 import *
  7from hardware import Pin
  8from hardware import I2C
  9from base import AtomicEchoPyramidBase
 10import time
 11
 12
 13label_title = None
 14label_mode = None
 15label_tip1 = None
 16label_tipe = None
 17i2c1 = None
 18base_echopyramid = None
 19
 20
 21mode = None
 22MODE_BRATH = None
 23MODE_FLOW = None
 24index = None
 25brightness = None
 26i = None
 27direction = None
 28
 29
 30# Describe this function...
 31def init(mode):
 32    global \
 33        MODE_BRATH, \
 34        MODE_FLOW, \
 35        index, \
 36        brightness, \
 37        i, \
 38        direction, \
 39        label_title, \
 40        label_mode, \
 41        label_tip1, \
 42        label_tipe, \
 43        i2c1, \
 44        base_echopyramid
 45    if mode == MODE_BRATH:
 46        print("mode: brathe")
 47        label_mode.setText(str("braeth"))
 48        label_mode.setCursor(x=32, y=40)
 49        for i in range(14):
 50            base_echopyramid.set_rgb_color(1, i, 0x33CCFF)
 51            base_echopyramid.set_rgb_color(2, i, 0x33CCFF)
 52
 53        brightness = 0
 54        direction = True
 55    elif mode == MODE_FLOW:
 56        print("mode: flow")
 57        label_mode.setText(str("flow"))
 58        label_mode.setCursor(x=46, y=40)
 59        for i in range(14):
 60            base_echopyramid.set_rgb_color(1, i, 0x000000)
 61            base_echopyramid.set_rgb_color(2, i, 0x000000)
 62
 63        base_echopyramid.set_rgb_brightness(1, 30, False)
 64        base_echopyramid.set_rgb_brightness(2, 30, False)
 65
 66
 67def btna_was_clicked_event(state):
 68    global \
 69        label_title, \
 70        label_mode, \
 71        label_tip1, \
 72        label_tipe, \
 73        i2c1, \
 74        base_echopyramid, \
 75        mode, \
 76        MODE_BRATH, \
 77        MODE_FLOW, \
 78        index, \
 79        brightness, \
 80        direction, \
 81        i
 82    mode = (mode if isinstance(mode, (int, float)) else 0) + 1
 83    mode = mode % 2
 84    init(mode)
 85
 86
 87def setup():
 88    global \
 89        label_title, \
 90        label_mode, \
 91        label_tip1, \
 92        label_tipe, \
 93        i2c1, \
 94        base_echopyramid, \
 95        mode, \
 96        MODE_BRATH, \
 97        MODE_FLOW, \
 98        index, \
 99        brightness, \
100        direction, \
101        i
102
103    M5.begin()
104    Widgets.fillScreen(0x000000)
105    label_title = Widgets.Label(
106        "EchoPyramid", 1, 1, 1.0, 0x11CFE8, 0x000000, Widgets.FONTS.DejaVu18
107    )
108    label_mode = Widgets.Label("breath", 32, 36, 1.0, 0xD41194, 0x000000, Widgets.FONTS.DejaVu18)
109    label_tip1 = Widgets.Label(
110        "press display", 18, 88, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu12
111    )
112    label_tipe = Widgets.Label(
113        "change mode", 16, 106, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu12
114    )
115
116    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btna_was_clicked_event)
117
118    i2c1 = I2C(1, scl=Pin(39), sda=Pin(38), freq=100000)
119    base_echopyramid = AtomicEchoPyramidBase(
120        i2c1, i2s_port=1, dev_addr=0x1A, sample_rate=16000, i2s_sck=6, i2s_ws=8, i2s_di=5, i2s_do=7
121    )
122    index = 0
123    MODE_BRATH = 0
124    MODE_FLOW = 1
125    mode = MODE_BRATH
126    brightness = 0
127    init(mode)
128
129
130def loop():
131    global \
132        label_title, \
133        label_mode, \
134        label_tip1, \
135        label_tipe, \
136        i2c1, \
137        base_echopyramid, \
138        mode, \
139        MODE_BRATH, \
140        MODE_FLOW, \
141        index, \
142        brightness, \
143        direction, \
144        i
145    M5.update()
146    if mode == MODE_BRATH:
147        base_echopyramid.set_rgb_brightness(1, brightness, False)
148        base_echopyramid.set_rgb_brightness(2, brightness, False)
149        if direction:
150            brightness = (brightness if isinstance(brightness, (int, float)) else 0) + 1
151            if brightness > 50:
152                direction = False
153        else:
154            brightness = (brightness if isinstance(brightness, (int, float)) else 0) + -1
155            if brightness < 0:
156                direction = True
157        print((str("brightness: ") + str(brightness)))
158        time.sleep_ms(50)
159    elif mode == MODE_FLOW:
160        if index > 0:
161            base_echopyramid.set_rgb_color(1, index - 1, 0x000000)
162            base_echopyramid.set_rgb_color(2, index - 1, 0x000000)
163        if index == 14:
164            index = 0
165        base_echopyramid.set_rgb_color(1, index, 0x3333FF)
166        base_echopyramid.set_rgb_color(2, index, 0x3333FF)
167        index = (index if isinstance(index, (int, float)) else 0) + 1
168        print((str("index: ") + str(index)))
169        time.sleep_ms(50)
170
171
172if __name__ == "__main__":
173    try:
174        setup()
175        while True:
176            loop()
177    except (Exception, KeyboardInterrupt) as e:
178        try:
179            from utility import print_error_msg
180
181            print_error_msg(e)
182        except ImportError:
183            print("please update to latest firmware")

示例输出:

触摸控制

本示例通过电容触摸键点亮不同侧 LED。

MicroPython 代码块:

  1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
  2#
  3# SPDX-License-Identifier: MIT
  4
  5import os, sys, io
  6import M5
  7from M5 import *
  8from hardware import Pin
  9from hardware import I2C
 10from base import AtomicEchoPyramidBase
 11import time
 12
 13
 14label0 = None
 15label1 = None
 16label2 = None
 17i2c1 = None
 18base_echopyramid = None
 19tp = None
 20tp_index = None
 21last_tp_time = None
 22strip_enable = None
 23time_diff = None
 24i = None
 25
 26
 27def setup():
 28    global \
 29        label0, \
 30        label1, \
 31        label2, \
 32        i2c1, \
 33        base_echopyramid, \
 34        tp, \
 35        last_tp_time, \
 36        strip_enable, \
 37        time_diff, \
 38        tp_index, \
 39        i
 40
 41    M5.begin()
 42    Widgets.fillScreen(0x000000)
 43    label0 = Widgets.Label("EchoPyramid", 1, 2, 1.0, 0x12C7DE, 0x000000, Widgets.FONTS.DejaVu18)
 44    label1 = Widgets.Label("Touch", 36, 47, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18)
 45    label2 = Widgets.Label("Control", 29, 75, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18)
 46
 47    i2c1 = I2C(1, scl=Pin(39), sda=Pin(38), freq=100000)
 48    base_echopyramid = AtomicEchoPyramidBase(
 49        i2c1, i2s_port=1, dev_addr=0x1A, sample_rate=16000, i2s_sck=6, i2s_ws=8, i2s_di=5, i2s_do=7
 50    )
 51    base_echopyramid.set_rgb_color(1, 2, 56789)
 52    last_tp_time = [0, 0, 0, 0]
 53    strip_enable = [False, False, False, False]
 54
 55
 56def loop():
 57    global \
 58        label0, \
 59        label1, \
 60        label2, \
 61        i2c1, \
 62        base_echopyramid, \
 63        tp, \
 64        last_tp_time, \
 65        strip_enable, \
 66        time_diff, \
 67        tp_index, \
 68        i
 69    M5.update()
 70    tp = base_echopyramid.get_touch()
 71    print((str("TP: ") + str(tp)))
 72    for tp_index in range(1, 5):
 73        if tp[int(tp_index - 1)]:
 74            if tp_index == 1:
 75                for i in range(7):
 76                    base_echopyramid.set_rgb_color(1, 7 + i, 0x00CCCC)
 77
 78            elif tp_index == 2:
 79                for i in range(7):
 80                    base_echopyramid.set_rgb_color(1, i, 0x00CCCC)
 81
 82            elif tp_index == 3:
 83                for i in range(7):
 84                    base_echopyramid.set_rgb_color(2, i, 0x00CCCC)
 85
 86            elif tp_index == 4:
 87                for i in range(7):
 88                    base_echopyramid.set_rgb_color(2, 7 + i, 0x00CCCC)
 89
 90            last_tp_time[int(tp_index - 1)] = time.ticks_ms()
 91            strip_enable[int(tp_index - 1)] = True
 92        else:
 93            time_diff = time.ticks_diff((time.ticks_ms()), (last_tp_time[int(tp_index - 1)]))
 94            if time_diff > 500 and strip_enable[int(tp_index - 1)]:
 95                strip_enable[int(tp_index - 1)] = False
 96                if tp_index == 1:
 97                    for i in range(7):
 98                        base_echopyramid.set_rgb_color(1, 7 + i, 0x000000)
 99
100                elif tp_index == 2:
101                    for i in range(7):
102                        base_echopyramid.set_rgb_color(1, i, 0x000000)
103
104                elif tp_index == 3:
105                    for i in range(7):
106                        base_echopyramid.set_rgb_color(2, i, 0x000000)
107
108                elif tp_index == 4:
109                    for i in range(7):
110                        base_echopyramid.set_rgb_color(2, 7 + i, 0x000000)
111
112
113if __name__ == "__main__":
114    try:
115        setup()
116        while True:
117            loop()
118    except (Exception, KeyboardInterrupt) as e:
119        try:
120            from utility import print_error_msg
121
122            print_error_msg(e)
123        except ImportError:
124            print("please update to latest firmware")

示例输出:

录音与播放

本示例录制一段短 WAV 后回放。

MicroPython 代码块:

  1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
  2#
  3# SPDX-License-Identifier: MIT
  4
  5import os, sys, io
  6import M5
  7from M5 import *
  8from hardware import Pin
  9from hardware import I2C
 10from base import AtomicEchoPyramidBase
 11import time
 12
 13
 14label_title = None
 15label_state = None
 16label_tip1 = None
 17label_tip2 = None
 18i2c1 = None
 19base_echopyramid = None
 20record = None
 21playing = None
 22record_file_path = None
 23record_time_ms = None
 24play_start_time = None
 25RECORD_DURATION = None
 26
 27
 28def btna_was_clicked_event(state):
 29    global \
 30        label_title, \
 31        label_state, \
 32        label_tip1, \
 33        label_tip2, \
 34        i2c1, \
 35        base_echopyramid, \
 36        record, \
 37        playing, \
 38        RECORD_DURATION, \
 39        record_file_path, \
 40        record_time_ms, \
 41        play_start_time
 42    if not playing:
 43        record = True
 44
 45
 46def setup():
 47    global \
 48        label_title, \
 49        label_state, \
 50        label_tip1, \
 51        label_tip2, \
 52        i2c1, \
 53        base_echopyramid, \
 54        record, \
 55        playing, \
 56        RECORD_DURATION, \
 57        record_file_path, \
 58        record_time_ms, \
 59        play_start_time
 60
 61    M5.begin()
 62    Widgets.fillScreen(0x000000)
 63    label_title = Widgets.Label("Audio", 36, 0, 1.0, 0x2293CB, 0x000000, Widgets.FONTS.DejaVu18)
 64    label_state = Widgets.Label("Idle", 46, 28, 1.0, 0xDED413, 0x000000, Widgets.FONTS.DejaVu18)
 65    label_tip1 = Widgets.Label(
 66        "press display", 1, 83, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18
 67    )
 68    label_tip2 = Widgets.Label(
 69        "start record", 8, 103, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18
 70    )
 71
 72    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btna_was_clicked_event)
 73
 74    i2c1 = I2C(1, scl=Pin(39), sda=Pin(38), freq=100000)
 75    base_echopyramid = AtomicEchoPyramidBase(
 76        i2c1, i2s_port=1, dev_addr=0x1A, sample_rate=16000, i2s_sck=6, i2s_ws=8, i2s_di=5, i2s_do=7
 77    )
 78    RECORD_DURATION = 0
 79    record_file_path = "test.wav"
 80    record_time_ms = 5000
 81    base_echopyramid.set_volume(60)
 82
 83
 84def loop():
 85    global \
 86        label_title, \
 87        label_state, \
 88        label_tip1, \
 89        label_tip2, \
 90        i2c1, \
 91        base_echopyramid, \
 92        record, \
 93        playing, \
 94        RECORD_DURATION, \
 95        record_file_path, \
 96        record_time_ms, \
 97        play_start_time
 98    M5.update()
 99    if record:
100        record = False
101        print("start record")
102        label_tip1.setVisible(False)
103        label_tip2.setVisible(False)
104        label_state.setText(str("Recording..."))
105        label_state.setCursor(x=6, y=28)
106        label_state.setColor(0xFF0000, 0x000000)
107        base_echopyramid.record_wav_file(
108            "/flash/res/audio/test.wav",
109            rate=16000,
110            bits=16,
111            channel=AtomicEchoPyramidBase.STEREO,
112            duration=record_time_ms,
113        )
114        print("start play")
115        label_state.setText(str("Playing..."))
116        label_state.setCursor(x=21, y=28)
117        label_state.setColor(0x33CC00, 0x000000)
118        base_echopyramid.play_wav_file("/flash/res/audio/" + str(record_file_path))
119        playing = True
120        play_start_time = time.ticks_ms()
121    if playing:
122        if (time.ticks_diff((time.ticks_ms()), play_start_time)) > record_time_ms:
123            playing = False
124            print("play finished")
125            label_state.setText(str("Idle"))
126            label_state.setCursor(x=46, y=28)
127            label_state.setColor(0xFFFF00, 0x000000)
128            label_tip1.setVisible(True)
129            label_tip2.setVisible(True)
130
131
132if __name__ == "__main__":
133    try:
134        setup()
135        while True:
136            loop()
137    except (Exception, KeyboardInterrupt) as e:
138        try:
139            from utility import print_error_msg
140
141            print_error_msg(e)
142        except ImportError:
143            print("please update to latest firmware")

示例输出:

蜂鸣音

本示例在每次触摸时播放随机蜂鸣音。

MicroPython 代码块:

 1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import Pin
 9from hardware import I2C
10from base import AtomicEchoPyramidBase
11import random
12
13
14label_title = None
15label_tip1 = None
16label_freq = None
17label_tip2 = None
18i2c1 = None
19base_echopyramid = None
20beep = None
21freq = None
22
23
24def btna_was_eclicked_event(state):
25    global label_title, label_tip1, label_freq, label_tip2, i2c1, base_echopyramid, beep, freq
26    beep = True
27
28
29def setup():
30    global label_title, label_tip1, label_freq, label_tip2, i2c1, base_echopyramid, beep, freq
31
32    M5.begin()
33    Widgets.fillScreen(0x000000)
34    label_title = Widgets.Label(
35        "Audio Play", 13, 2, 1.0, 0x0EE9EE, 0x000000, Widgets.FONTS.DejaVu18
36    )
37    label_tip1 = Widgets.Label(
38        "press display", 1, 83, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18
39    )
40    label_freq = Widgets.Label(
41        "Freq: -- Hz", 15, 41, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18
42    )
43    label_tip2 = Widgets.Label("beep", 39, 103, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18)
44
45    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btna_was_eclicked_event)
46
47    i2c1 = I2C(1, scl=Pin(39), sda=Pin(38), freq=100000)
48    base_echopyramid = AtomicEchoPyramidBase(
49        i2c1, i2s_port=1, dev_addr=0x1A, sample_rate=16000, i2s_sck=6, i2s_ws=8, i2s_di=5, i2s_do=7
50    )
51    base_echopyramid.set_volume(50)
52
53
54def loop():
55    global label_title, label_tip1, label_freq, label_tip2, i2c1, base_echopyramid, beep, freq
56    M5.update()
57    if beep:
58        beep = False
59        freq = random.randint(500, 3500)
60        if freq >= 1000:
61            label_freq.setCursor(x=0, y=41)
62            label_freq.setText(str((str("Freq:") + str((str(freq) + str("Hz"))))))
63        else:
64            label_freq.setCursor(x=9, y=41)
65            label_freq.setText(str((str("Freq:") + str((str(freq) + str("Hz"))))))
66        base_echopyramid.tone(freq, 200)
67
68
69if __name__ == "__main__":
70    try:
71        setup()
72        while True:
73            loop()
74    except (Exception, KeyboardInterrupt) as e:
75        try:
76            from utility import print_error_msg
77
78            print_error_msg(e)
79        except ImportError:
80            print("please update to latest firmware")

示例输出:

USB 电压

本示例从底座读取 USB 输入电压(毫伏)并显示。

MicroPython 代码块:

 1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import time
 6import M5
 7from M5 import *
 8from base import AtomicEchoPyramidBase
 9from hardware import Pin
10from hardware import I2C
11
12
13label_title = None
14label_voltage = None
15label_unit = None
16label_value = None
17i2c1 = None
18base_echopyramid = None
19last_time = None
20voltage = None
21
22
23def setup():
24    global \
25        label_title, \
26        label_voltage, \
27        label_unit, \
28        label_value, \
29        i2c1, \
30        base_echopyramid, \
31        last_time, \
32        voltage
33
34    M5.begin()
35    Widgets.fillScreen(0x000000)
36    label_title = Widgets.Label(
37        "EchoPyramid", 1, 1, 1.0, 0x12C4E6, 0x000000, Widgets.FONTS.DejaVu18
38    )
39    label_voltage = Widgets.Label(
40        "USB Volatge", 5, 31, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18
41    )
42    label_unit = Widgets.Label("mV", 47, 105, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu18)
43    label_value = Widgets.Label("5000", 31, 66, 1.0, 0xFFFFFF, 0x000000, Widgets.FONTS.DejaVu24)
44
45    i2c1 = I2C(1, scl=Pin(39), sda=Pin(38), freq=100000)
46    base_echopyramid = AtomicEchoPyramidBase(
47        i2c1, i2s_port=1, dev_addr=0x1A, sample_rate=16000, i2s_sck=6, i2s_ws=8, i2s_di=5, i2s_do=7
48    )
49
50
51def loop():
52    global \
53        label_title, \
54        label_voltage, \
55        label_unit, \
56        label_value, \
57        i2c1, \
58        base_echopyramid, \
59        last_time, \
60        voltage
61    M5.update()
62    if (time.ticks_diff((time.ticks_ms()), last_time)) >= 200:
63        last_time = time.ticks_ms()
64        voltage = base_echopyramid.get_input_voltage()
65        if voltage >= 5000:
66            label_value.setColor(0x33CC00, 0x000000)
67        else:
68            label_value.setColor(0xFF0000, 0x000000)
69        label_value.setText(str(voltage))
70
71
72if __name__ == "__main__":
73    try:
74        setup()
75        while True:
76            loop()
77    except (Exception, KeyboardInterrupt) as e:
78        try:
79            from utility import print_error_msg
80
81            print_error_msg(e)
82        except ImportError:
83            print("please update to latest firmware")

示例输出:

API

AtomicEchoPyramidBase

class base.echo_pyramid.AtomicEchoPyramidBase(*args, **kwargs)

基类:object

适用于 AtomS3R 的 Echo Pyramid 底座。

参数:
  • i2c – I2C 总线。

  • dev_addr (int) – STM32 I2C 地址,默认 0x1A。

  • es8311_addr (int) – ES8311 I2C 地址,默认 0x18。

  • i2s_port (int) – I2S 端口号,默认 1。

  • sample_rate (int) – 采样率,默认 24000。

  • i2s_sck (int) – I2S BCLK 引脚,默认 6。

  • i2s_ws (int) – I2S WS 引脚,默认 8。

  • i2s_di (int) – I2S DIN(麦克风)引脚,默认 5。

  • i2s_do (int) – I2S DOUT(扬声器)引脚,默认 7。

UiFlow2 代码块:

init.png

MicroPython 代码块:

from hardware import I2C, Pin
from base import AtomicEchoPyramidBase

i2c = I2C(1, scl=Pin(39), sda=Pin(38), freq=100000)
echo_pyramid = AtomicEchoPyramidBase(i2c, dev_addr=0x1A, i2s_sck=6, i2s_ws=8, i2s_di=5, i2s_do=7)
echo_pyramid.speaker.tone(2000, 500)
MONO = 1

单声道。

STEREO = 2

立体声。

get_touch()

获取触摸状态。

返回:

(tp1, tp2, tp3, tp4),True=按下,False=松开。

返回类型:

tuple

UiFlow2 代码块:

get_touch.png

MicroPython 代码块:

tp1, tp2, tp3, tp4 = echo_pyramid.get_touch()
set_rgb_brightness(strip, brightness, save=False)

设置 RGB 灯带亮度。

参数:
  • strip (int) – 灯带索引(1 或 2)。

  • brightness (int) – 亮度 0~100。

  • save (bool) – 保存到闪存。

返回类型:

None

UiFlow2 代码块:

set_rgb_brightness.png

MicroPython 代码块:

echo_pyramid.set_rgb_brightness(1, 50, False)
get_rgb_brightness(strip)

获取 RGB 灯带亮度。

参数:

strip (int) – 灯带索引(1 或 2)。

返回:

亮度 0~100,错误或无效灯带时返回 0。

返回类型:

int

UiFlow2 代码块:

get_rgb_brightness.png

MicroPython 代码块:

brightness = echo_pyramid.get_rgb_brightness(1)
set_rgb_color(strip, index, color)

设置单颗 RGB LED 颜色。

参数:
  • strip (int) – 灯带索引(1 或 2)。

  • index (int) – LED 索引 0~13。

  • color (int) – 24 位颜色 (R << 16 | G << 8 | B)。

返回类型:

None

UiFlow2 代码块:

set_rgb_color.png

MicroPython 代码块:

echo_pyramid.set_rgb_color(1, 0, 0x33CCFF)
get_rgb_color(strip, index)

获取单颗 RGB LED 颜色。

参数:
  • strip (int) – 灯带索引(1 或 2)。

  • index (int) – LED 索引 0~13。

返回:

24 位颜色 (R << 16 | G << 8 | B),错误时返回 0。

返回类型:

int

UiFlow2 代码块:

get_rgb_color.png

MicroPython 代码块:

color = echo_pyramid.get_rgb_color(1, 0)
set_addr(new_addr)

设置 STM32 I2C 地址,短延时后生效。

参数:

new_addr (int) – 新地址 0x08~0x77。

返回类型:

None

UiFlow2 代码块:

set_addr.png

MicroPython 代码块:

echo_pyramid.set_addr(0x1B)
get_addr()

获取当前 STM32 I2C 地址。

返回:

I2C 地址,错误时返回 0。

返回类型:

int

UiFlow2 代码块:

get_addr.png

MicroPython 代码块:

addr = echo_pyramid.get_addr()
get_firmware_version()

获取 STM32 固件版本。

返回:

版本号,错误时返回 0。

返回类型:

int

UiFlow2 代码块:

get_firmware_version.png

MicroPython 代码块:

ver = echo_pyramid.get_firmware_version()
get_input_voltage()

获取输入电压(来自 STM32 ADC)。

返回:

电压(毫伏),错误时返回 0。

返回类型:

int

UiFlow2 代码块:

get_input_voltage.png

MicroPython 代码块:

mv = echo_pyramid.get_input_voltage()
set_mute(mute)

静音或取消静音扬声器(AW87559)。

参数:

mute (bool) – True 静音,False 取消静音。

返回类型:

None

UiFlow2 代码块:

set_mute.png

MicroPython 代码块:

echo_pyramid.set_mute(True)
change_sample_rate(sample_rate)

更改音频采样率,影响播放与录音。

参数:

sample_rate (int) – 采样率(Hz),如 16000、24000。

返回类型:

None

MicroPython 代码块:

echo_pyramid.change_sample_rate(24000)
play_wav_file(file)

从存储播放 WAV 文件。

参数:

file (str) – WAV 文件路径。

返回类型:

None

UiFlow2 代码块:

play_wav_file.png

MicroPython 代码块:

echo_pyramid.play_wav_file("/flash/res/audio/test.wav")
tone(freq, duration)

播放蜂鸣音。

参数:
  • freq (int) – 频率(Hz)。

  • duration (int) – 持续时间(毫秒)。

返回类型:

None

UiFlow2 代码块:

tone.png

MicroPython 代码块:

echo_pyramid.tone(1000, 200)
play_wav(buf, duration=-1)

从缓冲区播放 WAV 数据。

参数:
  • buf (bytes) – WAV 数据。

  • duration (int) – 持续时间(毫秒),-1 表示整段缓冲区。

返回类型:

None

UiFlow2 代码块:

play_wav.png

MicroPython 代码块:

echo_pyramid.play_wav(wav_bytes, duration=1000)
play_raw(buf, rate=16000, bits=16, channel=2, duration=-1)

播放原始 PCM 数据。

参数:
  • buf (bytes) – 原始 PCM 数据。

  • rate (int) – 采样率(Hz)。

  • bits (int) – 位深(如 16)。

  • channel (int) – 声道数(1 或 2)。

  • duration (int) – 持续时间(毫秒),-1 表示整段缓冲区。

返回类型:

None

UiFlow2 代码块:

play_raw.png

MicroPython 代码块:

echo_pyramid.play_raw(pcm_bytes, rate=16000, bits=16, channel=2)
pause()

暂停播放。

UiFlow2 代码块:

pause.png

MicroPython 代码块:

echo_pyramid.pause()
返回类型:

None

resume()

恢复播放。

UiFlow2 代码块:

resume.png

MicroPython 代码块:

echo_pyramid.resume()
返回类型:

None

stop()

停止播放。

UiFlow2 代码块:

stop.png

MicroPython 代码块:

echo_pyramid.stop()
返回类型:

None

get_volume()

获取扬声器音量。

返回:

当前音量值。

返回类型:

int

UiFlow2 代码块:

get_volume.png

MicroPython 代码块:

volume = echo_pyramid.get_volume()
set_volume(volume)

设置扬声器音量。

参数:

volume (int) – 音量值。

返回类型:

None

UiFlow2 代码块:

set_volume.png

MicroPython 代码块:

echo_pyramid.set_volume(60)
record_wav_file(path, rate=16000, bits=16, channel=2, duration=3000)

将音频录制为 WAV 文件。

参数:
  • path (str) – 输出文件路径。

  • rate (int) – 采样率(Hz)。

  • bits (int) – 位深。

  • channel (int) – 声道模式,使用 MONOSTEREO

  • duration (int) – 持续时间(毫秒)。

返回类型:

None

UiFlow2 代码块:

record_wav_file.png

MicroPython 代码块:

echo_pyramid.record_wav_file("/flash/res/audio/test.wav", rate=16000, bits=16, channel=echo_pyramid.STEREO, duration=3000)
record(rate=16000, bits=16, channel=2, duration=3000)

将音频录制到 PCM 缓冲区。

参数:
  • rate (int) – 采样率(Hz)。

  • bits (int) – 位深。

  • channel (int) – 声道数。

  • duration (int) – 持续时间(毫秒)。

返回:

录制结果(与实现相关)。

UiFlow2 代码块:

record.png

MicroPython 代码块:

buf = echo_pyramid.record(rate=16000, bits=16, channel=2, duration=3000)
property pcm_buffer: bytes

来自麦克风的 PCM 缓冲区(只读),录音后可用。

UiFlow2 代码块:

pcm_buffer.png

MicroPython 代码块:

data = echo_pyramid.pcm_buffer
deinit()

反初始化扬声器与麦克风,并静音输出。

MicroPython 代码块:

echo_pyramid.deinit()
返回类型:

None