GettingStartCoding Mbits Re
GettingStartCoding Mbits Re
Mbits
The microcontroller learning board
for computing
Includes
20+
example code
+
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
Mbits :3
4: Mbits
Introduction to Mbits V2
Mbits :5
Getting start coding with Mbits
6: Mbits
Getting start coding with Mbits
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
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.1F Diode
+3V3 16
+3V3 +3V3 ESP-WROVER VCC VUSB
+3V3 100F
USB Mini B
MPU5060
6V3 27 D+
8 23 D+ 5
VLOGIC SCL
24 2k 2k D- 6 D-
0.1F 13 SDA 10k
VCC 27
0.1F RESET GND
9
AD0 1 38
0.1F 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.1F IO34 IO21 32
1k
0.1F 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.1F
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
RT8059
RGB LED
10k
4 3 249k 10F
2k2 5 V.IN LX
4 1 5
EN FB 5pF
1 10k
0.1F OPA344 GND
P10
P11
P12
P13
P14
P15
P16
P19
P20
P0
P4
P5
P6
P7
P1
P8
P9
P2
P3
3 2
MIC 10F
2 0.1F
10k 54k9
MIC 0.1F
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
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
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
Mbits : 11
Getting start coding with Mbits
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
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.
14 : Mbits
Getting start coding with Mbits
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.
Figure 2-5
Mbits : 15
Getting start coding with Mbits
16 : Mbits
Getting start coding with Mbits
Mbits : 17
Getting start coding with Mbits
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
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.
Mbits : 19
Getting start coding with Mbits
20 : Mbits
Getting start coding with Mbits
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
Mbits : 21
Getting start coding with Mbits
22 : Mbits
Getting start coding with Mbits
Mbits : 23
Getting start coding with Mbits
adjust volume
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.
24 : Mbits
Getting start coding with Mbits
Mbits : 25
Getting start coding with Mbits
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.
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.
28 : Mbits
Getting start coding with Mbits
Program 13-1 Reading sound detection example code Figure 4-5 The result of sound detection
on the microBlock’s Teminal
Mbits : 29
Getting start coding with Mbits
30 : Mbits
Getting start coding with Mbits
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.
32 : Mbits
Getting start coding with Mbits
Mbits : 33
Getting start coding with Mbits
34 : Mbits
Getting start coding with Mbits
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.
36 : Mbits
Getting start coding with Mbits
Mbits : 37
Getting start coding with Mbits
38 : Mbits
Getting start coding with Mbits
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.
Mbits : 39
Getting start coding with Mbits
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 :
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).
Figure 5-6 Illustrates the Dashboard for showing the temperature reading from Mbits V2 board
42 : Mbits
Getting start coding with Mbits
Mbits : 43
Getting start coding with Mbits
Figure 5-8 shows how to resize widgets in the microBlock IDE Dashboard.
44 : Mbits
Getting start coding with Mbits
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.
46 : Mbits
Getting start coding with Mbits
Mbits : 47