Skip to content

Commit

Permalink
Workaround for not having an any() method
Browse files Browse the repository at this point in the history
Reduced the timeout value for the UART bus from 1 second to 30
milliseconds. This makes the library almost as fast as the version that
had access to the UART.any() method.

Also, lots of updates to the documentation.
  • Loading branch information
mmabey committed Sep 28, 2017
1 parent 4a4add0 commit fde2880
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 118 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ ENV/
.idea
*.bak
_build

# Added by me
*.swp
*.mpy
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ deploy:
before_install:
- sudo apt-get -yqq update
- sudo apt-get install -y build-essential git python python-pip
- git clone https://github.com/adafruit/circuitpython.git
- git clone -b 2.0.0 https://github.com/adafruit/circuitpython.git
- make -C circuitpython/mpy-cross
- export PATH=$PATH:$PWD/circuitpython/mpy-cross/
- sudo pip install shyaml
Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ verify_ssl = true
url = "https://pypi.python.org/simple"

[dev-packages]
sphinx = "*"
sphinx-rtd-theme = "*"
Sphinx = "*"
sphinx_rtd_theme = "*"
118 changes: 88 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ Adafruit Soundboard Library

|ports| |docs| |version| |ci| |license_type|

.. toctree::
:maxdepth: 2
:hidden:

Home <self>
api

The `Adafruit Soundboards <https://learn.adafruit.com/adafruit-audio-fx-sound-board>`_ are an easy way to add sound to
your maker project, but the `library <https://github.com/adafruit/Adafruit_Soundboard_library>`_ provided by Adafruit
only supports Arduino.

If you've wanted to use one of these boards with a `MicroPython <http://micropython.org/>`_ or `CircuitPython
<https://github.com/adafruit/circuitpython>`_ microcontroller (MCU), this is the library you've been looking for.
<https://github.com/adafruit/circuitpython>`_ microcontroller (MCU), this is the library you've been looking for. Please
note, though, if you're planning to use MicroPython, you should refer to the separate repository
(https://github.com/mmabey/Adafruit_Soundboard_uPy) and documentation (coming soon), as their implementations differ.

Take a look at the latest documentation on `Read the Docs`_ and the latest code on `GitHub`_.


Installation
Expand All @@ -23,43 +34,88 @@ Make sure to get the latest version of the code from `GitHub`_.
CircuitPython Instructions
^^^^^^^^^^^^^^^^^^^^^^^^^^

First, you'll need to get `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_. Then, please ensure
all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
First, you'll need to get `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ and install it on your
board. Then, please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by
downloading `the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.

Next, you need to know what *version* of CircuitPython you installed on your MCU. The next steps you take depend on if
your version of CircuitPython matches what is listed in the "CircuitPython Version" badge above.

Matching Version
~~~~~~~~~~~~~~~~

If the version *matches* the "CircuitPython Version" badge above, simply download the latest version of the
``adafruit_soundboard.mpy`` script from `the releases page <https://github.com/mmabey/Adafruit_Soundboard/releases>`_
and copy it to the MCU.

Non-Matching Version
~~~~~~~~~~~~~~~~~~~~

If you are using a version of CircuitPython that's *different* from what's listed in the "CircuitPython Version" badge
above, do the following:

1. Clone the CircuitPython repository at the version tag you're using (requires the installation of ``git``):

::

git clone -b <VERSION HERE> https://github.com/adafruit/circuitpython.git

2. Build the ``mpy-cross`` cross-compiler (requires the \*nix program ``make``):

::

which make # If this command gives no output, you don't have make installed
cd circuitpython/mpy-cross && make

3. Clone the sound board library:

::

git clone https://github.com/mmabey/Adafruit_Soundboard.git soundboard

4. Cross-compile the library, which will create a file named ``adafruit_soundboard.mpy``:

::

cd soundboard && mpy-cross adafruit_soundboard.py

5. Copy the ``adafruit_soundboard.mpy`` file to your MCU.


MicroPython Instructions
^^^^^^^^^^^^^^^^^^^^^^^^

At this time, you have to install the driver by copying the |soundboard|_ to your MicroPython board along
with your ``main.py`` file. At some point in the future it may be possible to ``pip install`` it.

.. |soundboard| replace:: ``soundboard.py`` script
.. _soundboard: https://github.com/mmabey/Adafruit_Soundboard/blob/master/src/soundboard.py
Please refer to the separate repository (https://github.com/mmabey/Adafruit_Soundboard_uPy) and documentation (coming
soon), for using this library with MicroPython.


Quick Start
-----------

First, you'll need to decide which UART bus you want to use. To do this, you'll need to consult the documentation for
your particular MCU. In these examples, I'm using the original ``pyboard`` (see documentation `here
<http://docs.micropython.org/en/latest/pyboard/>`_) and I'm using UART bus 1 or ``XB``, which uses pin ``X9`` for
transmitting and ping ``X10`` for receiving.
First, you'll need to decide which pins you want to use for the UART bus. To do this, you'll need to consult the
documentation for your particular MCU. In these examples, I'm using the Adafruit `Metro M0 Express
<https://www.adafruit.com/product/3505>`_ and I'm using pin ``D0`` for the UART ``RX`` (receiving) and ``D1`` for ``TX``
(transmitting). See the `pinout guide <http://circuitpython.readthedocs.io/en/2.x/atmel-samd/README.html#pinout>`_ for
information on other supported pins for ``RX`` and ``TX``.

Then, create an instance of the :class:`~soundboard.Soundboard` class, like this:
Next, you *have to* connect the ``UG`` pin on the sound board to ``GND`` somehow. This is what tells the sound board to
function in UART mode. For more info, please refer to Adafruit's guide for the sound boards:
https://learn.adafruit.com/adafruit-audio-fx-sound-board/serial-audio-control#general-usage

Then, create an instance of the :class:`~adafruit_soundboard.Soundboard` class, like this:

::

sound = Soundboard('XB')
from adafruit_soundboard import Soundboard
sound = Soundboard('D1', 'D0')

I *highly* recommend you also attach the ``RST`` pin on the sound board to one of the other GPIO pins on the MCU (pin
``X11`` in the example). Also, my alternative method of getting the list of files from the board is more stable (in my
own testing) than the method built-in to the sound board. Also, I like getting the debug output and I turn the volume
down to 50% while I'm coding. Doing all this looks like the following:
``D3`` in the example). Also, I like getting the debug output and I turn the volume down to 50% while I'm coding. Doing
all this looks like the following:

