Skip to content

Commit cd5a13e

Browse files
docs: Update the docs to include the V2 API (bbcmicrobit#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 2caf5ef commit cd5a13e

File tree

11 files changed

+433
-134
lines changed

11 files changed

+433
-134
lines changed

docs/audio.rst

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,47 @@ Audio
33

44
.. py:module:: audio
55
6-
This module allows you play sounds from a speaker attached to the micro:bit.
6+
This module allows you play sounds with the micro:bit.
7+
8+
By default sound output will be via the edge connector on pin 0 and the
9+
built-in speaker **V2**. You can connect a wired headphones or a speaker to
10+
pin 0 and GND on the edge connector to hear the sounds.
711

812
The ``audio`` module can be imported as ``import audio`` or accessed via
913
the ``microbit`` module as ``microbit.audio``.
1014

11-
In order to use the audio module you will need to provide a sound source.
12-
13-
A sound source is an iterable (sequence, like list or tuple, or a generator) of
14-
frames, each of 32 samples.
15-
The ``audio`` modules plays samples at the rate of 7812.5 samples per second,
16-
which means that it can reproduce frequencies up to 3.9kHz.
17-
1815
Functions
1916
=========
2017

2118
.. py:function:: play(source, wait=True, pin=pin0, return_pin=None)
19+
play(source, wait=True, pin=(pin_speaker, pin0), return_pin=None)
2220
2321
Play the source to completion.
2422

25-
:param source: An iterable sound source, each element of which must be
26-
an ``AudioFrame``.
23+
:param source: ``Sound``: The ``microbit`` module contains a list of
24+
built-in sounds that your can pass to ``audio.play()``.
25+
26+
``AudioFrame``: The source agrument can also be an iterable
27+
of ``AudioFrame`` elements as described below.
2728
:param wait: If ``wait`` is ``True``, this function will block until the
2829
source is exhausted.
29-
:param pin: Specifies which pin the speaker is connected to.
30-
:param return_pin: Specifies a differential pin to connect to the speaker
31-
instead of ground.
30+
:param 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+
:param return_pin: specifies a differential edge connector pin to connect
37+
to an external speaker instead of ground. This is ignored for the **V2**
38+
revision.
39+
40+
.. py:function:: is_playing()
41+
42+
:returns: ``True`` if audio is playing, otherwise returns ``False``.
43+
44+
.. py:function:: stop()
45+
46+
Stops all audio playback.
3247

3348
Classes
3449
=======
@@ -52,9 +67,25 @@ Classes
5267
Using audio
5368
===========
5469

55-
You will need a sound source, as input to the ``play`` function. You can generate your own, like in
56-
``examples/waveforms.py``.
70+
You will need a sound source, as input to the ``play`` function. You can use
71+
the built-in sounds **V2** from the ``microbit`` module, ``microbit.Sound``, or
72+
generate your own, like in ``examples/waveforms.py``.
73+
74+
Built-in sounds **V2**
75+
----------------------
5776

77+
The built-in sounds can be called using ``audio.play(Sound.NAME)``.
78+
79+
* ``Sound.GIGGLE``
80+
* ``Sound.HAPPY``
81+
* ``Sound.HELLO``
82+
* ``Sound.MYSTERIOUS``
83+
* ``Sound.SAD``
84+
* ``Sound.SLIDE``
85+
* ``Sound.SOARING``
86+
* ``Sound.SPRING``
87+
* ``Sound.TWINKLE``
88+
* ``Sound.YAWN``
5889

5990
Technical Details
6091
=================
@@ -63,7 +94,8 @@ Technical Details
6394
You don't need to understand this section to use the ``audio`` module.
6495
It is just here in case you wanted to know how it works.
6596

66-
The ``audio`` module consumes ``AudioFrame`` samples at 7812.5 Hz, and uses
97+
The ``audio`` module can consumes an iterable (sequence, like list or tuple, or
98+
generator) of ``AudioFrame`` instances, each 32 samples at 7812.5 Hz, and uses
6799
linear interpolation to output a PWM signal at 32.5 kHz, which gives tolerable
68100
sound quality.
69101

@@ -84,4 +116,3 @@ Example
84116

85117
.. include:: ../examples/waveforms.py
86118
:code: python
87-

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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ 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

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+
1927
If you're a new programmer, teacher or unsure where to start, begin with the
2028
:ref:`Tutorials <Tutorials>` and use the `micro:bit Python Editor <https://python.microbit.org>`_
2129
to program the micro:bit.
@@ -76,6 +84,7 @@ Projects related to MicroPython on the BBC micro:bit include:
7684
i2c.rst
7785
image.rst
7886
machine.rst
87+
microphone.rst
7988
micropython.rst
8089
music.rst
8190
neopixel.rst

docs/microbit.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Classes
6464
:maxdepth: 1
6565

6666
image.rst
67+
Sound <audio.rst>
6768

6869

6970
Modules
@@ -73,8 +74,10 @@ Modules
7374
:maxdepth: 1
7475

7576
accelerometer.rst
77+
Audio V2 <audio.rst>
7678
compass.rst
7779
display.rst
7880
i2c.rst
81+
microphone.rst
7982
spi.rst
8083
uart.rst

0 commit comments

Comments
 (0)