Skip to content

Commit 70f9a28

Browse files
docs: Include V2 features in tutorials (#709)
* docs: update-tutorials for V2 * docs: update images * remove pin functions reference link * reduce size of image * Update docs/pin.rst * Update docs/pin.rst * Update docs/tutorials/io.rst Co-authored-by: Carlos Pereira Atencio <carlos@microbit.org>
1 parent 8a7a594 commit 70f9a28

8 files changed

Lines changed: 62 additions & 36 deletions

File tree

docs/tutorials/blue-microbit.png

32 KB
Loading

docs/tutorials/happy.png

11.7 KB
Loading

docs/tutorials/images.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ display is a part of the ``Image`` object and called ``HAPPY``. We tell
1818
``show`` to use it by putting it between the parenthesis (``(`` and ``)``).
1919

2020
.. image:: happy.png
21+
:width: 300px
22+
:align: center
2123

2224
Here's a list of the built-in images:
2325

docs/tutorials/io.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
Input/Output
2-
------------
1+
Input/Output Pins
2+
-----------------
33

44
There are strips of metal along the bottom edge of the BBC micro:bit that make
55
it look as if the device has teeth. These are the input/output pins (or I/O pins
66
for short).
77

88
.. image:: blue-microbit.png
9+
:width: 300px
10+
:align: center
11+
:alt: micro:bit with pins labelled
912

1013
Some of the pins are bigger than others so it's possible to attach crocodile
1114
clips to them. These are the ones labelled 0, 1, 2, 3V and GND (computers
1215
always start counting from zero). If you attach an edge connector board to the
1316
device it's possible to plug in wires connected to the other (smaller) pins.
1417

15-
Each pin on the BBC micro:bit is represented by an *object* called ``pinN``
16-
where ``N`` is the pin number. So, for example, to do things with the pin
17-
labelled with a 0 (zero), use the object called ``pin0``.
18+
On the latest micro:bit **V2** the micro:bit logo can also be used as a touch
19+
input.
1820

19-
Simple!
21+
In MicroPython, each pin on the BBC micro:bit is represented by an *object*
22+
called ``pinN``, where ``N`` is the number pf the pin.
23+
24+
For example, to use the pin labelled 0 (zero), you can use the object called
25+
``pin0`` in your script. The logo pin **V2** uses ``pin_logo``.
2026

2127
These objects have various *methods* associated with them depending upon what
22-
the specific pin is capable of.
28+
the specific pin is capable of eg. read, write or touch.
2329

2430
Ticklish Python
2531
+++++++++++++++
2632

2733
The simplest example of input via the pins is a check to see if they are
28-
touched. So, you can tickle your device to make it laugh like this::
34+
touched. So, you can tickle your micro:bit to make it laugh like this::
2935

3036
from microbit import *
3137

@@ -35,18 +41,32 @@ touched. So, you can tickle your device to make it laugh like this::
3541
else:
3642
display.show(Image.SAD)
3743

38-
With one hand, hold your device by the GND pin. Then, with your other hand,
44+
With one hand, hold your micro:bit by the GND pin. Then, with your other hand,
3945
touch (or tickle) the 0 (zero) pin. You should see the display change from
4046
grumpy to happy!
4147

48+
When you use the latest micro:bit **V2** you can also change the default
49+
behaviour of the pin, so that you don't have to touch GND at all.::
50+
51+
from microbit import *
52+
pin0.set_touch_mode(pin0.CAPACITIVE)
53+
while True:
54+
if pin0.is_touched():
55+
display.show(Image.HAPPY)
56+
else:
57+
display.show(Image.SAD)
58+
59+
The default for the edge connector pins is `resistive` and the logo pin
60+
**V2** is `capacitive`.
61+
4262
This is a form of very basic input measurement. However, the fun really starts
4363
when you plug in circuits and other devices via the pins.
4464

4565
Bleeps and Bloops
4666
+++++++++++++++++
4767

48-
The simplest thing we can attach to the device is a Piezo buzzer. There are two
49-
types of piezo buzzers. The simplest type to use are called active buzzers.
68+
The simplest thing we can attach to the micro:bit is a Piezo buzzer. There are
69+
two types of piezo buzzers. The simplest type to use are called active buzzers.
5070
Active buzzers contain an oscillator that produces a tone at a predetermined
5171
pitch when a current is passed through them. Passive buzzers require an
5272
oscillating current to be passed through them to produce a tone at the frequency
@@ -55,11 +75,17 @@ one tone, while passive buzzers are slightly more complicated to use but can
5575
produce a variety of tones.
5676

5777
.. image:: piezo_buzzer.jpg
78+
:width: 250px
79+
:align: center
80+
:alt: piezo buzzer
5881

5982
We're going to use an active piezo buzzer for output. To attach one to your BBC
6083
micro:bit you should attach crocodile clips to pin 0 and GND (as shown below).
6184

6285
.. image:: pin0-gnd.png
86+
:width: 250px
87+
:align: center
88+
:alt: piezo connected to pin0 and GND
6389

6490
The wire from pin 0 should be attached to the positive connector on the buzzer
6591
and the wire from GND to the negative connector.

docs/tutorials/music.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ Music
22
-----
33

44
MicroPython on the BBC micro:bit comes with a powerful music and sound module.
5-
It's very easy to generate bleeps and bloops from the device *if you attach a
6-
speaker or passive piezo buzzer*. Use crocodile clips to attach pin 0 and GND
7-
to the positive and negative inputs on the speaker/buzzer - it doesn't matter
8-
which way round they are connected to a speaker, but a piezo buzzer may be
9-
polarized (check for a "+" marking the positive terminal).
5+
It's very easy to generate bleeps and bloops from the device by attaching a
6+
speaker or set of wired headphones, or by using the built-in speaker **V2**.
7+
8+
If you are attaching a speaker, a passive piezo buzzer, or headphones, you can
9+
use crocodile clips to attach pin 0 and GND to the positive and negative inputs.
10+
It doesn't matter which way round they are connected to a speaker, but a piezo
11+
buzzer may be polarized (check for a "+" marking the positive terminal).
1012

1113
.. image:: pin0-gnd.png
14+
:width: 250px
15+
:align: center
16+
:alt: piezo connected to pin0 and GND
1217

1318
.. note::
1419

15-
Do not attempt this with an active Piezo buzzer - such buzzers are only able to
16-
play a single tone.
20+
Do not attempt this with an active Piezo buzzer - such buzzers are only
21+
able to play a single tone.
1722

1823
Let's play some music::
1924

docs/tutorials/piezo_buzzer.jpg

-114 KB
Loading

docs/tutorials/pin0-gnd.png

25.9 KB
Loading

docs/tutorials/speech.rst

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
Speech
22
------
33

4-
.. warning::
5-
6-
WARNING! THIS IS ALPHA CODE.
7-
8-
We reserve the right to change this API as development continues.
9-
10-
The quality of the speech is not great, merely "good enough". Given the
11-
constraints of the device you may encounter memory errors and / or
12-
unexpected extra sounds during playback. It's early days and we're
13-
improving the code for the speech synthesiser all the time. Bug reports
14-
and pull requests are most welcome.
15-
164
Computers and robots that talk feel more "human".
175

186
So often we learn about what a computer is up to through a graphical user
@@ -42,9 +30,14 @@ In any case, we're going to create a DALEK poetry recital on demand.
4230
Say Something
4331
+++++++++++++
4432

45-
Before the device can talk you need to plug in a speaker like this:
33+
If you have the latest micro:bit **V2** device, you can use the built-in
34+
speaker as well as or instead of connecting a speaker or set of headphones
35+
like this:
4636

47-
.. image:: ../speech.png
37+
.. image:: pin0-gnd.png
38+
:width: 250px
39+
:align: center
40+
:alt: piezo connected to pin0 and GND
4841

4942
The simplest way to get the device to speak is to import the ``speech`` module
5043
and use the ``say`` function like this::
@@ -58,10 +51,10 @@ change some of the parameters that the speech synthesiser uses to produce the
5851
voice. Our speech synthesiser is quite powerful in this respect because we can
5952
change four parameters:
6053

61-
* ``pitch`` - how high or low the voice sounds (0 = high, 255 = Barry White)
62-
* ``speed`` - how quickly the device talks (0 = impossible, 255 = bedtime story)
63-
* ``mouth`` - how tight-lipped or overtly enunciating the voice sounds (0 = ventriloquist's dummy, 255 = Foghorn Leghorn)
64-
* ``throat`` - how relaxed or tense is the tone of voice (0 = falling apart, 255 = totally chilled)
54+
* ``pitch`` - how high or low the voice sounds (0 = high, 255 = low)
55+
* ``speed`` - how quickly the device talks (0 = fast, 255 = slow)
56+
* ``mouth`` - how tight-lipped or overtly enunciating the voice sounds (0 = closed mouth, 255 = open mouth)
57+
* ``throat`` - how relaxed or tense is the tone of voice (0 = tense, 255 = relaxed)
6558

6659
Collectively, these parameters control the quality of sound - a.k.a. the
6760
timbre. To be honest, the best way to get the tone of voice you want is to

0 commit comments

Comments
 (0)