microbit-raspberrypi.pdf

(1708 KB) Pobierz
Raspberry Pi Learning Resources
rpf.io/learn
1
Getting started with the micro:bit
What you will learn
By following the ‘Getting started with the micro:bit’ resource, you will learn:
How to install mu on your Raspberry Pi
How to connect the micro:bit to your Raspberry Pi
How to push MicroPython programs from your Raspberry Pi to the micro:bit
What you will need
Hardware
As well as a Raspberry Pi with an SD card and the usual peripherals, you’ll
also need:
x1
x1
This learning resource is provided for free by the
Raspberry Pi Foundation
under a
Creative
Commons
licence. See more at
raspberrypi.org/resources
and
github.com/raspberrypilearning.
Raspberry Pi Learning Resources
rpf.io/learn
2
Getting started with the micro:bit
If you’re one of the thousands of schoolchildren across the UK to receive one of the
BBC’s amazing micro:bits, and you want to learn how you can send code to it from
your Raspberry Pi, then this resource will give you a quick and easy setup guide to
help you start exploring the micro:bit.
Downloading and installing mu
MicroPython is a small but very fast version of Python 3 that has been specially
designed to work on microcontrollers, such as those found on the micro:bit. To
start writing MicroPython code on your Raspberry Pi, it’s helpful to have an IDE
(Integrated Development Environment), to make things a little easier for you. Lucki-
ly, mu is an open-source editor specially designed for children, and can run on your
Raspberry Pi.
To install
mu,
you should follow the instructions in the software installation guide.
Once
mu
is installed, you can find it in
Menu>Programming>mu
A new window should open up that looks like this:
Raspberry Pi Learning Resources
rpf.io/learn
3
Plugging in your micro:bit
The micro:bit has a micro USB port that you can use to connect it to your
Raspberry Pi. This will provide a power and data connection.
Connect your Raspberry Pi to the micro:bit using a USB A-to-micro-B cable, as
shown below:
GPIO
DISPLAY
PWR IN
CAMERA
A/V
USB X2
ETHERNET
You’ll know that the micro:bit has connected to your Raspberry Pi, because a
dialogue box should pop up like the one below:
This dialogue box might pop up a few times while you’re playing with the micro:bit.
You can simply click on Cancel when it does.
USB X2
Raspberry Pi Learning Resources
rpf.io/learn
4
Using mu
The
mu
software has been designed with young learners in mind. It has a very
easy-to-use interface, and most of the menu items should be self-explanatory.
The
New
button will open a new file. In mu this is done in a new tab. Have a go
opening a few new files, and then closing them again.
The
Load
button is for opening existing code that you have written.
The
Save
button saves any work you have in the visible tab.
The
Flash
button will push your code onto the micro:bit. You’ll learn more about
this later on.
The
Repl
button opens an
interactive shell.
This is covered in the next section.
The
Zoom
buttons will alter the size of the text in the window.
The
Theme
button switches between
light
and
dark
themes. You can choose
your preference.
The
Help
button will open the Epiphany web browser and take you to the
help pages.
The
Quit
button will close mu.
Raspberry Pi Learning Resources
rpf.io/learn
5
Using the REPL
The
REPL
is an interactive shell, running on the micro:bit itself. Here you can write
code and instantly see it running on your micro:bit.
You can click in the
REPL
and start writing your code straight away.
Try the following two lines:
from
microbit
import
*
display.scroll('Woop,
woop')
Did you see the text scrolling across the LED matrix of the micro:bit? If not,
you can type the second line again to scroll the message a second time:
display.scroll('Woop,
woop')
The REPL is a great place to write single lines of code to test them out, but for
larger scripts, you’ll need to use files.
Zgłoś jeśli naruszono regulamin