micro:bit

Hmmm… Happened to get this chance of playing with micro:bit for fun, then take this opportunity to write a blog. It seems this BBC products is very convenient. Let’s just plug and play.

1. Introduction

1.1 lsusb

Just plug in and lsusb.

1
2
3
......
Bus 001 Device 008: ID 0d28:0204 NXP LPC1768
......

1.2 Hardware Specification

Refer to micro:bit Hardware Specification

1.3 User Guide Overview

Refer to micro:bit User Guide Overview

2. Tutorials and Configurations

Since I’m NOT a professional Makecode coder, I’ll run a couple of simple micro:bit projects using either Python or C/C++.

😓 😌

3. Display Hellow World Using micro:bit MicroPython

3.1 Required Configuration on Your Host

Please refer to micro:bit MicroPython Installation

1
2
3
4
5
$ sudo add-apt-repository -y ppa:team-gcc-arm-embedded
$ sudo add-apt-repository -y ppa:pmiller-opensource/ppa
$ sudo apt-get update
$ sudo apt-get install gcc-arm-none-eabi srecord libssl-dev
$ pip3 install yotta

and now ,let’s check yotta.

1
2
3
4
5
6
7
8
9
10
11
12
  ✔  pip show yotta 
 ~
Name: yotta
Version: 0.20.5
Summary: Re-usable components for embedded software.
Home-page: https://github.com/ARMmbed/yotta
Author: James Crosby
Author-email: James.Crosby@arm.com
License: Apache-2.0
Location: /home/longervision/.local/lib/python3.6/site-packages
Requires: jsonschema, PyJWT, PyGithub, mbed-test-wrapper, Jinja2, valinor, requests, intelhex, jsonpointer, hgapi, colorama, argcomplete, semantic-version, cryptography, pathlib, certifi
Required-by:

3.2 Connect micro:bit

Please refer to micro:bit MicroPython Dev Guide REPL, and now let’s connect micro:bit using picocom.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 12  ✔  sudo picocom /dev/ttyACM0 -b 115200                                                             ~ 
picocom v2.2

port is : /dev/ttyACM0
flowcontrol : none
baudrate is : 115200
parity is : none
databits are : 8
stopbits are : 1
escape is : C-a
local echo is : no
noinit is : no
noreset is : no
nolock is : no
send_cmd is : sz -vv
receive_cmd is : rz -vv -E
imap is :
omap is :
emap is : crcrlf,delbs,

Type [C-a] [C-h] to see available commands

Terminal ready

*** Picocom commands (all prefixed by [C-a])

*** [C-x] : Exit picocom
*** [C-q] : Exit without reseting serial port
*** [C-b] : Set baudrate
*** [C-u] : Increase baudrate (baud-up)
*** [C-d] : Decrease baudrate (baud-down)
*** [C-i] : Change number of databits
*** [C-j] : Change number of stopbits
*** [C-f] : Change flow-control mode
*** [C-y] : Change parity mode
*** [C-p] : Pulse DTR
*** [C-t] : Toggle DTR
*** [C-|] : Send break
*** [C-c] : Toggle local echo
*** [C-s] : Send file
*** [C-r] : Receive file
*** [C-v] : Show port settings
*** [C-h] : Show this message

Oh, my god… why can’t I just code directly here from within the console??? That’s ABSOLUTELY NOT my style.

3.3 Code & Run

The VERY FIRST demo is ALWAYS displaying Hello World. To fulfill this task, please refer to How do I transfer my code onto the micro:bit via USB.

As mentioned above, the UNACCEPTABLE thing is: it seems we have to use micro:bit Python IDE for python coding for micro:bit??? Anyway, my generated HEX of Hello World is here.

4. Flash Lancaster microbit-samples Using Yotta

Please strictly follow Lancaster University micro:bit Yotta.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 141  ✔  cd microbit-samples/
142   master  ✔  ls
debugOnVisualStudioCode.gif* LICENSE* module.json* README.md* source/
143   master  ✔  yt target bbc-microbit-classic-gcc
info: get versions for bbc-microbit-classic-gcc
info: download bbc-microbit-classic-gcc@0.2.3 from the public module registry
info: get versions for mbed-gcc
info: download mbed-gcc@0.1.3 from the public module registry
144   master  ✔  yt build
info: get versions for microbit
info: download microbit@v2.1.1 from GitHub lancaster-university/microbit
info: get versions for microbit-dal
info: download microbit-dal@v2.1.1 from GitHub lancaster-university/microbit-dal
info: get versions for mbed-classic
info: download mbed-classic@microbit_hfclk+mb6 from GitHub lancaster-university/mbed-classic
info: get versions for ble
info: download ble@v2.5.0+mb3 from GitHub lancaster-university/BLE_API
info: get versions for ble-nrf51822
info: download ble-nrf51822@v2.5.0+mb7 from GitHub lancaster-university/nRF51822
info: get versions for nrf51-sdk
info: download nrf51-sdk@v2.2.0+mb4 from GitHub lancaster-university/nrf51-sdk
info: generate for target: bbc-microbit-classic-gcc 0.2.3 at ....../microbit-samples/yotta_targets/bbc-microbit-classic-gcc
CMake Deprecation Warning at CMakeLists.txt:16 (cmake_policy):
The OLD behavior for policy CMP0017 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.


