Waveshare Alphabot2 User manual

Alphabot2 for micro:bit User Manual
1/ 76
Alphabot2 for micro:bit
User Manual

Alphabot2 for micro:bit User Manual
2/ 76
CONTENT
Preface .......................................................................................................................................................... 5
micro:bit............................................................................................................................................... 5
Notes..................................................................................................................................................... 6
Chapter 1 LED lights................................................................................................................................. 8
JavaScript Blocks editor.................................................................................................................. 8
Blocks............................................................................................................................................ 9
Lighting LEDs ...........................................................................................................................10
Heart Beating ...................................................................................................................................13
Display Text.......................................................................................................................................14
Chapter 2 Buttons...................................................................................................................................15
Pressing..............................................................................................................................................15
Pressing 2 ..........................................................................................................................................16
Chapter 3 Sensors...................................................................................................................................18
Temperature Sensor ......................................................................................................................18
Accelerometer..................................................................................................................................19
Magnetometer.................................................................................................................................21
Light sensor ......................................................................................................................................23
Chapter 4 Music.......................................................................................................................................25
Play a melody...................................................................................................................................26

Alphabot2 for micro:bit User Manual
3/ 76
Play Piano ..........................................................................................................................................27
Play melody 2...................................................................................................................................28
Chapter 5 RGB LED.................................................................................................................................29
Add package.....................................................................................................................................30
Lighting ..............................................................................................................................................31
Display different Colors................................................................................................................32
Blinky LEDs........................................................................................................................................33
Rainbow .............................................................................................................................................34
Chapter 6 Moving, Robot.....................................................................................................................35
Add Pakcage.....................................................................................................................................36
Motors ................................................................................................................................................37
Moving ...............................................................................................................................................38
Moving 2............................................................................................................................................40
Moving 3............................................................................................................................................41
Chapter 7 Infrared Obstacle Avoiding.............................................................................................42
Infared Sensor Status ....................................................................................................................43
Obstacle Avoiding ..........................................................................................................................44
Chapter 8 Bluetooth...............................................................................................................................45
Add Package.....................................................................................................................................45
Bluetooth Connetion .....................................................................................................................46

Alphabot2 for micro:bit User Manual
4/ 76
Bluetooth Connecting 2 ...............................................................................................................51
D-Pad controller..............................................................................................................................53
D-PAD Controller 2 ........................................................................................................................55
Chapter 9 2.4g Radio .............................................................................................................................56
Add Package.....................................................................................................................................56
radio communicating ....................................................................................................................56
Joystick for micro:bit .....................................................................................................................58
Joystick for micro:bit 2..................................................................................................................62
Posture control................................................................................................................................64
Chapter 10 Ultrasonic Obstacle Avoidancing ...............................................................................66
Ultrasonic sensor ............................................................................................................................67
Obstacle Avoiding ..........................................................................................................................68
Chapter 11 Line Tracking......................................................................................................................69
Tracker sensor..................................................................................................................................70
Original data.....................................................................................................................................71
Calibrated Data................................................................................................................................74
Tracking..............................................................................................................................................76

Alphabot2 for micro:bit User Manual
5/ 76
PREFACE
This Alphabot2 robot kit uses the BBC micro: bit as the host controller, combined
with several functional modules, it is easy for the kids to experience robotic tricks such
as line tracking, obstacle avoiding, ultrasonic ranging, servo operation, Bluetooth
remote control, etc.
MICRO:BIT
The BBC micro: bit is a pocket-sized computer to learn programming for kids and
beginners
⚫Nordic nRF51822
◼16 MHz 32-bit ARM Cortex-M0 microcontroller
◼Bluetooth® 4.0 low energy/2.4GHz RF SoC
◼16kB RAM
◼256kB Flash
⚫Freescale KL26Z –48 MHz ARM Cortex-M0+ MCU
⚫Compass –Freescale MAG3110 3-axis magnetometer, I2C interface
⚫Accelerometer –Freescale MMA8652 3-axis accelerometer, I2C interface
⚫Power connector –3V power supply
⚫Reset button –reset the system
⚫Micro USB connector –for connecting PC, download code, serial communication,
etc.

