Musical-Microbit.pdf
(
1217 KB
)
Pobierz
Create electronic music on your micro:bit with
this handy tutorial and reference book.
Make music on the micro:bit
Attribution-NonCommercial-ShareAlike 4.0 International.
Make music on the micro:bit - Maplin
2
Contents
2 - Contents and Introduction
3 - Hardware setup
Attaching a speaker
Modifying some jumpers
4 - Connecting headphones
Using an edge connector
5 - Your first micro:tune
Refining your code
6 - Taking it further
Ready music
7 - Timing is everything!
Tempo
8 - Notes : A reference guide
9 - Links and resources
This is not a Free Culture Licence.
Share and adapt the contents of this guide as you will
as long as you attribute Maplin as the author of the
original work and use it for non-commercial purposes,
although it may be used for commercial classes as
long as there is no charge for this guide or derivative
publications.
Make music on the micro:bit © Maplin 2017
micro:bit and the micro:bit logo are property of the
Micro:bit Educational Foundation.
MicroPython is a project by Damien George and is
copyright to George Robotics Ltd 2014.
Copyright notices
With the aim of free learning for everyone this guide
is offered with a Creative Commons Selected Licence.
Attribution-NonCommercial-ShareAlike 4.0
International.
Document created Jan2017. Updates to MicroPython, micro:bit and any related resource may change outside of our control and render parts of this booklet inaccurate or incorrect.
Introduction
This free and informative booklet aims to
cover a range of tips and includes some
sample code to get you composing in no
time with your micro:bit.
We will mostly be looking at microPython
as the language of choice, but you can
use any of the languages found at
www.microbit.org
to produce music.
You’ll also need some accessories to hear
any music you make as the micro:bit
doesn’t have a speaker or a 3.5mm
connection for speakers.
We hope that you find this booklet useful
and offer it freely for you to share with
your friends and classmates or use it in
your classroom or workgroup.
If you need to purchase a micro:bit or any
accessories required for musical or other
projects, pay us a visit at
maplin.co.uk
or
check out your local store.
We love to see - and hear - what you make
with your micro:bit. Show us your video,
YouTube link or some pictures - drop us a
mail with an attachment or a link to
showandtell@maplin.co.uk.
Make music on the micro:bit - Maplin
3
Hardware setup
While the micro:bit is packed with great
features, there is no speaker built into the
board, which is good from a learning point
of view as it helps you see how the
speaker is driven to make a sound.
We cover a couple of different ways to get
sound from your micro:bit, with a small
speaker module and with a pair of
headphones. Both are simple to attach
and require little prior knowledge.
Attaching a speaker
A small speaker module is adequate for
this task and can be obtained cheaply or
scavenged and recycled from many
electronic items.
If your child is conducting experiments
with the micro:bit, maybe you want to help
with this step as it involves stripping wires
which may call for a sharp implement.
fig 1: micro:bit speaker setup
DIRECTION OF
CURRENT FLOW
DIRECTION OF
CURRENT FLOW
In the example to the left
the speaker module is
connected from Pin 0 of the
micro:bit and then back
through a resistor to the
GND Pin. The same setup
would work without the
resistor but this adds some
electrical protection to
your micro:bit in this set up.
Connectivity tip: Modifying some jumpers
In our example above the wires
connecting to the micro:bit are modified
jumper wires for breadboards that are
common to many electronic kits and
activities. The pin can sometimes break
off the end so this gives you a way to
recycle these otherwise broken leads to
use with your micro:bit.
You should modify a small number of your
jumper leads so you have the pin on one
end and around 4cm of bare wire at the
other to thread through a micro:bit pin.
Cut the jumper and strip around 4cm of
the shielding plastic from it. Then twist the
copper threads of the wire until they’re
firmly twisted together.
fig 2: Jumpers
Save the other part of the jumper, the
small pin plug may prove useful to attach
to something else, or if your jumper is long
enough, cut it in the middle and you can
make two leads from one.
Make music on the micro:bit - Maplin
4
Connecting headphones
If you’d rather connect a pair of
headphones, it’s done in exactly the same
way as we connected the speaker to the
micro:bit. Choose an old pair of
headphones, even one where only one
side works will be fine, ideally they won’t
have any extra controls like volume on the
wires.
Cut off the jack plug, split the two wires
and bare off the ends - you will probably
find these wires are very thin so use care
when stripping.
If you have some crocodile clips you may
find these useful for holding this type of
wire, which (depending on what they are
made of) sometimes even want to resist
solder flow.
fig 3: Preparing headphone wires
Connectivity tip: Using an edge connector
As you may have found, wrapping wires
round the micro:bit’s pin terminals can be
tricky. A much easier and enjoyable way
to prototype with a micro:bit is using an
edge connector - a socket type device
that you plug the micro:bit into. This then
gives access to the full range of pins
available via reliable header pin
connection. We strongly recommend the
use of an edge connector when
prototyping with a micro:bit. They are
available as a build it yourself kit - which
can be quite tricky if you have little
experience soldering, but the better
option is the ready built model that comes
ready to use from the pack.
The micro:bit, when used with an edge
connector, has 21 pins available for your
projects, including the 3V power and GND
connections. The non-power pins can be
used for input and output operations,
however some of them are also
connected to the internal hardware
features of the board.
fig 4: Pre-built micro:bit edge connector (by Kitronik)
Maplin Order Code: A81UQ
fig 5: micro:bit pin reference
Make music on the micro:bit - Maplin
5
Your first micro:tune
Load up a new window ready to program
with the MicroPython editor. While it can
look a bit daunting compared to block
programming, you should be able to copy
and modify the program below to make
your micro:bit music come to life.
There are lots of reference guides for
MicroPython in general and they will
cover the .play() command in much more
detail than here, this guide merely aims to
get you making music as quickly as
possible
Basic example MicroPython music program
import music
testMelody = ["C4:4", "D4:4", "E4:4", "F4:4", "G4:4"]
music.play(testMelody)
G4:4?
The letters in this program tell the micro:bit what note to play.
So G4:4 decoded simply means... G(4th octave):(for 4 beats)
Refining your code
This booklet just gives a taster of what you can do and are is not meant to take the part
of proper programming reference, it is however worth noting some MicroPython
features here when it comes to music.
When writing musical
notes in this format,
it’s only necessary to
add the octave and
the beat duration if
it’s different to the
last note, that means
we could rewrite the
code above with
identical results but
in a more readable
and shorter form.
Shortened example
import music
testMelody = ["C4:4", "D", "E", "F", "G"]
music.play(testMelody)
This example shows a shorter, but identical version of the
tune above. It’s only necessary to call the octave and note
length if it differs from the previous note.
Experiment with your own compositions and see if you can put toghether a tune that you
know, once you get the hang of writing the code you’ll see that you can very quickly lay
down tunes for your micro:bit.
Plik z chomika:
Automan1964
Inne pliki z tego folderu:
microprocessor interfacing techniques.pdf
(109882 KB)
Beginning BBC micro bit.pdf
(25106 KB)
252630.pdf
(16622 KB)
networking_with_the_microbit.pdf
(12857 KB)
MicrobitLessonfull_withLessondividers.pdf
(22241 KB)
Inne foldery tego chomika:
00 - Raspberry Pi
01 - Esp8266
02 - Arduino
02 - Arduino2
03 - Electronica
Zgłoś jeśli
naruszono regulamin