CMake Deprecation Warning at /usr/local/share/cmake-3.17/Modules/CMakeForceCompiler.cmake:75 (message):
The CMAKE_FORCE_C_COMPILER macro is deprecated. Instead just set
CMAKE_C_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
....../microbit-samples/yotta_targets/mbed-gcc/CMake/toolchain.cmake:78 (cmake_force_c_compiler)
toolchain.cmake:8 (include)
/usr/local/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:93 (include)
CMakeLists.txt:76 (project)


CMake Deprecation Warning at /usr/local/share/cmake-3.17/Modules/CMakeForceCompiler.cmake:89 (message):
The CMAKE_FORCE_CXX_COMPILER macro is deprecated. Instead just set
CMAKE_CXX_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
....../microbit-samples/yotta_targets/mbed-gcc/CMake/toolchain.cmake:79 (cmake_force_cxx_compiler)
toolchain.cmake:8 (include)
/usr/local/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:93 (include)
CMakeLists.txt:76 (project)


GCC version is: 6.3.1
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/arm-none-eabi-gcc
suppressing warnings from ble-nrf51822
suppressing warnings from nrf51-sdk
suppressing ALL warnings from mbed-classic, ble, ble-nrf51822 & nrf51-sdk
-- Configuring done
-- Generating done
-- Build files have been written to: ....../microbit-samples/build/bbc-microbit-classic-gcc
[112/172] Building CXX object ym/microbit-dal/source/CMakeFiles/microbit-dal.dir/core/MicroBitHeapAllocator.cpp.o
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitHeapAllocator.cpp: In function 'void free(void*)':
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitHeapAllocator.cpp:342:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (*cb == 0 || *cb & MICROBIT_HEAP_BLOCK_FREE)
^~
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitHeapAllocator.cpp:345:10: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
*cb |= MICROBIT_HEAP_BLOCK_FREE;
^
[120/172] Building CXX object ym/microbit-dal/source/CMakeFiles/microbit-dal.dir/core/MicroBitFiber.cpp.o
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitFiber.cpp: In function 'void scheduler_init(EventModel&)':
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitFiber.cpp:189:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (fiber_scheduler_running())
^~
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitFiber.cpp:194:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
messageBus = &_messageBus;
^~~~~~~~~~
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitFiber.cpp: In function 'int fiber_wait_for_event(uint16_t, uint16_t)':
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitFiber.cpp:388:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(ret == MICROBIT_OK)
^~
....../microbit-samples/yotta_modules/microbit-dal/source/core/MicroBitFiber.cpp:391:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
return ret;
^~~~~~
[159/172] Building CXX object ym/microbit-dal/source/CMakeFiles/microbit-dal.dir/bluetooth/MicroBitIOPinService.cpp.o
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp: In member function 'void MicroBitIOPinService::onDataWritten(const GattWriteCallbackParams*)':
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:179:42: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[i].getDigitalValue();
~~~~~~~~~~~~~~~~~~~~~~~~~^~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:182:41: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[i].getAnalogValue();
~~~~~~~~~~~~~~~~~~~~~~~~^~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:199:41: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[i].getDigitalValue();
~~~~~~~~~~~~~~~~~~~~~~~~~^~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:202:40: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[i].getAnalogValue();
~~~~~~~~~~~~~~~~~~~~~~~~^~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:224:43: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[pin].setAnalogValue(value);
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:225:46: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[pin].setAnalogPeriodUs(period);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:245:51: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[data->pin].setDigitalValue(data->value);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:247:50: warning: array subscript is above array bounds [-Warray-bounds]
io.pin[data->pin].setAnalogValue(data->value == 255 ? 1023 : data->value << 2);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp: In member function 'void MicroBitIOPinService::updateBLEInputs(bool)':
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:136:50: warning: array subscript is above array bounds [-Warray-bounds]
value = io.pin[i].getDigitalValue();
~~~~~~~~~~~~~~~~~~~~~~~~~^~
....../microbit-samples/yotta_modules/microbit-dal/source/bluetooth/MicroBitIOPinService.cpp:138:49: warning: array subscript is above array bounds [-Warray-bounds]
value = io.pin[i].getAnalogValue() >> 2;
~~~~~~~~~~~~~~~~~~~~~~~~^~
[172/172] Linking CXX executable source/microbit-samples
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libstdc++_nano.a(atexit_arm.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libstdc++_nano.a(new_opv.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libstdc++_nano.a(del_opv.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libstdc++_nano.a(del_op.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libstdc++_nano.a(new_op.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/bin/ld: warning: /usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libstdc++_nano.a(new_handler.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
145   master  ✘  cp ./build/bbc-microbit-classic-gcc/source/microbit-samples-combined.hex /media/longervision/MICROBIT
146   master  ✔ 

5. Projects Field

Please refer to micro:bit Official Python Projects.