Alphabot2 for micro:bit User Manual
6/ 76
⚫5x5 LED display –5x5 LED grid
⚫Button A/B –programmable buttons
⚫I/O connection pins –5 I/O rings and 20-pin edge connector, including SPI,
UART, I2C, Analog, PWM, etc.
⚫Dimensions –5cm x 4cm
NOTES
1. Components in different package will be different. In this guide, we describe all
components, and some of them may not be included in the package you buy.
2. The use manual, schematic, demo code and datasheet, all these resources can be
downloaded in Wiki.
➢https://www.waveshare.com/wiki/AlphaBot2_for_micro:bit
3. There may be mistakes in this guide due to the limit of time. If you find them,
please kindly contact Waveshare Team.
1
4. To avoid of destroying the Alphabot2, we recommend you read this manual and
following it if you are the first time receive your parcel.
5. Please check your parcel when you receive to check if all the components your
bought are included. We recommend you to first learn how to use the micro: bit
by following Chapter 1 to Chapter 3 if you are the beginner.
1

Alphabot2 for micro:bit User Manual
7/ 76
6. You must turn on the power switch and make sure the battery supplies power
normally before you connect USB cable to micro:bit for programming. You cannot
power Alphabot2 by micro:bit, otherwise the power LED's light is very slight and
Alphabot2 will work improperly.
7. You must turn off power before you plug/pull micro:bit, to avoid of destroying
micro:bit. And please keep the LED matrix of micro:bit towards to outside.
8. All the demo codes mentioned here are provided in Wiki. Demo codes are based
on make code programming environment of Microsoft. The makecode tool
supports Graphic programming and JavaScript. The demo codes are all hex files,
can be copied to micro:bit directly and run. (The micro:bit is recognized as a
potable drive when connected to PC. Flashing demo code to micro:bit by copied
hex file to this drive). You can also import demo code to miscode website for
modifying and flashing.
9. All specifications and demo codes supplied herein are subject to change without
notice at any time.

Alphabot2 for micro:bit User Manual
8/ 76
CHAPTER 1 LED LIGHTS
The micro:bit has 25 (5x5) individually-programmable LEDs, allowing you to
display text, numbers and images, here we will learn about coding these LEDs.
JAVASCRIPT BLOCKS EDITOR
The link of online JavaScript Block Editor of BBC: https://makecode.microbit.org/#
Accessing the editor. There is divided to four area, the upper area is menu bar, center
area is Blocks, left is simulating demonstration area and the right is Blocks and
JavaScript editing area.

Alphabot2 for micro:bit User Manual
9/ 76
BLOCKS
Blocks in Basic are mainly used for basic operation like LEDs controlling.
: Run the code at the beginning
: Repeat the code forever at the background

Alphabot2 for micro:bit User Manual
10 / 76
: Draw an image on the LED screen (LEDs)
: Scroll a number on the LEDs
: Display text on the LEDs, display one
character at a time.
: Draw selected icon on the LEDs
: Turn off all LEDs
: Draw an arrow on the LEDs
LIGHTING LEDS
Connecting the micro:bit to computer via a micro USB cable, the micro:bit will show
up on your computer as a drive called “MICROBIT”.
Now let’s start our first code that to light the LEDs with the blocks we describe
above. Just as below:

Alphabot2 for micro:bit User Manual
11 / 76
Click the LED to make them light on, you can see that the LEDs of simulated micro:bit
light on as the codes.
Click Download to download the code to the drive of micro:bit. You can also save the
HEX file to another place, and then copy to micro:bit instead of directly download to
micro:bit.

Alphabot2 for micro:bit User Manual
12 / 76