::

SB_RST = 'X11'
sound = Soundboard('XB', rst_pin=SB_RST, vol=0.5, debug=True, alt_get_files=True)
sound = Soundboard('D1', 'D0', 'D3', vol=0.5, debug=True)

Once you've set up all of this, you're ready to play some tracks:

Expand All @@ -72,7 +128,7 @@ Once you've set up all of this, you're ready to play some tracks:
sound.stop()

# Play the test file that comes with the sound board
sound.play('T00 OGG')
sound.play(b'T00 OGG')

# Play track 1 immediately, stopping any currently playing tracks
sound.play_now(1)
Expand Down Expand Up @@ -104,18 +160,18 @@ You can also control the volume in several different ways:
API Reference
-------------

.. toctree::
:maxdepth: 2
Please read the |api|_ for additional details on how to use the library.

api
.. |api| replace:: ``adafruit_soundboard`` API reference
.. _api: api.html


Contributing
------------

Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_soundboard/blob/master/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.
Contributions are welcome! Please read the `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_soundboard/blob/master/CODE_OF_CONDUCT.md>`_ before contributing to
help this project stay welcoming.


License
Expand All @@ -124,8 +180,8 @@ License
This project is licensed under the `MIT License <https://github.com/mmabey/Adafruit_Soundboard/blob/master/LICENSE>`_.


.. |ports| image:: https://img.shields.io/badge/MicroPython%20Ports-pyboard,%20wipy,%20esp8266-lightgrey.svg
:alt: Supported ports: pyboard, wipy, esp8266
.. |ports| image:: https://img.shields.io/badge/CircuitPython%20Version-2.0-blue.svg
:alt: Supported version of CircuitPython: 2.0
:target: `GitHub`_

.. |docs| image:: https://readthedocs.org/projects/adafruit-soundboard/badge/
Expand All @@ -134,7 +190,7 @@ This project is licensed under the `MIT License <https://github.com/mmabey/Adafr

.. |version| image:: https://img.shields.io/github/release/mmabey/Adafruit_Soundboard/all.svg
:alt: Release Version
:target: https://github.com/mmabey/Adafruit_Soundboard
:target: `GitHub Releases`_

.. |ci| image:: https://travis-ci.org/mmabey/Adafruit_Soundboard.svg
:alt: CI Build Status
Expand All @@ -146,4 +202,6 @@ This project is licensed under the `MIT License <https://github.com/mmabey/Adafr

.. _GitHub: https://github.com/mmabey/Adafruit_Soundboard

.. _GitHub Releases: https://github.com/mmabey/Adafruit_Soundboard/releases

.. _Read the Docs: http://adafruit-soundboard.readthedocs.io/
Loading

0 comments on commit fde2880

Please sign in to comment.