Skip to content

Commit 4c652da

Browse files
docs: Update the docs to include the V2 API (#692)
* Add microphone API * include V2 on index * update music and V2 pins * update speech * update audio * update i2c * add description to built-in sounds * format sounds * format pins * format pins * spelling * Update docs/audio.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/audio.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/i2c.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/microbit_micropython_api.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/microbit_micropython_api.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * changes based on initial feedback * update return pin * sound is in microbit module * Update docs/audio.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/microbit_micropython_api.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/microbit_micropython_api.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * more feedback updates * spacing * Update docs/audio.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * does this comment work? * Revert "does this comment work?" This reverts commit 4846113. * update audio * update audio * add Python Editor * add references to sound * update mic image * Update docs/microbit_micropython_api.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * multiple fixes * use Param in docs * update SouneEvent * update microphone module * update param * update image list * update parameters * remove note * update param * add line break * add mic and make clases a-z * format parameters * Update docs/microbit_micropython_api.rst * Update docs/microbit_micropython_api.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * more updates * tidy up * move SoundEvent * Revert "move SoundEvent" This reverts commit 8f52c97. * move soundEvent * update image list * remove param reference * more feedback updates * move audio to modules * Update docs/music.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/microphone.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/microbit_micropython_api.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/microphone.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/music.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * Update docs/audio.rst Co-authored-by: Carlos Pereira Atencio <[email protected]> * more updates Co-authored-by: Carlos Pereira Atencio <[email protected]>
1 parent a92ca9b commit 4c652da

File tree

13 files changed

+479
-170
lines changed

13 files changed

+479
-170
lines changed

docs/audio.rst

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,48 @@ Audio
33

44
.. py:module:: audio
55
6-
This module allows you play sounds from a speaker attached to the Microbit.
7-
In order to use the audio module you will need to provide a sound source.
6+
This module allows you to play your own sounds. If you are using a micro:bit
7+
**V2**, ``audio`` is also part of the ``microbit`` module.
88

9-
A sound source is an iterable (sequence, like list or tuple, or a generator) of
10-
frames, each of 32 samples.
11-
The ``audio`` modules plays samples at the rate of 7812.5 samples per second,
12-
which means that it can reproduce frequencies up to 3.9kHz.
9+
By default sound output will be via the edge connector on pin 0 and the
10+
built-in speaker **V2**. You can connect a wired headphones or a speaker to
11+
pin 0 and GND on the edge connector to hear the sounds.
1312

1413
Functions
1514
=========
1615

1716
.. py:function:: play(source, wait=True, pin=pin0, return_pin=None)
17+
play(source, wait=True, pin=(pin_speaker, pin0), return_pin=None)
1818
1919
Play the source to completion.
2020

21-
``source`` is an iterable, each element of which must be an ``AudioFrame``.
21+
* **source**: ``Sound`` - The ``microbit`` module contains a list of
22+
built-in sounds that your can pass to ``audio.play()``.
2223

23-
If ``wait`` is ``True``, this function will block until the source is exhausted.
24+
* **source**: ``AudioFrame`` - The source agrument can also be an iterable
25+
of ``AudioFrame`` elements as described below.
2426

25-
``pin`` specifies which pin the speaker is connected to.
27+
* **wait**: If ``wait`` is ``True``, this function will block until the
28+
source is exhausted.
2629

27-
``return_pin`` specifies a differential pin to connect to the speaker
28-
instead of ground.
30+
* **pin**: As with the music module, you can use the optional ``pin``
31+
argument to specify the output pin can be used to override the
32+
default of ``microbit.pin0``. If you have the latest micro:bit **V2**,
33+
you can use ``microbit.pin_speaker``. The pin argument can also take a
34+
tuple of two pins, for example ``pin=(pin_speaker, pin0)`` which would
35+
output sound on the built-in speaker and pin 0.
36+
37+
* **return_pin**: specifies a differential edge connector pin to connect
38+
to an external speaker instead of ground. This is ignored for the **V2**
39+
revision.
40+
41+
.. py:function:: is_playing()
42+
43+
Return ``True`` if audio is playing, otherwise return ``False``.
44+
45+
.. py:function:: stop()
46+
47+
Stops all audio playback.
2948

3049
Classes
3150
=======
@@ -41,9 +60,25 @@ Classes
4160
Using audio
4261
===========
4362

44-
You will need a sound source, as input to the ``play`` function. You can generate your own, like in
45-
``examples/waveforms.py``.
63+
You will need a sound source, as input to the ``play`` function. You can use
64+
the built-in sounds **V2** from the ``microbit`` module, ``microbit.Sound``, or
65+
generate your own, like in ``examples/waveforms.py``.
4666

67+
Built-in sounds **V2**
68+
----------------------
69+
70+
The built-in sounds can be called using ``audio.play(Sound.NAME)``.
71+
72+
* ``Sound.GIGGLE``
73+
* ``Sound.HAPPY``
74+
* ``Sound.HELLO``
75+
* ``Sound.MYSTERIOUS``
76+
* ``Sound.SAD``
77+
* ``Sound.SLIDE``
78+
* ``Sound.SOARING``
79+
* ``Sound.SPRING``
80+
* ``Sound.TWINKLE``
81+
* ``Sound.YAWN``
4782

4883
Technical Details
4984
=================
@@ -52,23 +87,24 @@ Technical Details
5287
You don't need to understand this section to use the ``audio`` module.
5388
It is just here in case you wanted to know how it works.
5489

55-
The ``audio`` module consumes samples at 7812.5 Hz, and uses linear interpolation to
56-
output a PWM signal at 32.5 kHz, which gives tolerable sound quality.
90+
The ``audio`` module consumes ``AudioFrame`` samples at 7812.5 Hz, and uses
91+
linear interpolation to output a PWM signal at 32.5 kHz, which gives tolerable
92+
sound quality.
5793

5894
The function ``play`` fully copies all data from each ``AudioFrame`` before it
59-
calls ``next()`` for the next frame, so a sound source can use the same ``AudioFrame``
60-
repeatedly.
95+
calls ``next()`` for the next frame, so a sound source can use the same
96+
``AudioFrame`` repeatedly.
6197

62-
The ``audio`` module has an internal 64 sample buffer from which it reads samples.
63-
When reading reaches the start or the mid-point of the buffer, it triggers a callback to
64-
fetch the next ``AudioFrame`` which is then copied into the buffer.
65-
This means that a sound source has under 4ms to compute the next ``AudioFrame``,
66-
and for reliable operation needs to take less 2ms (which is 32000 cycles, so should be plenty).
98+
The ``audio`` module has an internal 64 sample buffer from which it reads
99+
samples. When reading reaches the start or the mid-point of the buffer, it
100+
triggers a callback to fetch the next ``AudioFrame`` which is then copied into
101+
the buffer. This means that a sound source has under 4ms to compute the next
102+
``AudioFrame``, and for reliable operation needs to take less 2ms (which is
103+
32000 cycles, so should be plenty).
67104

68105

69106
Example
70107
=======
71108

72109
.. include:: ../examples/waveforms.py
73110
:code: python
74-

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
# General information about the project.
5555
project = u'BBC micro:bit MicroPython'
56-
copyright = u'2015-2016, Multiple authors'
56+
copyright = u'2015-2020, Multiple authors'
5757

5858
# The version info for the project you're documenting, acts as replacement for
5959
# |version| and |release|, also used in various other places throughout the

docs/i2c.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ Functions
2828

2929
.. warning::
3030

31-
Changing the I²C pins from defaults will make the accelerometer and
32-
compass stop working, as they are connected internally to those pins.
31+
On a micro:bit V1 board, changing the I²C pins from defaults will make
32+
the accelerometer and compass stop working, as they are connected
33+
internally to those pins. This warning does not apply to the **V2**
34+
revision of the micro:bit as this has `separate I²C lines
35+
<https://tech.microbit.org/hardware/i2c/>`_
36+
for the motion sensors and the edge connector.
37+
3338

3439

3540
.. py:function:: scan()

docs/index.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@ BBC micro:bit MicroPython documentation
88

99
Welcome!
1010

11-
The BBC micro:bit is a small computing device for children. One of the
12-
languages it understands is the popular Python programming language. The
13-
version of Python that runs on the BBC micro:bit is called MicroPython.
11+
The `BBC micro:bit <https://microbit.org>`_ is a small computing device for
12+
children. One of the languages it understands is the popular Python programming
13+
language. The version of Python that runs on the BBC micro:bit is called
14+
MicroPython.
1415

1516
This documentation includes lessons for teachers
1617
and API documentation for developers (check out the index on the left). We hope
1718
you enjoy developing for the BBC micro:bit using MicroPython.
1819

19-
If you're a new programmer, teacher or unsure where to start, begin with the tutorials.
20+
.. note::
21+
22+
The BBC micro:bit MicroPython documentation contains information for all
23+
versions of the micro:bit board. Where functionality is applicable only
24+
to the latest device, you will see a note or comment marking this as
25+
**V2**.
26+
27+
If you're a new programmer, teacher or unsure where to start, begin with the
28+
tutorials.
2029

2130
.. image:: comic.png
2231

@@ -28,8 +37,15 @@ If you're a new programmer, teacher or unsure where to start, begin with the tut
2837

2938
Projects related to MicroPython on the BBC micro:bit include:
3039

31-
* `Mu <https://github.com/ntoll/mu>`_ - a simple code editor for kids, teachers and beginner programmers. Probably the easiest way for people to program MicroPython on the BBC micro:bit.
32-
* `uFlash <https://uflash.readthedocs.io/en/latest/>`_ - a command line tool for flashing raw Python scripts onto a BBC micro:bit.
40+
* `micro:bit Python Editor <https://python.microbit.org>`_ A simple
41+
browser-based code editor, designed to help teachers and learners get the
42+
most out of text-based programming on the micro:bit.
43+
44+
* `Mu <https://codewith.mu>`_ A simple offline code editor for kids, teachers
45+
and beginner programmers.
46+
47+
* `uFlash <https://uflash.readthedocs.io/en/latest/>`_ A command line tool
48+
for flashing raw Python scripts onto a BBC micro:bit.
3349

3450
.. toctree::
3551
:maxdepth: 2
@@ -67,6 +83,7 @@ Projects related to MicroPython on the BBC micro:bit include:
6783
i2c.rst
6884
image.rst
6985
machine.rst
86+
microphone.rst
7087
micropython.rst
7188
music.rst
7289
neopixel.rst

docs/microbit.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Classes
6262
:maxdepth: 1
6363

6464
image.rst
65+
Sound <audio.rst>
6566

6667

6768
Modules
@@ -70,9 +71,11 @@ Modules
7071
.. toctree::
7172
:maxdepth: 1
7273

73-
display.rst
74-
uart.rst
75-
spi.rst
76-
i2c.rst
7774
accelerometer.rst
75+
Audio V2 <audio.rst>
7876
compass.rst
77+
display.rst
78+
i2c.rst
79+
microphone.rst
80+
spi.rst
81+
uart.rst

0 commit comments

Comments
 (0)