0% found this document useful (0 votes)
20 views

GettingStartCoding Mbits Re

Uploaded by

ben nasr Nejib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

GettingStartCoding Mbits Re

Uploaded by

ben nasr Nejib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Getting start coding with

Mbits
The microcontroller learning board
for computing

Includes
20+
example code
+

Written by Kridsada Jaiyen, Thanachote Sripakdee


English translated by Chaiwat Limpornchitwilai www.inex.co.th
COPYRIGHTS AND TRADEMARKS
Copyright © 2022 by Innovative Experiment Co.,Ltd (INEX). All Rights Reserved. By obtaining
a printed copy of this documentation or software you agree that it is to be used exclusively
with Mbits V2 board and AX-Mbits activity board. Any other uses are not permitted and
may represent a violation of INEX copyrights, legally punishable according to Federal and
international copyright or intellectual property laws. Any duplication of this documentation
for commercial uses is expressly prohibited by INEX. Duplication for educational use, in whole
or in part, is permitted subject to the following conditions: the material is to be used solely in
conjunction with Mbits V2 microcontrollers and products, and the user may recover from the
student only the cost of duplication. Check with INEX for approval prior to duplicating any of
our documentation in part or whole for any other use.

DISCLAIMER OF LIABILITY
Innovative Experiment Co.,Ltd (INEX) is not responsible for special, incidental, or consequential
damages resulting from any breach of warranty, or under any legal theory, including lost
profits, downtime, goodwill, damage to or replacement of equipment or property, or any
costs of recovering, reprogramming, or reproducing any data stored in or used with INEX
products. INEX is also not responsible for any personal damage, including that to life and health,
resulting from use of any of our products. You take full responsibility for your microcontroller
application, no matter how life-threatening it may be.

ERRATA
While great effort is made to assure the accuracy of our texts, errors may still exist. Occasionally
an errata sheet with a list of known errors and corrections for a given text will be posted
on the related product page at www.inex.co.th. If you find an error, please send an email to
[email protected].

2: Mbits
Table of Contents
Chapter 1 Introduction to Mbits V2 the microcontroller
learning board for practical computing and IoT 5

1.1 Mbits story 5


1.2 Mbits V2 technical features 5
1.3 Components of Mbits V2 board 7

Chapter 2 microBlock IDE installation 11


2.1 Features 11
2.2 Getting start Mbits with microBlock IDE 13

Chapter 3 Basic I/O of Mbits 19


3.1 Using A and B button of Mbits board 20
3.2 Sound output 24

Chapter 4 Built-in sensor of Mbits 27


4.1 Temperature sensor 27
4.2 Microphone 28
4.3 Accelerometer sensor 30

Chapter 5 How to use microBlock IDE’s Dashboard 36


5.1 What is Dashboard ? 36
5.2 About Dashboard’s widget 37
5.3 Getting start microBlock IDE’s Dashboard with Mbits V2 39

Chapter 6 Introduction to AX-Mbits the I/O activity board


for Mbits V2 microcontroller board 46
6.1 Features of AX-Mbits 46

Mbits :3
4: Mbits
Introduction to Mbits V2

Chapter 1 the microcontroller learning


board for practical computing
and IoT

1.1 Mbits story


Mbits V2 is a tiny microcontroller board for computing education. Mbits is created by
a collaboration of Shenzhen Elecrow Limited from China, Innovative Experiment or INEX
and Artronshop from Thailand. The Mbits V2 board useESP32 the main microcontroller with
WiFi and Bluetooth connectivity. Shenzhen Elecrow collaborate with INEX to make the Mbits
V2 board under the hardware requirements that make use of the main microcontroller on
board that is ESP32 to be stable and maximized to support STEAM education and computing
learning especially for Thailand.
The development tool for this Mbits V2 board is mainly
using microPython program which corresponds to coding and
computing education. The recommended development tools is
microBlock IDE. It was developed by Artronshop which supports
block-based code development for beginners and microPython for
next level programming. It covers learning for coding, electronics,
automatic control, basic embedded systems and STEAM education.

1.2 Mbits V2 technical features


Hardware feature
• Tiny size microcontroller board 52 x 52 mm.
• ESP32 Wrover-B core microcontroller with 4MB SPI Flash memory and 8MB PSRAM.
• 2.4GHz wireless connectivity for both WiFi and Bluetooth with BLE 4.2
• 25 programmable RGB 3-color LED display, arranged in a 5x5 dot matrix
• A piezo speaker for driving various signal tones and music
• Sound detection circuit with a MEMS microphone.
• Equipped with a 3-axis accelerometer, used to detect acceleration, moving and tilt
• Two programmable push-button switches are available and identified as switches A and B.
• The inputoutput port connectors are edge connector type and not compatible with micro:bit.
• I2C bus pin for I/O extension
• RESET switch and an LED indicates the operating status.
• Connect with USB port via microUSB for downloading code and computer data commu-
nication
Software features
• Support the most popular IoT cloud server for making IoT projects.
• It can fully support the microPython programming development.
• Mbits V2 also support program development with C/C++ programming by Arduino IDE
which uses ESP-IDF as core compiler

