Skip to content

Micropython support for ev3dev2.sound #628

Closed

Description

@staadecker

ev3dev2.sound does not support micropython. This is an issue because audio keys are useful while testing. For now I can use the following to make the robot beep.

import os
os.system("/usr/bin/beep")

However it would be nice to have support. I found that what is breaking the module is
from subprocess import check_output, Popen, PIPE.

Activity

  1. dwalton76 commented on May 10, 2019

    @dwalton76
    Collaborator

    yeah the issue is with Sound.py using subprocess...I was reading this:
    https://forum.micropython.org/viewtopic.php?t=5055

    It sounds like you should be able to replace the subprocess calls with os.fork() or os.system() calls. If you want to work on it assign this issue to yourself (or if you can't let me know and I can assign it to you).

  2. staadecker commented on May 11, 2019

    @staadecker
    Author

    Unfortunately, this is really not my area of expertise. I'm confused when looking at the code. For now I will use os.system("/usr/bin/beep")

  3. JunOllyLi commented on May 12, 2019

    @JunOllyLi

    I had an experiment project, to improve ev3dev2 support in Micropython.
    You guys can try it if you are interested. I am not familiar with the Debian Packaging stuff, so this would require some hands on compiling.

    https://github.com/robosaurus-ev3dev2-upy/upy-ev3dev2

    So far I tested LEDs, sound, buttons and they work. And of course the motors and external sensors were already supported.

  4. dwalton76 commented on May 12, 2019

    @dwalton76
    Collaborator

    I'll take a stab at it

  5. dwalton76 commented on May 12, 2019

    @dwalton76
    Collaborator

    @JunOllyLi wow you have made a lot of progress!! Have you thought about submitting pull requests for the changes you have made to the various repos? It would be nice to pull your work in and have sound, buttons and LEDs all working in micropython for ev3dev-lang-python.

  6. WasabiFan commented on May 13, 2019

    @WasabiFan
    Member

    Yeah, @JunOllyLi we'd love to accept these changes into the official repos if you're interested. I haven't looked through it in depth, but I expect we'd be open to merging pretty much all of it. We'd really love the help for improved uPy support!

  7. JunOllyLi commented on May 13, 2019

    @JunOllyLi

    Would love to, but if you looked at my changes, mostly they are in micropyton-lib and evdev. There only two very small quick hacks in ev3dev2, which I am not even satisfied although they work. At lease one of the changes should be fixed later with better PCRE implementation in Micropython-lib.
    The change in evdev is a total re-written C code in Micropython module style, not going to be compatible with CPython code at all. Not sure if evdev guys would like to take it.
    Some of the changes in Micropython-lib probably makes sense to get merged back. But I would need more time to make them better. I am not a Python programmer, and the changes I made was just to "make ev3dev2 work", and not totally compliant with the CPython API definitions. I know I have skipped a lot of potential parameters in those functions.

  8. WasabiFan commented on May 13, 2019

    @WasabiFan
    Member

    I only looked over your changes briefly, so I can't say for sure what parts are doable and what aren't. We do ship our own fork of micropython-lib with ev3dev, so that could probably be updated. Or, just include them in our own library source.

    The evdev library is a bit of a different story, but I'd be interested in looking at the options there... Depending on the changes you made we might be able to emulate them via Python or ship the native code in some reasonable container, maybe as a separate package.

  9. self-assigned this
    on May 13, 2019
  10. dwalton76 commented on May 13, 2019

    @dwalton76
    Collaborator

    Once a few PRs go in the main feature we will be missing that is in @JunOllyLi 's library is Button support. dlech had that working here so I don't think we are too far off from having pretty good micropython support without have to touch ev3dev, micropython-lib, or micropython.

  11. JunOllyLi commented on May 14, 2019

    @JunOllyLi

    I only looked over your changes briefly, so I can't say for sure what parts are doable and what aren't. We do ship our own fork of micropython-lib with ev3dev, so that could probably be updated. Or, just include them in our own library source.

    The evdev library is a bit of a different story, but I'd be interested in looking at the options there... Depending on the changes you made we might be able to emulate them via Python or ship the native code in some reasonable container, maybe as a separate package.

    Yes, I don't see any problem to implement that in Python. I was just too lazy to do that. It requires a couple of IOCTLs, and what needed is to get the bit definition of the IOCTL numbers ported from C to Python, and pack/unpack the C structures used in those IOCTLs. I just took the shortcut and used what already defined in C. As I said, I am not a Python programmer, C is more my type. :)

  12. dwalton76 commented on May 19, 2019

    @dwalton76
    Collaborator

    @staadecker FYI Sound will work with micropython now

  13. staadecker commented on May 19, 2019

    @staadecker
    Author

    @dwalton76 thank you! How can I use the latest unreleased code on the EV3. Is the repo already cloned and I just need to pull to get the updates?

  14. WasabiFan commented on May 20, 2019

    @WasabiFan
    Member

    @staadecker we'd love some help testing! The easiest way to test it is to clone the repository and add it to your PATH so that it overrides the system-installed version. This should do it:

    $ cd ~/
    $ git clone https://github.com/ev3dev/ev3dev-lang-python.git
    $ export PATH=~/ev3dev-lang-python/
    

    The last line only applies within your current terminal session; if you'd like it to be permanent you can add the line to your ~/.bashrc. But you should test it once first to make sure I didn't mess up the commands.

    If you confirm, I'll update #611 and merge that, then probably do a release soon. If you're up for it, you can also test out other things we've recently added tagged "micropython".

  15. dwalton76 commented on May 20, 2019

    @dwalton76
    Collaborator

    @WasabiFan I am pretty close on being done with #571 , I have it working (I pulled in dlech's code) it just needs some cleanup of some duplicated code between the Button classes for python3 vs the Button classes for micropython. I would like to get that one one before we do a release. We have so much working in micropython now I am using it more and more.

  16. WasabiFan commented on May 20, 2019

    @WasabiFan
    Member

    Damn, nice! I wasn't expecting buttons to get working that fast. This sounds good to me; I'll wait until the buttons are merged.

  17. staadecker commented on May 30, 2019

    @staadecker
    Author

    @staadecker we'd love some help testing! The easiest way to test it is to clone the repository and add it to your PATH so that it overrides the system-installed version. This should do it:

    $ cd ~/
    $ git clone https://github.com/ev3dev/ev3dev-lang-python.git
    $ export PATH=~/ev3dev-lang-python/
    

    The last line only applies within your current terminal session; if you'd like it to be permanent you can add the line to your ~/.bashrc. But you should test it once first to make sure I didn't mess up the commands.

    If you confirm, I'll update #611 and merge that, then probably do a release soon. If you're up for it, you can also test out other things we've recently added tagged "micropython".

    @WasabiFan. I tried testing it today. I was able to clone the repo into the home folder. I can use the repo in python3 no problem using export PYTHONPATH=~/ev3dev-lang-python/. However, micropython is unable to find the package and using PATH` doesn't work either.

  18. added a commit that references this issue on Dec 20, 2025
    bae544f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions