milkv-duo / duo-buildroot-sdk

Milk-V Duo Official buildroot SDK
411 stars 174 forks source link

pinpong 用例不正常 #136

Open Arielfoever opened 2 months ago

Arielfoever commented 2 months ago

代码

# -*- coding: utf-8 -*-

#实验效果:控制板载蜂鸣器播放音乐和控制L灯闪烁
#接线:使用UNIHIKER主板

import time
from pinpong.board import Board,Pin
from pinpong.extension.unihiker import *

Board().begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
#Board("UNIHIKER","COM36").begin()   #windows下指定端口初始化
#Board("UNIHIKER","/dev/ttyACM0").begin()   #linux下指定端口初始化
#Board("UNIHIKER","/dev/cu.usbmodem14101").begin()   #mac下指定端口初始化

led = Pin(Pin.P25, Pin.OUT) #引脚初始化为电平输出

#音乐 DADADADUM ENTERTAINER PRELUDE ODE NYAN RINGTONE FUNK BLUES BIRTHDAY WEDDING FUNERAL PUNCHLINE
#音乐 BADDY CHASE BA_DING WAWAWAWAA JUMP_UP JUMP_DOWN POWER_UP POWER_DOWN
#播放模式 Once(播放一次) Forever(一直播放) OnceInBackground(后台播放一次) ForeverInBackground(后台一直播放)
buzzer.play(buzzer.DADADADUM, buzzer.OnceInBackground) #后台播放音乐一次
# buzzer.set_tempo(4,60) #设置每一拍音符数,每分钟节拍数
# buzzer.pitch(494, 4) #播放音符
# buzzer.pitch(494) #后台播放音符
# time.sleep(10)
# buzzer.stop() #停止后台播放
# buzzer.redirect(Pin.P0) #引脚重定向,只支持PWM引脚 
# buzzer.play(buzzer.ENTERTAINER, buzzer.ForeverInBackground) #后台永久播放音乐
while True:
  led.value(1) #输出高电平
  print("1") #终端打印信息
  time.sleep(0.3) #等待1秒 保持状态

  led.value(0) #输出低电平
  print("0") #终端打印信息
  time.sleep(0.3) #等待1秒 保持状态

出自 https://github.com/milkv-duo/duo-buildroot-sdk/blob/develop/buildroot-2021.05/package/python-pinpong/pinpong/examples/milkv-Duo/buzzer.py

输出

Traceback (most recent call last):
  File "/root/buzzer.py", line 8, in <module>
    from pinpong.extension.unihiker import *
  File "/usr/lib/python3.9/site-packages/pinpong/extension/unihiker.py", line 5, in <module>
    from numpy import mat
ModuleNotFoundError: No module named 'numpy'
krzysztofkuczek commented 2 months ago

You have to build with

BR2_PACKAGE_PYTHON_NUMPY:                                                                                                                                x
  x                                                                                                                                                          x
  x NumPy is the fundamental package for scientific computing                                                                                                x
  x with Python.                                                                                                                                             x
  x                                                                                                                                                          x
  x Note that NumPy needs fenv.h fully supported by the                                                                                                      x
  x C library.                                                                                                                                               x
  x                                                                                                                                                          x
  x http://www.numpy.org/                                                                                                                                    x
  x                                                                                                                                                          x
  x Symbol: BR2_PACKAGE_PYTHON_NUMPY [=y]                                                                                                                    x
  x Type  : bool                                                                                                                                             x
  x Prompt: python-numpy                                                                                                                                     x
  x   Location:                                                                                                                                              x
  x     -> Target packages                                                                                                                                   x
  x       -> Interpreter languages and scripting                                                                                                             x
  x         -> External python modules                                                                                                                       x
  x   Defined at package/python-numpy/Config.in:17                                                                                                           x
  x   Depends on: (BR2_PACKAGE_PYTHON [=n] || BR2_PACKAGE_PYTHON3 [=y]) && BR2_PACKAGE_PYTHON3 [=y] && BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS [=y] && (\     x
  x BR2_TOOLCHAIN_USES_GLIBC [=n] || BR2_TOOLCHAIN_USES_MUSL [=y])                                                                                           x
  x   Selected by [n]:                                                                                                                                       x
  x   - BR2_PACKAGE_PIGLIT [=n] && BR2_PACKAGE_PYTHON3 [=y] && BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS [=y] && (BR2_PACKAGE_WAFFLE_SUPPORTS_GLX [=n] || \     x
  x BR2_PACKAGE_WAFFLE_SUPPORTS_WAYLAND [=n] || BR2_PACKAGE_WAFFLE_SUPPORTS_X11_EGL [=n] || BR2_PACKAGE_WAFFLE_SUPPORTS_GBM [=n]) && (\                      x
  x BR2_TOOLCHAIN_USES_GLIBC [=n] || BR2_TOOLCHAIN_USES_MUSL [=y])                                                                                           x
  x   - BR2_PACKAGE_PYTHON_MATPLOTLIB [=n] && (BR2_PACKAGE_PYTHON [=n] || BR2_PACKAGE_PYTHON3 [=y]) && BR2_INSTALL_LIBSTDCPP [=y] && \                       x
  x BR2_PACKAGE_PYTHON3 [=y] && BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS [=y] && (BR2_TOOLCHAIN_USES_GLIBC [=n] || BR2_TOOLCHAIN_USES_MUSL [=y])               x
  x   - BR2_PACKAGE_OPENCV3_LIB_PYTHON [=n] && BR2_PACKAGE_OPENCV3 [=n] && BR2_PACKAGE_PYTHON3 [=y] && BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS [=y] && (\     x
  x BR2_TOOLCHAIN_USES_GLIBC [=n] || BR2_TOOLCHAIN_USES_MUSL [=y])                                                                                           x
  x   - BR2_PACKAGE_UHD_PYTHON [=n] && BR2_PACKAGE_UHD [=n] && BR2_PACKAGE_PYTHON3 [=y] && BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS [=y] && (\                 x
  x BR2_TOOLCHAIN_USES_GLIBC [=n] || BR2_TOOLCHAIN_USES_MUSL [=y])                                                                                           x
  x   - BR2_PACKAGE_GNURADIO_PYTHON [=n] && BR2_PACKAGE_GNURADIO [=n] && BR2_PACKAGE_PYTHON3 [=y] && BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS [=y] && (\       x
  x BR2_TOOLCHAIN_USES_GLIBC [=n] || BR2_TOOLCHAIN_USES_MUSL [=y])                                                                                           x
  x   - BR2_PACKAGE_KISMET_PYTHON_TOOLS [=n] && BR2_PACKAGE_KISMET [=n] && BR2_PACKAGE_PROTOBUF_ARCH_SUPPORTS [=y] && \                                      x
  x BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS [=y] && BR2_PACKAGE_PYTHON3 [=y] && !BR2_STATIC_LIBS [=n] && BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 [=y] && (\            x
  x BR2_TOOLCHAIN_USES_GLIBC [=n] || BR2_TOOLCHAIN_USES_MUSL [=y])