Mbits :5
Getting start coding with Mbits

Figure 1-1 Mbits V2 hardware and software development cooperation

6: Mbits
Getting start coding with Mbits

Figure 1-2 Mbits V2 board layout

1.3 Components of Mbits V2 board


Figure 1-2 shows the various components of Mbits V2 microcontroller board. The
operation diagram of Mbits V2 is shown in Figure 1-3 and the complete schematic diagram
is shown in Figure 1-4. The main device is The ESP32 Wrover-B microcontroller module. It has
4MB Flash memory and an additional 8MB of PSRAM memory. It contains wireless commu-
nication circuits WiFi and Bluetooth 4.2. Supports in Bluetooth Low Energy or BLE.

Mbits V2 contains variety of communication bus includes 2-wire or I2C bus, the SPI
bus and the UART bus. Input/Output pf Mbits V2 provides both digital and analog input-
output ports and PWM. The Mbits V2 board widely used in the construction a wide variety of
projects from basic automation systems, toys, appliances, smart and automatically machine,
data acquisition system and wireless control via WiFi or BLE, or even control via the Internet
network.

Mbits :7
Getting start coding with Mbits

Figure 1-3 Mbits V2 operation diagram


The Mbits display is 25 programmable RGB 3 color LEDs arranged in a 5 x 5 dots
layout. It supports the display of text, numbers, symbols, lines, dots and 2D graphics with
programmatically selectable display colours.
Mbits drives sound through piezo speaker. It can drive signals in audio frequencies
including music notes
Mbits V2 has built-in some sensors. It consist of :
1. MPU6050 3-axis accelerometer sensor is used to detect the acceleration, tilt, fall
or movement of the board. It communicates with the ESP32 core microcontroller via the I2C
bus.
2. TMP75 temperature probe communicates with the ESP32 main microcontroller
via the I2C bus
3. A sound detection circuit using a microphone. The working result is a voltage
that varies with the loudness of the sound.

8: Mbits
Getting start coding with Mbits

+3V3

DI G DI G DI G DI G DI G

+V DO +V DO +V DO +V DO +V DO

+3V3 +3V3
DI G DI G DI G DI G DI G

+V DO +V DO +V DO +V DO +V DO
10k 10k

DI G DI G DI G DI G DI G
Button-A Button-B
P9 P8
+V DO +V DO +V DO +V DO +V DO

DI G DI G DI G DI G DI G

+V DO +V DO +V DO +V DO +V DO

DI G DI G DI G DI G DI G

+V DO +V DO +V DO +V DO +V DO
+3V3

+3V3
TMP75 2k2
8 x2 +3V3
7 A0 VCC +5V
6 A1 SCL 2
5 A2 SDA 1 +3V3
4 10k Schottky
GND 0.1F Diode
+3V3 16
+3V3 +3V3 ESP-WROVER VCC VUSB
+3V3 100F

USB Mini B
MPU5060
6V3 27 D+
8 23 D+ 5
VLOGIC SCL
24 2k 2k D- 6 D-
0.1F 13 SDA 10k
VCC 27
0.1F RESET GND
9
AD0 1 38
0.1F GND GND CH340G
11 2 VCC IO23 37
20 FSYNC 3 36
CPOUT ADDR EN IO22 1k
10 18 4 35 3
REGOUT GND Select IO36 TXD IO1 RxD
5 IO39 34 2
RxD IO3 TxD
6 33
0.1F IO34 IO21 32
1k
0.1F 7 IO35 13 DTR
NC
MPU5060 addr. select 8 IO32 31 BC817
IO19
(*default) Open 0x69 9 IO33 30 14 RTS 4
IO18 3V3 +3V3
Close 0x68 10 IO25 29
IO5
11 IO26 28 0.1F
NC 1k
12 IO27 27
NC
13 IO14 26 BC817
+3V3 IO4
14 IO12 25
IO0 (BSL) XI XO GND
15 GND 24
IO2 7 8 1
16 IO13 23
PIEZO IO15
17 22 XTAL
ADC1-3

SPEAKER IO9 IO8


18 IO10 21 12MHz
IO7
19 IO11 20 22pF
IO6
1k
GPIO26
+3V3 BC817
Power supply
GPIO39

