🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    質問:M5stackへのPythonモジュールのインストール方法

    Scheduled Pinned Locked Moved 日本語フォーラム
    5 Posts 2 Posters 8.3k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ? Offline
      A Former User
      last edited by

      多分大変初歩的なとこだとは思うのですが、分かる方教えてください。

      やりたいこと

      wav|mp3を流しながら(バックグラウンド再生しながら)、別の動作(画面遷移|servo動作)させたい
        このために、m5stackにpythonの外部モジュールpyaudioをインストールして使いたい

      環境

      windows10/m5stack core2
        普段はUIFlowからblocky/micropythonを書いているが、
        Teratermとarduino-ideも使用可能

      やってみたこと①

      /flash/res/pyaudio.py を追加して import pyaudio でやってみたが、
        pyaudioの依存元portaudioがないため動作しない

      やってみたこと②

      https://stackoverflow.com/questions/48135955/installation-of-pyaudio-on-raspberry-pi-3-fails-with-gcc-error
        https://qiita.com/Nyanpy/items/cb4ea8dc4dc01fe56918
        https://qiita.com/yukky-k/items/0d18ec22420e8b35d0ac
        を参考に、sudo pip install pyaudioでインストールできそうなことは分かったが、
        TeratermからUSB接続したm5stackを見ても、micropython(uiflow)として動いており
        sudo pip install pyaudioのコマンドが通せない

      1 Reply Last reply Reply Quote 0
      • mongonta555M Offline
        mongonta555 Global Moderator
        last edited by

        ESP32はラズパイのようにLinuxOSはないので、パッケージを入れることはできません。サウンド制御の部分も独自のドライバでUIFlowからは使えるようになっています。

        恐らくなのですが、portaudio部分を自分で実装しないとpyaudioは使用できないと考えます。(そのままでは動かすのは不可。)

        Pythonで完結するように_threadを使用してサーボ制御と音声の再生を行う方法を模索するしかないでしょう。(UIFlowのMicroPythonでは細かいタスクやスレッドの優先度の制御はできないのでかなり難しいと思います。)

        1 Reply Last reply Reply Quote 0
        • mongonta555M Offline
          mongonta555 Global Moderator
          last edited by

          TwitterでA_P_Delchiさんという方がMicroPythonでサーボの動作と別の処理をスレッドで実現しています。(WAV/MP3再生はしていません。)
          こちらが参考になると思います。

          https://twitter.com/A_P_Delchi/status/1609525689342119938

          https://github.com/apdelchi/sign-chan

          1 Reply Last reply Reply Quote 0
          • ? Offline
            A Former User
            last edited by

            情報ありがとうございます!
            _threadを使用する方向でも検討してみます。

            1 Reply Last reply Reply Quote 0
            • ? Offline
              A Former User
              last edited by

              おっしゃる通り、_threadsで渡すようにしたら
              バックグラウンド再生しつつサーボ制御できました!

              from m5stack import *
              from m5stack_ui import *
              from uiflow import *
              
              import module
              import time
              import math
              import _thread
              
              
              
              def chika_led():
                speaker.playWAV('/sd/head2.wav')
              
              def chika_scr():
                i = 0
                while i < 15 :
                  servo2.position(7,150)
                  wait_ms(100)
                  servo2.position(7,158)
                  wait_ms(100)
                  i = i + 1
              
              
              
              screen = M5Screen()
              screen.clean_screen()
              screen.set_screen_bg_color(0)
              servo2 = module.get(module.SERVO2)
              
              _thread.start_new_thread(chika_led,())
              _thread.start_new_thread(chika_scr,())```
              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post