Alphabot2 for micro:bit User Manual
13 / 76
HEART BEATING
This code, we use block show icon, first display big heart icon then the small heart.
Repeat the code and it looks like heart beating. Let’s do it.

Alphabot2 for micro:bit User Manual
14 / 76
DISPLAY TEXT
Here we use show string block to display text “Hello!” on LEDs. The text will scroll
on LEDs character by character.
【Tips】
To delete the blocks, you can right click and delete it or just drag it to the left side.

Alphabot2 for micro:bit User Manual
15 / 76
CHAPTER 2 BUTTONS
There are two programmable buttons on the front of the micro:bit, which are labelled
A and B. In this chapter, we will code with these buttons.
PRESSING
Blocks we use in this section are included in Input package. With this block, if A or B
buttons on your micro:bit are pressed, codes are executed.
Coding the buttons to display characters, A when button A is pressed, B when button
B is pressed, and C when both buttons are pressed.
1. We create a new project, place on button pressed block to run codes when button
A, button B or buttons A+B are pressed separately.

Alphabot2 for micro:bit User Manual
16 / 76
2. Place show string block in on button pressed block to display string on LEDs
display. Duplicate and complete the script to as below:
3. Connect your micro:bit to PC, click Download to flash the code to your board.
Press buttons on micro:bit to test if expected string is displayed.
PRESSING 2
There is another way to detect buttons. In last section, codes are run when button is
pressed, here we use if then and button is pressed blocks to do the same thing.
Instead of running code directly, a Boolean value
2
“true” is returned if button is
pressed, “false” if button is not be pressed.
2
Boolean value: True or False

Alphabot2 for micro:bit User Manual
17 / 76
if then block is in Logic package, button is pressed block is in Input package.
1. Place if then block on forever, then put button is pressed block on it.
2. Place show string block, then clock ⊕icon to complete the codes as below:
3. Connect your micro:bit to PC, click Download to flash the code to your board.
Press buttons on micro:bit to test if expected string is displayed.
【Tips】
Some users may notice that in this script, A+B are detected first instead of A or B. You
can try to change the detect order to see what will happen.

Alphabot2 for micro:bit User Manual
18 / 76
CHAPTER 3 SENSORS
Micro:bit integrates Temperature sensor, Accelerometer, Compass and so on. In this
chapter, we learn to use these sensors.
TEMPERATURE SENSOR
This sensor allows the micro:bit to detect the current ambient temperature in degree
Celsius. It is embedded in the main chip nrf51822, which is used to detect the
temperature of chip in fact. Even temperature of chip is a little different with ambient
temperature, but we can use it to get an approximate value.
In Input package, temperature (°C) block is there. Combine with show number block,
we can show the ambient temperature in your room on LEDs display.
1. Place show number block on forever.
2. Place the temperature (°C) blocks

Alphabot2 for micro:bit User Manual
19 / 76
3. Add one pause (ms) for delay.
4. Download the code to your micro:bit, touch the CPU ( the main chip) for a
moment, you will find the temperature became higher.
ACCELEROMETER
The accelerometer MMA8652 is integrated on the left bottom of micro:bit
.
Acceleration is a trend to move. If we apply a force to an object in one direction, then
the object will trend to move in the direction, we call this trend the acceleration. For
example, we are being applied gravity all the time, if there is not any holder under our

Alphabot2 for micro:bit User Manual
20 / 76
feet, we will free-fall. It is that we have a trend to falling, which is called the
acceleration of gravity written as g in formulas.
We measure coordinate of x, y and z directions. With these three values, we could get
the direction of accelerations. If there is only acceleration of gravity, the direction is
downward. We keep measuring values of x, y and z coordinates to get the acceleration
of micro:bit, and detect actions like shake, tilt and so on
1. Place on blocks, choose the action
2. Place show arrow block choose the arrow
Table of contents
Other Waveshare Robotics manuals