10k (simplified circuit)


+3V3
+3V3 +5V +3V3
100
0.1F k 22H
Button-B
Button-A

RT8059
RGB LED

10k
4 3 249k 10F
2k2 5 V.IN LX
4 1 5
EN FB 5pF
1 10k
0.1F OPA344 GND
P10
P11
P12

P13
P14
P15
P16

P19
P20
P0

P4
P5
P6
P7

P1

P8
P9

P2
P3

3 2
MIC 10F
2 0.1F
10k 54k9
MIC 0.1F
GPIO13

GPIO25

GPIO27

GPIO34
GPIO35

GPIO32

GPIO36
GPIO14
GPIO12
GPIO15

GPIO33
GPIO18
GPIO19
GPIO23

GPIO21
GPIO22
ADC1-4

ADC1-5
GPIO5

GPIO4

GPIO2

+3V3
P-MOSFET 1A
SDA
ADC1-6
ADC1-7

ADC1-0

SCL
MISO
MOSI
SCK

- IN +
BATT.
Mbits 0 1 2 3V GND
V2.0 R220104

Figure 1-4 Mbits V2 schematic diagram

Mbits :9
Getting start coding with Mbits

Input and Output ports of Mbits V2 are assigned to edge connector. It consists of Main
pins 5 pins (3-I/O, +3.3V and GND. The I/O ports has 20 pins and were defined by P0 to P019
as following the Figure 1-5.

GND

GND

GND
I2C SDA GPIO22 P20
I2C SCL GPIO21 P19
3V3

3V3

3V3
GPIO2 P16
SPI MOSI GPIO23 P15
SPI MISO GPIO19 P14
SPI SCK GPIO18 P13

GPIO33 ADC1-5 P2

GPIO15 P12
GPIO12 P11
GPIO14 P10
ButtonA GPIO36 ADC1-0 P9
ButtonB GPIO4 P8

GPIO32 ADC1-4 P1

GPIO35 ADC1-7 P7
GPIO34 ADC1-6 P6
GPIO5 P5
GPIO27 P4

GPIO25 P0

RGB LED GPIO13 P3


Speaker GPIO26
Mic GPIO39 ADC1-3

Figure 1-5 Mbits V2 Input/Output port assignment at edge connector

10 : Mbits
About
Chapter 2 microBlock IDE
microBlock IDE is a development software for ESP32 microcontroller by drag and
drop blocks or coding in microPython.

Figure 2-1 microBlock IDE development software for ESP32 microcontroller work with all operating system

2.1 Features of microBlock IDE


microBlock IDE has interested features as follows :
• Upload programs as fast as 2 seconds.
• Automatically detect and connect the ESP32 microcontroller board (includes Mbits V2)
• There is a terminal window to check the operation easily.
• There is Auto Completion for helping coding.
• Easy to drive LED and music with standard coding block.
• Adding more function blocks in the program with Extensions.
• There is an automatic file saving. No problem with power outage and lost work files.
  • Convert code from block to microPython and able to edit code with microPython language.
  • There are both versions Offline by installation on the computer and Online through the
browser.

Mbits : 11
Getting start coding with Mbits

Open the web browser. Go to http://microblock.app

Figture 2-2 microBlock IDE website


The homepage will introduce about features. Click Download button for downloading it.

Figure 2-3 microBlock IDE download webpage

After getting the installation file, double click for starting the installation. Please wait until
the program installation is complete.

12 : Mbits
Getting start coding with Mbits

2.2 Getting start coding for Mbits with microBlock IDE


When running the microBlock IDE for the first time The selected board to be used
may be another microcontroller board. Choosing the Mbits board this is done by creating
a new project.

Figure 2-4 The main windows of microBlock IDE


(1) At menu File select New for creating (3) Select icon of Mbits board then click
the new project. on the Create button in the bottom of
window.

(2) The program will ask for confirmation.


The current code will be lost after the new
project is created. Click on the Yes button.

Mbits : 13
Getting start coding with Mbits

(4) Connect the Mbits board with USB port of the computer.

(5) microBlock IDE will detect the hardware and connect the Mbits automatically and
show the status at the status bar at bottom of the main screen.

Mbits V2 board is now ready to code with the microBlock IDE.

14 : Mbits
Getting start coding with Mbits

{ Example 1 Messge scrolling }


It is simple stating code for beginner. It is a scrolling
text display at the LED RGB 5×5 dots by setting the color of
the LED as needed.

Scan QR Code to see result.

Note :
   For uploading code first time, system will
check the version of microPython firmware of
the Mbits board. If it is previous version or no
firmware, the Upgrade firmware windows will
Program 1-1 appear. Click on the Upgrade Firmware button.

(1) Drag the display show scroll block from menu


Display and drop on the working area. Change message and
color as coder want.

After firmware is upgraded complete, the


satisfaction window will appear.

Figure 2-5

(2) Once the code creating is satisfied, click on the


Upload button to send the code to Mbits following the Figure
2-5. Once the code is uploaded, the Mbits board will start
working immediately.

Mbits : 15
Getting start coding with Mbits

{ Example 2 Heart blinking }


The display show block is used to turn For this example will display large and
on the RGB 5×5 LED at any desired position small heart icons to perform alternately
with any color. The example display is show every 0.5 second. Result is LED RGB 5x5
in the Figure 2-6. dot flashing.

Scan QR Code to see result.

Figure 2-6 display show icon

    In the Tab Collection, there are more


already icons for helping user to save more
times for creating the graphic display follow-
ing the Program 2-1.

Program 2-1 Heart blinking example code

16 : Mbits
Getting start coding with Mbits

{ Example 3 LED single running }


In order for the LED RGB 5×5 dots turning on at the Result is LED RGB 5×5 dots
specified coordinates, there is a command block; display dot of Mbits turn on one by one
in the Display section. Set the x (0 to 4) and y (0 to 4) coordinates until they were complete.
of the LED 5x5 dots and choose the desired color as well. If would
like to turn off LED, must be able to set it to black following the
Figure 2-7.

Figure 2-7 Introduces the display dot block


Scan QR Code to see result.
To loop repeating a given interval, the count with block
(equivalent to the for statement) in the Control section is executed
this. It is used to loop and change variables to the specified value
following the Figure 2-8.

Figure 2-8 the display dot block details


When executed complete 1 cycle,
clear LED 5×5 dots with the display clear
block. The complete code is shown in the
Program 3-1.

Program 3-1 LED single running example code

Mbits : 17
Getting start coding with Mbits

{ Example 4 LED random }


Random number block Click on the block. the set variable block
is appeared. Set the variable name. For
example is X.
There are 3 new blocks as follows :
To randomize numbers, use the random
integer block in the Operators section to
return a random number in a given range.
Modifying the code in the Example 3, it is
a new program that allows the LED to turn for setting the value to the variable
on randomly.

Setting variable
In the section Variable, there is Create
Variable block for creating the variable to for increasing and decreasing the
reserve the memory area for data storage. variable value

it is the variable block.

Example code for LED random is show in


the Program 4-1.

Scan QR Code to see result.

Program 4-1 LED random example code

18 : Mbits
Basic I/O
Chapter 3 of Mbits
The Mbits V2 board is a complete board with integrated input and output devices
including LEDs, switches, microphones, speakers, temperature sensors and 3-axis
accelerometers.

Figure 3-1 Mbits V2 board layout and component

Mbits : 19
Getting start coding with Mbits

3.1 Using A and B button of Mbits board

activate when switch is pressed and


released

activate when switch is pressed

activate when switch is released

return “true” when switch is pressed

return “true” when switch is released

return “1” when switch is pressed


return “0” when switch is released

Figure 3-2 Swith A and B block for Mbits V2 of microBlock IDE

20 : Mbits
Getting start coding with Mbits

{ Example 5 Reading switch A and B of Mbits }


Create the short code for showing
the difference in the operation of the on
press and on pressed blocks. The code
is shown in the Program 5-1

Figure 3-3 switch on press and on pressed block


Program 5-1 on press block format

Scan QR Code to see result.


The result of on press block will occur
Program 5-1 on press example code when switch is pressed immediately

Program 5-2 on pressed block format

Scan QR Code to see result.

The result of on pressed block will occur


when switch is released only.
Program 5-2 on pressed example code

Return value of switch command blocks

Return “True” when switch is pressed Return “True” when switch is released Return “0” when switch is released
Return “False” when switch is released Return “False” when switch is pressed Return “1” when switch is pressed

Figure 3-4 Return value of switch command block description

Mbits : 21
Getting start coding with Mbits

{ { Example 6 countdown 60 seconds }


This example uses the wait until block to wait the
switch A of Mbits is pressed before execute the next com-
mand. It counts numeric values down from 59 to 0. Every 1
second it shows : (colon) in between the numbers.
When counting down is complete, Mbits will show
a heart icon and drive a sound out of the speaker.
The display show number block will show numbers
in short format. It causes Mbits can show 2-digit number on Scan QR Code to see result.
the LED 5x5 dot display.

Program 6-1 countdown 60 seconds example code

22 : Mbits
Getting start coding with Mbits

{ Example 7 Switch pressing monitor }


This example is demonstration of Mbits board’s switch pressing. The code will loop
to check the condition of pressing the switch.
If the switch A and B are pressed together, Mbits show the LED RGB 5×5 dots as all red.
If the switch A is pressed only, Mbits show the LED RGB 5×5 dots as all green.
If the switch B is pressed only, Mbits show the LED RGB 5×5 dots as all blue.
No any switch is pressed, Mbits clear all the LED RGB 5×5 dots.

Scan QR Code to see result.

Program 7-1 Mbits board’s switch pressing monitor example code

Mbits : 23
Getting start coding with Mbits

3.2 Sound output


Mbits V2 board has a piezo speaker for driving sound and melody from the Buzzer
blocks.

generate sound from setting the


frequency and duration time

generate sound from choosing the


melody note and beat

adjust volume

Figure 3-5 Buzzer command blocks

3.2.1 buzzer tone block

This command block is used for generating sound by setting the frequency in
Hertz (Hz) and duration time in second. The sound is driven by the on-board piezo speaker.
Frequencty response is 300 to 5000Hz.

{ Example 8 Randomize sound generator }


This example monitors the A switch pressing. If it is pressed,
Mbits will generate the sound continuous until the switch is
released. The sound frequencies are randomized in the range of
300 to 3000 Hz.
Scan QR Code to see result

Program 8-1 Randomize sound generator example code

24 : Mbits
Getting start coding with Mbits

{ Example 9 Driving sound from bass


to treble }
This example demonstrates about generate the sound
tone from bass to treble after the switch A is pressed. The highest
frequency is 3000Hz. After finish, the program loops back to wait
the switch pressing again. Scan QR Code to see result.

Program 9-1 Switch controlled tone generator

{ Example 10 Mbits Siren }


This example demonstrates about generate the siren
sound after the switch A is pressed. Program will repeat 10 times
for generating 2 frequencies alternating and drives out to speaker.
This sound is loud like siren sound.

Scan QR Code to see result.

Program 10-1 Mbits siren sound generator example code

Mbits : 25
Getting start coding with Mbits

3.2.2 buzzer note block

Figure 3-6 buzzer note block description


It is a command block used to produce sounds
similar the buzzer tone block. The different is setting Whole = 4 beats
parameters. This block requires the melody note and
rhythm of the sound as follows : White = 2 beats
• Scale : it is the name of a melody note that can
be defined in many notes in a single command and has a Quarter = 1 beat
Collection to retrieve sample songs to play and editable.
Developer can listen to the notes from the computer Eighth = 1/2 beat
before uploading to the Mbits board.
• duration : it is the amount of time you want Sixteenth = 1/4 beat
the music to play. There are 5 values.

{ Example 11 Play melody }


This example demonstrates about playing melody songs from
Collection. Program 11-1 plays 2 songs : Twinkle,Twinkle Little Star
and Jingle Bells from 9 songs. Playing is begin when the switch A or
B is pressed.
Scan QR Code to see result.

Program 11-1 Play melody example code

26 : Mbits
Built-in sensor
Chapter 4 of Mbits
Get to know and use the built-in 3 sensors of
the Mbits board : Temperature sensor, Microphone
and Accelerometer sensor.

4.1 Temperature sensor


Mbits V2 board has an ambient temperature
sensor. It senses temperature of the surrounding
environment in real-time. Figure 4-1 illustrates the
location of the temperature sensors on the back side
of the Mbits board. Figure 4-1 The temperature sensor on the
back side of the Mbits V2 board

{ Example 12 Temperature monitor }


This example demonstrates about measuring ambient temperature around the Mbits
board. The temperature value will show with 4 digit decimal points on the Terminal windows
of microBlock IDE and Mbits board's LED display every second

Program 12-1 Temperature monitor example code

Scan QR Code to see result.

Figure 4-2 The result of temperature sensing on the Teminal and


Mbits V2 board

Mbits : 27
Getting start coding with Mbits

4.2 Microphone

Figure 4-3 illustrates the microphone position on the front and back side of the Mbits V2 board

Mbits V2 board has a sound detection sensor as shown in the Figure 4-3. The micro-
phone with amplifier circuit is doing this function. The microphone converts the audio signal
to an electric signal and feeds it to the analog to digital converter (ADC) input of Mbits V2
boardt. The microBlock IDE has a command block for reading the sound signal data from ADC
and return with digital data in range 0 to 4095 as shown in the Figure 4-4.

Reading data from the block sound level


in range 0 to 4095

Figure 4-4 sound level block description

28 : Mbits
Getting start coding with Mbits

{ Example 13 Reading sound detection data }


When microphone detects the sound signal, data will
be changed following the sound level is changing. This example
demonstrates about read and show the sound level detection
on the Terminal of microBlock IDE.
Create the Program 13-1 and upload to Mbits board. See
the result with the Terminal window following the figure 4-5.
Scan QR Code to see result.

Program 13-1 Reading sound detection example code Figure 4-5 The result of sound detection
on the microBlock’s Teminal

{ Example 14 Sound controlled switch }


From the Example 13 result, the
normal sound detection data is 2500.
It is reference point data. The higher
sound level will gives higher data.
This example will use this condition to
turn on the Mbits board’s LED display.
Before driving the LED RGB 5×5 dots
on or off, need to check the previous
state first.
If the value is 0, means the current
state is off. Then turn on the LED to
shows the heart icon and set the state
value as 1.
If the value is 1, means the current
state is on, Then turn off the LED
following clear the value as 0 and
delay a short time for protection the
fluctuate status.
Create the code as shown in the
Program 14-1. Uploads to Mbits
board. Make a noise by clapping to
Scan QR Code to see result.
microphone on the Mbits board and
Program 14-1 Sound controlled switch example code see the result from Mbits board’s LED
display.

Mbits : 29
Getting start coding with Mbits

4.3 Accelerometer sensor


Mbits V2 has a 3-axis accelerometer
sensor; MPU6050. It is used for detection the
acceleration, tilt, shaking and dropping the
Mbits board. The accelerometer sensor is
soldered at the back of Mbits board as shown
in the Figure 4-6

Figure 4-6 illustrates the accelerometer sensor


location on the Mbits board.
The microBlock IDE prepare the command block for reading the acceleration in the
Input section following the Figure 4-7

execute when any event


is happened

condition is “true” when any


event is happened

return the acceleration


value of X, Y, Z axis and
Strength

return the pitch and roll value

return the gyro value in degree/second


of X, Y, Z axis and Strength

Figure 4-7 IMU command block description description

30 : Mbits
Getting start coding with Mbits

{ Example 15 Numerical Shaking }


This example demonstrates about number random from
shaking the Mbits board. Create the code following the Program
15-1. Use the display show 1-chars block for displaying full scale 1
digit number after shaking the board. The event On shake gesture
activates the random block for getting the number 1 to 9. Mbits
will show the number on its LED display.

Scan QR Code to see result.

Program 15-1 Mbits board’s Numerical Shaking example code

{ Example 16 Acceleration Gesture events }


Using the accelerometer sensor on the Mbits board can be done from acceleration
gesture. There are 11 events as shown in the Figure 4-8.

shaking the Mbits board

set the board up (refer the direction of the name


Mbits)
set the board down (refer the direction of the name
Mbits upside down)
face the board up

face the board down

tilt the board to left direction

tilt the board to right direction

drop the board to floor

cast the board with value of acceleration 3g

cast the board with value of acceleration 6g

cast the board with value of acceleration 8g

Figure 4-8 Description of Acceleration gesture events from the Mbits V2 board’s accelerometer sensor

Mbits : 31
Getting start coding with Mbits

Create the code following the Program 16-1. Upload to Mbits board.
Try to do any acceleration events such as shake, tilt, throw and drop the Mbits board.
See the result from Mbits board's LED display and listens the activated sound from Mbits
board's speaker. It is driven everytime that event is occurred.

Program 16-1 Acceleration testing example code

Scan QR Code to see result.

32 : Mbits
Getting start coding with Mbits

{ Example 17 Tilt controlled blinking LED }


This example demonstrates about using the acceleration to drives the blinking LED.
Mbits will get the acceleration data from sensor's detection. Then converts to LED coordinator
and drives LED to blinking.

Example code is shown in the Program 17-1. The result


data from acceleration block is between -1023 to 1023.
Then converts to only positive data by adding 1023. It causes
data range as 0 to 2046. Next, convert to X and Y axis coordinate
by dividing by 450 and use the round down block for setting to
integer number. The result is 0 to 4. Use this result to set the X and
Y axis coordinate then send to the display dot block for driving
LED on and off with 0.1 second delay time. It makes LED blinking
at the dot display by tilting the Mbits board. About LED’s color สแกน QR Code เพื่อดูผลลัพธ์
in this code is set as red. It is possible to change to another color
as needed.

Program 17-1 Tilt controlled blinking LED example code

Mbits : 33
Getting start coding with Mbits

{ Example 18 Finding Star game }


From the Example 17, adapt to make the simple game. The game start by setting the
target RGB LED and blinking red LED. Player must tilt the Mbits to moves the blinking red LED
to the target LED. When both LED position are same, Mbits board drives the beep signal and
send the score point to show on the Terminal window. The game is finish and restart to new
game suddenly.
The complete code is shawn in the Program 18-1. This code is modified from Example
17-1 code. Add the variables XX and YY for setting the target LED position and drive it on
without blink. While the finding LED will be set the position from the value of sensor’s acceler-
ation. The position is changed from tilting and makes LED as red color and blink. The code will
compare the position of target LED and the finding LED always. When they are same position,
it drives a sound signal with 2000 Hz frequency in
0.2 second then turn off all LED. Next, set the
new position of both LEDs for starting
new game. Increase the CNT
variable once and send to the
terminal.

Create the code of


Program 18-1 and upload
to Mbits board. Try to tilt
the board to move the
blinking red LED to meet
the target RGB LED. Have
fun !!

Scan QR Code to see result.

Program 18-1 Finding Star game example code

34 : Mbits
Getting start coding with Mbits

{ Example 19 Dice game }

Scan QR Code to see result.

This is popular game. The


example code is shown in the
Program 19-1. It runs under on
shake gesture event. The Mbits
will random the integer number
from 1 to 6 by the random in-
teger block then store in the
variable dice. The random is
occurred from shaking the Mbits
board. Program will check the
number if equal 1 it set the LED
display to show “one dot”, if equal
to 2 it show “two dot”. Do it like
this for complete 6 numbers. It
makes like an electronic dice.
Create the code in the
Program 19-1 with MakeCode
editor and Upload to Mbits board.
Try to shake the board and see
the result on LED display.

Program 19-1 Dice game example code

Mbits : 35
How to use
Chapter 5 microBlock Dashboard

The microBlock IDE version 2.1.0 and higher has a display window that call “Dashboard”
for displaying text, numerical data, the status of LEDs, gauges, graphs and other electrical
quantities. The Mbits V2 board connects to the Dashboard with serial data communication via
USB serial port. During the interaction, the computer must be connected to Mbits V2 board
at all times.

5.1 Introduction to microBlock Dashboard


Dashboard is a graphical display window that is very popular in modern development
software. Unlike the Terminal window that only displays text or numbers, the microBlock
IDE also packs this capability into the program. The main component of this tool is called as
Widgets.

Figure 5-1 The example dashboard in the microBlock IDE

36 : Mbits
Getting start coding with Mbits

5.2 About Dashboard widget


In the Toolbox, there are different 5.2.3 Gauge
widgets for using on the Dashboard. It can
be summarized as follows:         It is a widget to display the performance
in a gauge.
5.2.1 Text
      It is widget for displaying in text both
characters and numbers.

Name : Name of the widget


Source : Name of the data
Min : The minimum value that a gauge
Name : Name of the widget
can display.
Source : Name of the data
Max : The maximum value that a gauge
Unit : Unit of display can display.

5.2.2 Lamp 5.2.4 Chart


     It is a widget to display data in graphs
that show both the data value and time.

        It is widget for displaying thr lamp. It is


suitable for using with digital data.
• Data is “0”. Lamp is off.
• Data is “1”. Lamp is on.
Name : Name of the widget
Name : Name of the widget Source : Name of the data
Source : Name of the data Min : The minimum value that a graph
can display.
Max : The maximum value that a graph
can display.
Limit : The maximum amount of data
displayed on the graph.

Mbits : 37
Getting start coding with Mbits

5.2.5 Log 5.2.7 Game


It is a widget displaying a data set con-         It is minigame; Pong. Use the left and
taining data and time. right arrow key to control.

Name : Name of the widget


Source : Name of the data
  Limit : The maximum amount of data
to be displayed.
5.2.8 Compass
5.2.6 Aircraft    It is a compass display widget. Normally
it is used with the magnetic sensing module
       It is a widget displaying datasets in and electronic compass (recommended
a model plane format. Available is in LSM303 from STMicroelectronics).
microBlock IDE V2.2.0 and higher. Typically
this widget works with 3-axis accelerometer
sensor.

Name : Name of the widget


Source : Name of the data

Name : Name of the widget


Pitch : Set the pitch angle data
Roll : Set the roll angle data
     Heading : Set the amount data of
heading

38 : Mbits
Getting start coding with Mbits

5.3 Getting start microBlock Dashboard with Mbits V2


To use the Dashboard window, the code must be generated in the microBlock IDE
then uploaded to the Mbits V2 board first. Set the name and required information to send to
the dashboard display via USB serial port. The command block used is send to dashboard.

5.3.1 Command block for the microBlock Dashboard


The command block used to send data is send to dashboard block in the Advanced
toolbar under Dashboard menu.

This command block is used to send data for displaying on the Dashboard. It consist of :
1. Characters and numbers - Put this data after the send block command.
2. Name of Data - such as “Temp” or “Temperature_data” . It is the data from
temperature sensor. The data name must not contain spaces and not in Thai or other language.
Put this data into the “source1” block.

{ Example 20 Temperature display on the Dashboard }


This example will show the data values from the temperature sensor on Mbits board
that sent to display as characters on the Dashboard window. The steps are as follows.

Program 20-1 Mbits Temperature Dashboard example code


(1) Create the code from Program 20-1 and upload to the Mbits board.
(2) The next step is creates the Dashboard page. Click on the Dashboard menu at the
top right to open the Dashboard window.

Mbits : 39
Getting start coding with Mbits

(3) Dashboard window appears as


shown in Figure 5-2. In the first use, there is
no widget or any device. After connected the
Mbits board, it will show Connected in the
upper right corner. If disconnect is occurred,
please reconnect the USB cable to the Mbits
board before using the next step.

Figure 5-2 illustrate the Dashboard main window

5.3.2 Start with select, drag and drop widget


(1) Click on the Toolbox
(2) Click to select the widget of the desired tools.
(3) A widget will appear on the working area then select Text as in Figure 5-3.

Figure 5-3 Guidelines for selecting and drop widgets on the microBlock IDE Dashboard

40 : Mbits
Getting start coding with Mbits

(4) To present the data, the steps are as shown in Figure 5-4.
(4.1) Click on the gear-shaped button at the top right.
(4.2) A window for setting the Text widget appears. The properties to be set
are as follows :

Name is the name of the widget.


Source is the name of the data to be displayed.
Unit is the unit of displayed value, such as Celsius degree (C).

(4.3) Click to an empty area of Dashboard to close the widget settings.

Figure 5-4 Show the step of present the data to display on the Dashboard of the microBlock IDE

Mbits : 41
Getting start coding with Mbits

The result
Once the settings have been successfully, the temperature value will be displayed on
the widget named Temperature in C (Celsius).

Display the temperature data from


the Mbits V2 board that sent from
the send to dashboard block

Figure 5-6 Illustrates the Dashboard for showing the temperature reading from Mbits V2 board

42 : Mbits
Getting start coding with Mbits

5.3.3 Relocation of widgets


       Repositioning widgets or display devices on the Dashboard can be done by clicking and
holding the mouse at the top bar of the widget. Then drag and drop it to the desired position
as shown in Figure 5-7.

Click on the top bar of


the widget then drag and
drop it to desired position

Figure 5-7 shows a guide to relocation widgets in the Dashboard window

Mbits : 43
Getting start coding with Mbits

5.3.4 Scaling of widgets


Developers can resize the widgets on the Dashboard by clicking and holding the
mouse in the lower right corner of the widget and dragging it to the desired size as shown in
Figure 5-8.

Click and hold the mouse


button at the widget corner
then drag to the desired size

Figure 5-8 shows how to resize widgets in the microBlock IDE Dashboard.

44 : Mbits
Getting start coding with Mbits

5.3.5 Deleting widgets


Illustrate the steps as shown in Figure 5-9.
(1) Click on the gear shaped button at the top right of the widget which want to delete.
(2) Click on the Delete button to delete.

Figure 5-9 Illustrate deleting widgets in the Dashboard window of the microBlock IDE

Mbits : 45
Introduction to AX-Mbits
Chapter 6 the I/O activity board for
Mbits V2 microcontroller
board

AX-Mbits is one of the extension board to support the Mbits V2 microcontroller board.
It is eveloped and manufactured in Thailand by Thai engineers from Innovative Operations
Co., Ltd. (www.inex.co.th). This board is designed to help facilitate learning and use of Mbits
microcontroller board for learning computing and coding. Especially with supporting the
Mbits board to interface with the real world applications more comfortable.

Figure 6-1 Illustrate the components of the AX-Mbits extension board

6.1 Features of AX-Mbits


• There is a socket for plugging the Mbits board.
• There is a DC power jack and screw terminal block for 6 to 9V external adaptor or power
supply. Provides the 5V and +3.3V supply voltage from regulator circuit with reverse polarity
protection.
• 13 Input/Output port with JST connector.
• There is an I2C bus connector for connecting additional external devices.
•There are 4 servo motor connections. Connected with Mbits ports P10, P11, P12 and P16.
Use voltage from +5V power supply to supply the servo motor. Supports small servo motors
powered by 4.8 to 6V.
• There are two push button switches following Mbits V2's A and B switches.
• It has a variable resistor for experimenting with analog inputs. It adjust voltage 0 to +3V.

46 : Mbits
Getting start coding with Mbits

Figure 6-2 The schematic diagram of the AX-Mbits extension board.

Figure 6-3 Connection of Mbits V2 and AX-Mbits board

Mbits : 47

You might also like