This is only a preview of the March 2020 issue of Practical Electronics. You can view 0 of the 80 pages in the full issue. Articles in this series:
|
Make it with Micromite
Phil Boyce – hands on with the mighty PIC-powered, BASIC microcontroller
Part 14: Using Bluetooth to set your Micromite free
S
o far in this series, if you want
to interact with your Micromite
Keyring Computer (MKC) you have
to physically connect it (and the Development Module (DM)) to your computer with
a USB cable. Then, you run a terminal
application such as TeraTerm on your
computer. The terminal application acts
purely as a ‘console’ which provides the
Micromite with a screen (for output), and
a keyboard (for input). You can think of
this set-up as the Micromite being ‘USB
tethered’ to a screen and keyboard – see
Fig.1. Note that the physical length of the
USB cable, which for technical reasons
is usually no more than one metre, determines the maximum distance between
the Micromite and computer.
This month, we are going to show
you how to ‘set your Micromite free’ by
replacing the USB physical link with a
wireless link. Using Bluetooth technology
to create this wireless link, it becomes
possible to separate your Micromite and
computer from each other by up to 10m.
First though, why would you want to
use a wireless link instead of having the
Micromite tethered to within a metre of
your computer? Well, a wireless link opens
up all kinds of remote-control projects
and capabilities; for example:
Several sensors could be connected
to a Micromite, and assembled into a
waterproof enclosure that you locate
outdoors. Sensor data can then be
formatted in your Micromite code (with
PRINT commands and Escape codes –
see Part 8, September 2019) for display
on your computer screen, which is
located conveniently indoors.
A battery-powered robot-buggy could
be created that incorporates an on-board
Micromite. A Bluetooth link would
Questions? Please email Phil at:
contactus<at>micromite.org
Practical Electronics | March | 2020
Computer
Development Module (DM)
Console
Terminal app
3.3V
Reg
Screen
D+
Keyboard
COM x
USB cable tether
D−
USB
BoB
USB port
USB-to-serial
Tx
Rx
Rx
Tx
5V
3.3V
Reg
Micromite
Micromite Keyring Computer (MKC)
Fig.1. Using a USB cable to connect your MKC/DM to your computer results in them
being tethered together. Distance apart is limited by length of USB cable – typically no
more than 1m.
allow the robot to roam freely, totally
untethered; yet it can be fully controlled
from your computer’s keyboard. (A
Bluetooth-controlled robot-buggy will
be a future project).
You could modify any of your
existing projects to enable them to
be accessed remotely. For example,
adding Bluetooth to last month’s Mood
Light project means that it can remain
where you want it to be positioned,
while customising the code from the
comfort of your ‘remote’ computer.
Computer
These examples have probably inspired
you with some ideas for wireless
interaction with your Micromite. Let’s
get started by understanding the design
of this Bluetooth link.
Design concept
In Fig.1, you can see the familiar method
we have used so far in this series to
connect the MKC to the computer’s USB
port via the USB-to-serial module inside
the DM. Electrically, the USB-to-serial
module deals with the complex USB
Development Module (DM)
Console
Terminal app
3.3V
Reg
Screen
D+
Keyboard
COM x
USB port
D−
USB-to-serial
Tx
Rx
Serial link tether
5V
USB
BoB
USB
cable
USB
PSU
USB
BoB
Rx
3.3V
Reg
Tx
Micromite
Micromite Keyring Computer (MKC)
Fig.2. Rearranging the elements in Fig.1 results in a serial link tether. Theoretically, this
means the computer and Micromite can now be separated by more than 1m.
53
Computer
Development Module (DM)
Console
Terminal app
3.3V
Reg
USB-to-serial
Screen
D+
D−
5V
USB 5V
BoB
Keyboard
COM x
5V
USB
cable
USB port
Tx
Rx
Rx
Tx
Wireless
tether
Serial-towireless
Serial-towireless
USB
PSU
USB
BoB
3.3V
Reg
Tx
Rx
Rx
Tx
5V
Micromite
Micromite Keyring Computer (MKC)
Fig.3. Adding a pair of USB-to-wireless modules to Fig.2 allows for an untethered
wireless link between the computer and the Micromite.
protocol, and provides a much simpler
serial protocol that has two physical
connections: Transmit (Tx) and Receive
(Rx). These are the connections that the
Micromite serial console uses.
Now, without changing any connections,
let’s reposition the elements shown in Fig.1
to create Fig.2. This version highlights that
we’re using a ‘serial-link tether’ as opposed
to a ‘USB cable tether’. The important
point here is that a wired serial link is
much easier to convert into a wireless
link compared to converting a USB-tether
link. We do this by introducing a pair of
serial-to-wireless modules, one at either
end of the serial-link – see Fig.3.
Note that in this new layout, power
and connectivity to the DM require the
addition of a USB break-out-board (BoB)
at the computer end. This is because the
DM is no longer plugged into the MKC,
which is where it got these connections
previously. So, referring to Fig.2 and Fig.3,
you can see that by adding a USB BoB at
the computer end, the required power and
data signals (D+ and D−) can be routed
directly to the DM. At the Micromite end,
we just need to power the MKC from a 5V
STATUS
LED
USB power source.
That’s the theory; now a quick look at a
suitable serial-to-wireless module.
HC-05 Bluetooth module
The HC-05 is a low-cost Bluetooth serial-towireless module with all the functionality
we need (see Fig.4). For now, simply
consider a single HC-05 module as having
two interfaces: a serial interface (Tx-pin
and Rx-pin), and also a wireless Bluetooth
interface. In use, any serial data sent (from
an external device) to the HC-05’s receive
pin (Rx) is wirelessly transmitted via
Bluetooth (ideally to a paired Bluetooth
device). Likewise, any Bluetooth data
received by the HC-05 (from a paired
Bluetooth device) is sent out serially on
the transmit pin (Tx). Note that all of this
happens without us having to worry about
any of the technicalities of the Bluetooth
protocol.
Now consider having two HC-05s paired
to each other via Bluetooth – see Fig.5.
What the above translates into is that
any serial data sent to the Rx pin on the
left-hand HC05 is then automatically
outputted on the Tx pin of the right-hand
BUTTON
c)
d)
EN
VCC
TXD
GND
RXD
b)
STATE
a)
Fig.4. (a) Pinout of the HC-05 serial-to-Bluetooth module. Some have the button soldered
in place (b), and some don’t (c). Pins are labelled on the reverse of the module (d).
54
HC-05. Likewise, serial data received on
the Rx pin on the right-hand HC-05 is
automatically outputted from the Tx pin
on the left-hand HC-05. In effect, we have
created an untethered-wireless seriallink; and this is exactly what we need to
replace the hard-wired ‘serial-link tether’
(see Fig.2 and Fig.3).
Some of you with Bluetooth built into
your computer may be wondering why
we’re not using it at the ‘computer end’
of the wireless link, and therefore just use
a single HC-05 at the ‘Micromite end’.
You can indeed do this, but in practice
there are many potential complications,
such as: incompatible Bluetooth versions,
driver issues, drop-out problems, other
Bluetooth device(s) already paired to your
computer’s Bluetooth… and so on. In the
design presented here we will eliminate
all of these potential issues by simply
using a pair of low-cost HC-05 modules
that form a dedicated wireless link to
your Micromite.
HC-05 hardware overview
Referring to the diagram in Fig.4a, the
hardware elements of the HC-05 that we
need to concern ourselves with are the:
Six pins on a 0.1-inch single-row header
(discussed below)
Small red status LED (flashes at different
speeds to indicate various things –
useful during testing)
Miniature button (to put the unit into
configuration mode).
Note that not all HC-05 modules come with
the miniature button soldered into place
(but the two solder pads will always be
there – Fig.4c). If it is absent, use the two
solder-pads to connect a 2-way 0.1-inch
pin header, and use a jumper to mimic the
button being pressed (required when we
come to configure the HC-05 modules).
Turning to the six pins on the module:
EN is the enable input. If left
unconnected (as we are doing), or if
tied high (+V) it will allow the HC-05
to operate. If taken low (linked to GND),
the unit is disabled (and enters lowpower mode)
GND and VCC supply the required
power (3.6V to 6V)
TXD and RXD are the two serial-interface
pins
STATE is an output (active high) that
indicates successful connection status of
the Bluetooth module (a totally different
function to the small on-board red LED).
Notes regarding Bluetooth and
the HC-05
If you have used Bluetooth before you will
no doubt recognise terms such as: ‘master’,
‘slave’, ‘paired’, ‘bind’, and ‘passkey’.
Several of these terms will become relevant
when we initially create our Bluetooth link
Practical Electronics | March | 2020
If any of the above is unclear, please
don’t worry; we will cover most of
Practical Electronics | March | 2020
these points as we work
through the assembly
and configuration of the
Bluetooth link. After you
have finished reading this
article, do reread the above
list.
HC-05
HC-05
Tasks to implement
the Bluetooth link
EN
VCC
GND
TXD
RXD
STATE
EN
VCC
GND
TXD
STATE
In order to create the
wireless Bluetooth seriallink in Fig.5, we need to
configure one HC-05 as
a master, and the other
HC-05 as a slave. Then
we need to ensure that Fig.5. Using two HC-05 modules to create a wireless
we bind them together so Bluetooth serial-link; effectively replacing a wired serial link
that they automatically (represented by the dotted lines).
connect to each other.
Note that once they are both configured,
adaptors will require a 6-way socket to
it does not matter which HC-05 module
allow the HC-05 module to be plugged in.
in Fig.5 is the ‘master’, and which is the
In addition, we will use an LED on each
‘slave’. This is because the two modules
adaptor to show when the two Bluetooth
together form a two-way (duplex) serialmodules are connected to each other (this
link (Tx>Rx and Rx<Tx). Do not fall into
will prove very useful when the modules
the misconception that one module is a
are positioned in different locations).
‘transmitter’, and the other is a ‘receiver’
Everything else on each adaptor is just
– each is both.
the required pins and/or sockets, to make
To be able to configure the two HC-05
the relevant connections. Fig.6 shows the
modules in the first place, and then go
assembled adaptors.
on to physically use them with our DM
A really useful bonus (or rather, part
and MKC (as shown in Fig.3), we need to
of the design) is that the adaptor board at
work through the following sequence of
the computer end will also double up as
tasks, T1 to T9:
the HC-05 configuration unit. Let’s begin
T1 Build an HC-05 Bluetooth interface
with the first assembly task.
(with BoB) for the DM (computer end)
T2 Build an HC-05 Bluetooth interface
T1: HC-05 adaptor for the DM
for the MKC (Micromite end)
This adaptor is designed to be plugged
T3 If either HC-05 is without the miniature
into the DM (from above) and needs the
following specific requirements:
button, then add a jumper link
T4 Set terminal application settings to
n
Correctly positioned pins (downward
facing) allowing the adaptor to be
HC-05 requirements
plugged into the DM.
T5 Configure one HC-05 as a slave
T6 Configure the other HC-05 as a master
n
A socket for the HC-05 module. This
is just a 6-way socket and allows
T7 Set terminal application settings back
easy insertion, and removal, of an
to Micromite requirements
HC-05 (especially useful during the
T8 Plug everything together
configuration process).
T9 Test the wireless Bluetooth link
n
An LED and current-limiting resistor,
which indicates that the HC-05 has
Keeping the hardware simple
successfully connected (via Bluetooth)
Looking through the list above, you will
to the other HC-05 module at the
see that only the first three tasks involve
Micromite end. Since we are creating
any hardware construction – the rest is
a Bluetooth link, we will use a blue
configuration and testing. Referring back
LED (you can use any colour, but do
to Fig.3, you can see that the serial-touse the appropriate resistor value)
wireless module (HC-05) at the computer
end connects directly to the USB-to-serial
n
A USB socket – this allows connection
module (in the DM). Likewise, the HC-05
to the computer and is required because
at the Micromite end connects directly to
the DM does not have its own USB
the MKC. So to keep the theme of ‘simple
socket. We will use a USB BoB identical
plug-in modules’ for the MKC and DM,
to the one used in the MKC (see Fig.3).
and also to keep construction to the bare
minimum, we only need to assemble two
You can see from the schematic (Fig.7)
straightforward adaptor boards: one for
that there is nothing complex – it’s just a
the computer end that plugs into the
matter of making the required connections
DM (T1); and another for the Micromite
between the USB BoB, the HC-05, the
end that plugs into the MKC (T2). Both
LED, and the DM (as outlined in Fig.3).
RXD
because they are part of the configuration
that we will need to perform. Before
we discuss the configuration in detail,
there are several points that we need to
highlight regarding Bluetooth and the
HC-05 module:
n
Bluetooth is a one-to-one wireless link
that connects two devices
n
To form a Bluetooth link, one end must
be the ‘master’ Bluetooth device, and
the other must be the ‘slave’ Bluetooth
device. This means that two masters
will not connect to each other, nor will
two slaves
n
For a master and a slave to connect
to each other, they need to have the
same ‘passkey’ (sometimes referred to
as ‘passphrase’, or ‘password’)
n
When two devices are communicating
with each other via Bluetooth, they
are regarded as being ‘connected’ and
‘paired’. No other device can join in the
communication (remember, Bluetooth
is a one-to-one connection)
n
The HC-05 has two modes of operation:
‘configuration’ (also known as AT
mode), and ‘communication’ (also
known as Data mode)
n
In configuration mode, there are several
settings that can be altered. These
settings ultimately affect how the HC-05
behaves when in Data mode
n
To enter configuration mode, the HC-05
module is powered up while pressing
the module’s button (or shorting the
link on modules without a button)
n
Configuration settings are sent to the
HC-05 via the serial link (Rx and Tx
pins) at a fixed baud rate of 38,400
n
Configuration settings can be sent to the
HC-05 from any terminal application,
such as TeraTerm (use the same terminal
app you currently use when connecting
to the Micromite via the DM)
n
To configure a setting, use the format:
AT+setting_name=value (this is why
configuration mode is also referred to
as ‘AT mode’)
n
To interrogate a setting’s current value,
use the format: AT+setting_name?
n
All settings on the HC-05 are stored in
Flash memory. This means that they
will be remembered even when the
HC-05 is powered off
n
Settings only need to be set up once;
when all settings have been configured
correctly, the HC-05 only needs to be
used in Data (communication) mode
n
However, any setting(s) can be changed
at any time by re-entering configuration
mode
n
Two correctly configured HC-05 modules
can be made to automatically pair with
each other (by ‘binding’ the master to
the address of the slave).
55
Fig.6. (left) The completed adaptors: note here that the buttons are not in place on the
HC-05 modules and hence one horizontal, and one vertical 2-way pin header has been
added onto each HC-05. (right) The adaptors in use: the one with the USB BoB plugs
into the DM, and the other adaptor with the 3-way IR socket plugs into the MKC.
The USB socket (on the USB BoB) has
five pins broken out onto a 0.1-inch header
– although only four are used. The outer
two pins supply 5V power to the HC-05
module and the DM. Two other pins from
the BoB (D+ and D−) are routed directly to
the DM (to the USB-to-serial module). The
Rx/Tx from the USB-to-serial module (DM)
are routed directly to the HC-05’s serial
pins (RXD and TXD). Finally, the activehigh output from the HC-05’s STATE pin
directly feeds the blue (connection status)
LED via a 1kΩ current-limiting resistor.
Fig.8 shows the stripboard, along with
the relevant track-cuts, wire-links, and
component placements. We will not go into
J3
5V
5V
D–
D+
ID
0V
NC
J1
0V
USB BoB
To DM
D+ / D–
5V
0V
J2
Power to DM
11 12
EN
VCC
TXD
GND
To DM Rx / Tx
RXD
STATE
J6
J4
J5
Support and
alignment only
R1
1kΩ
0V
D1
11
12
5V
0V
Fig.7. Block diagram for DM. Note the
additional USB BoB that is required.
56
step-by-step detail – it’s a straightforward
build. Simply cut the correct size board (19
tracks by 10 holes); make the seven trackcuts; insert the six wire-links, 1kΩ resistor,
LED (long lead (anode) into hole H7) and
mount the four banks of downward-facing
pins (that will plug into the DM). Next,
mount the 5-way pinstrip (for the BoB),
and the 6-way socket (for the HC-05).
Finally, solder the BoB onto the 5-way
upward-facing pinstrip – be careful to get
the correct orientation (the USB socket
is upper-most, meaning the GND pin
should be closest to the left edge of the
stripboard). It is also worth soldering two
pieces of wire to strengthen the USB BoB
onto the stripboard (positions B1 and B5).
And that’s all there is to it. Throughout
construction, do the usual checks to ensure
that track-cuts are across the full width
of the track, and that there are no shorts
between adjacent tracks. Correct anything
that doesn’t look right.
To test the adaptor, carefully insert it
into your DM with the orientation shown
in Fig.6, but do not install an HC-05 yet.
Connect it via your micro-USB lead to
your computer, and launch your terminal
app exactly as if you were using the MKC.
Press some keys and you should see the
DM’s red LED (data) flash as you press
them. However, nothing should appear on
the screen. If you do not see the DM’s red
LED flash then stop and check everything.
There is not much that can cause an issue,
so start by ensuring that the DM’s green
LED (power) is lit; ensure that the adaptor
is inserted into the DM correctly; check
the soldering on the adaptor, as well as
the track-cuts and wire-links; and finally
check that the terminal app is connecting
to your usual COM port (as if you were
connecting to your MKC).
Once you can see the red LED flash
each time you press a key, then you can
continue. Grab a short piece of wire (or a
component leg off-cut) and temporarily
insert it between the second and third
holes on the 6-way HC-05 socket (link E8
to E9). This will connect the Tx output
from the USB-to-serial module (on the DM)
back to the Rx input. So now when you
press keys you should see the characters
appear (echo) in your terminal app. Note
that the Enter key does not move down
A
B
C
D
E
F
G
H
I
J
J
I
H
G
F
E
D
C
B
A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
A
J1
J2
B
BoB
C
D
J3
E
J4
F
R1
G
k a
H
I
D1
J5
J6 J
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
J
I
H
G
F
E
D
C
B
A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Fig.8. Stripboard for DM: (top) component
side (bottom) conductor strip side. (Blue
indicates downward facing connector pins
on underside – see photos in Fig.6.)
Practical Electronics | March | 2020
n
Upward facing sockets that
J8
0V
5V
J2
J5
0V
17
18
15
16
5V
To MKC
J1
EN
VCC
21
To MKC
TXD
22
23
GND
24
25
STATE
26
RXD
J4
J3
5V
0V
0V
J6
J7
1
3
2
5
4
7
6
9
8
A
B
C
D
E
F
G
H
I
J
K
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
J1
J2 D1
J4
J5 k
19 20 21 22 23 24 J3
a
R1
J6
J7
J8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
A
B
C
D
E
F
G
H
I
J
K
K
J
I
H
G
F
E
D
C
B
A
K
J
I
H
G
F
E
D
C
B
A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
D1
R1
1kΩ
mimic those on the MKC
(allowing access to the
Micromite’s I/O pins, and
other hardware modules to
be plugged in)
n
A socket for the HC-05 module.
This is oriented horizontally
so that when the HC-05 is
inserted, it is not going to
prevent other plug-in modules
from being inserted (see Fig.6)
n
An LED and current-limiting
resistor for visual indication
that the HC-05 has successfully
connected to the HC-05
module at the computer end.
11
10
13
12
14
To MKC
Fig.9. Block diagram for the MKC adaptor
a line (ie, it does not perform a line feed
(LF)). Instead, it will just position the
cursor at the beginning of the current line
(ie, perform a carriage return (CR)). If you
don’t see the characters appear when you
press keys then perform the usual checks.
Next, remove the temporary link from
the second and third position and insert
it between the first and fifth holes on the
6-way socket. This should result in the
adaptor’s LED being lit. If it isn’t lit then
check the LED circuit, and if you have
access to a multimeter, carefully check
that you have close to 5V present at the
fifth position. Correct anything wrong,
and ensure that you do see the LED on the
adaptor lit (when positions 1 and 5 on the
HC-05 socket are linked) before moving on.
As a final test, remove the temporary test
link and carefully insert an HC-05 module
(see Fig.6 for orientation). You should see
the small red LED on the HC-05 flash.
That concludes testing for now. We
will come back and use this adaptor in
task T5; but for now, unplug everything
from your computer, and let’s build the
other adaptor.
T2: HC-05 adaptor for the MKC
This adaptor is designed to be plugged
into the MKC (from above). However, it
must also allow other hardware modules
to be plugged in (normally other modules
would be plugged directly into the MKC).
So this is a pass-through adaptor and
needs to have the following requirements:
n
Correctly positioned pins (downward
facing) allowing the adaptor to be
plugged into the MKC
Practical Electronics | March | 2020
The schematic for this adaptor
is shown Fig.9. Once again, it Fig.10. Stripboard for the MKC: (top) component
is just a matter of making the side (bottom) conductor strip side. (Blue indicates
required connections between downward facing connector pins on underside – see
the MKC, the HC-05 and the LED photos in Fig.6.) J3 soldered directly to copper strips.
to check that the adaptor’s LED turns
(as outlined in Fig.3). The 5V power for
on. Perform the usual checks and rectify
the HC-05 on this adaptor board is taken
errors before moving on.
directly from the MKC. The HC-05’s serial
Now you may carefully insert an HC-05
pins (RXD and TXD) feed directly to the
module with the correct orientation (see
MKC’s Tx and Rx (console) pins. And,
Fig.6), and check the small red LED on
as before, the active-high output from
the HC-05 flashes. If it doesn’t flash then
the HC-05’s STATE pin directly feeds
you will need to ensure you have a 5V
the connection status LED via a 1kΩ
supply going to the GND and VCC pins
current-limiting resistor. Note that a 3-way
on the HC-05 socket. If 5V is there but
socket (J8) has been added that allows an
the LED does not flash then it may be a
infrared receiver to be inserted. This is not
faulty HC-05. (I mention this because I
a requirement for the Bluetooth link, but
have had one – out of approximately 30
it adds useful functionality if we want to
purchased – that turned out to be faulty.)
use an IR receiver in a project.
That concludes testing this adaptor; we
The stripboard requirements are shown
will come back and use it in task T8 when
in Fig.10 – it uses a slightly bigger board (24
we set up the complete Bluetooth link.
tracks by 11 holes). Make the 14 track-cuts;
insert the six wire-links, 1kΩ resistor, LED
(with the long lead (anode) in hole B19);
T3: No Button? Simply add a link
mount the three banks of downward-facing
By default, when you power up the HC-05
pins (that will plug into the MKC); and
it will be in communication (Data) mode;
mount the 6-way socket (for the HC-05).
ie, it acts as a serial-to-wireless module –
Note the HC-05 socket (J3) is soldered to
albeit one that may not actually be paired
the underside of the stripboard (not through
to another Bluetooth device. However, as
holes), and with a horizontal orientation
mentioned above, to enter configuration
(see Fig.6). Finally, solder the four upward
mode you need to hold down the miniature
facing sockets. Perform the usual checks
button while powering up the HC-05. If
along the way to ensure the track cuts are
both of your HC-05 modules have the
correct, and no solder shorts have been
button in place, then you can jump this
introduced between adjacent tracks.
section and move straight on to task T4.
When you are happy that everything
However, if either HC-05 has no button
looks correct with this adaptor, carefully
(and you do not have any spare miniature
insert it into your MKC with the orientation
buttons to solder into position) then solder
shown in Fig.6. Again, do not install an
a two-way pin-header across the button
HC-05. Then connect your MKC to your
pads. You can mount this header either
computer (or any 5V USB PSU) using your
horizontally, or vertically (see photos in
usual USB lead. Note that we are only
Fig.6). Then, whenever you need to put
testing for 5V on the adaptor, so there is
the HC-05 into configuration mode, simply
no need to launch your terminal app for
place a jumper link onto the header (to
this test. If you have access to a multimeter
short out the button pads) before you
you can carefully check that you have close
power up the HC-05.
to 5V present at the fifth position on the
Now that all the hardware has been
HC-05 socket (J3) (effectively point A23).
assembled, and some basic tests have been
Insert a short piece of wire into the first
performed, we need to prepare your terminal
and fifth positions of the HC-05 socket
app to configure the two HC-05 modules.
57
T4: Preparing the terminal app
(for HC-05)
Until now, whenever you used your MKC
for development, you first inserted the DM
into it, and then connected this duo to
your computer, from which you launched
your terminal app. Everything (should
have) then worked, and you saw either
the usual Micromite welcome message,
or cursor, or your running program.
This all happens because you initially
went through the process of making
the necessary settings in your terminal
app. These settings were then saved,
allowing you to do a ‘single click’ (this
was discussed in Part 4, May 2019).
In essence, the terminal app only talks
to the USB-to-serial module (on the COM
port assigned by the operating system).
Nothing happens in the terminal app
until something intelligent (ie, your
MKC) is connected to the Tx and Rx pins
on the USB-to-serial module. Whenever
something is connected to these pins,
successful communication can only take
place if the settings in the terminal app
match those required by the connected
device (remember we had to set the
speed to match the Micromite’s OPTION
BAUDRATE setting). So currently, your
terminal app is specifically set up for
communicating with your Micromite.
However, we have now replaced the
MKC with an HC-05. This means we need
to adjust some terminal app settings to
allow successful communication with the
HC-05 bcause its parameters are different
to those used by the Micromite.
In the following discussion, we will
be referring to TeraTerm as our terminal
app. If you use a different terminal app
then don’t worry – you will use the
same settings, but they will be found in
different places within the menus. (Useful
tip: before making any changes to the
terminal app settings, take a picture of the
screen showing the current settings – we
will need to set them back to what they
currently are once we have configured
the two HC-05 modules. A camera on a
smartphone can help here. Otherwise,
simply write them down or take (and
save) a screen grab.)
Before we adjust the terminal app
settings, let’s first connect some hardware
for it to communicate with. Take the
smaller adaptor and insert it carefully
into your DM. Now connect this up to
your computer in exactly the same way
as if you were plugging in the MKC/DM
combination. Check that the green power
LED on the DM is lit. If an HC-05 module
was already inserted into the adaptor,
carefully remove it. Now launch your
usual terminal application (exactly as if
you were connecting to your MKC/DM).
If everything goes well, then you will see
your terminal screen open up (and it will
58
be connected to the USB-to-serial
module in your DM).
Do not expect to see anything
on the terminal screen yet. The
position we are trying to get to is:
terminal app open and connected
to your DM. If your terminal app
doesn’t connect for some reason,
then check which virtual COM port
your operating system has assigned
(shutting down any open sessions of
your terminal app first). Remember,
at this stage simply treat everything Fig.11. TeraTerm settings highlighted here need to be
as if you are connecting to the MKC/ altered to enable successful communication with the
DM (all we have done is replace the HC-05. Also set TeraTerm’s baud rate to 38400.
MKC with a Bluetooth module).
performed up to this point (ie, DM green
Next, take one of the HC-05 modules
power LED on, slow flash on HC-05
and press the button (or add the jumper
small red LED, 38400 baud, echo on and
link) while you insert the HC-05 into
Transmit as CR+LF).
the adaptor board. This should result in
the small red LED on the HC-05 initially
T5: Configure the slave HC-05
coming on, and then it should start flashing
In this task, we will first reset the HC-05 to
slowly. If this is the case, then the HC-05
original factory defaults (just in case any
is now in configuration mode. If the LED
settings have previously been changed).
is flashing quickly, then either the button
Then we will set the HC-05 to be a slave,
wasn’t fully pressed, or the jumper link
followed by setting the baud rate of the
wasn’t in place correctly. Remember,
HC-05 to the same value the Micromite
the button needs to be pressed while the
uses (ie, what we noted down from the
HC-05 is inserted. If you’re using a link,
previous section). Finally, we will find
it can remain in place for now.
the unique address of this HC-05 module
Once you have the small red LED
so that the address can be programmed
flashing slowly, you are ready to move
into the other HC-05 (the master). Doing
on and adjust the terminal app settings.
this ensures the master only connects to
First, we need to ensure the baud rate is set
this slave HC-05.
correctly. In TeraTerm, go to Setup/Serial
So, with an HC-05 inserted into the
port... and make a note of the current Speed
adaptor and in configuration mode (slow
setting – it is likely to be either 38,400,
flashing red LED), let’s now configure
or 115,200. This is the speed that your
it to be the slave. You’ll need to type
terminal app communicates at with your
in the commands ensuring you see an
Micromite. Now ensure that the Speed
OK response at each stage (see Fig.12).
Note that if you make a mistake when
is set to 38,400, which the HC-05 uses
entering a command, using the Delete
(remember to record all current settings
key, BackSpace key, or cursor keys will
prior to changing them). Press OK to save.
result in an error upon pressing the Enter
Now go to Setup/Terminal and tick the
key. If you do not see an OK response,
Local echo option to set it. On this same
or if you see any error message, then
screen, set the New-line, Transmit: option
simply repeat the relevant command.
to CR+LF (see screenshot in Fig.11). Press
So now type the following commands,
OK to save. These are the only settings
each followed by Enter:
that need to be adjusted. Note that if you
AT+ORGL Assigns original factory
were to close your terminal app then these
modified settings will be lost. So to save
settings
them more permanently, go to Setup/Save
setup and then click the Save button.
Henceforth, whenever you launch your
terminal app, the settings will be pre-set
for communicating with the HC-05.
Now for the crucial test – in the terminal
window type AT, then press Enter; you
should see an OK response. Note that it
is case insensitive, so at is also valid. If
you just see a blank line returned then
simply repeat AT (Enter) until you see
OK. Once you see this, it means that you
are successfully communicating with
the HC-05 module and you are now in a
position to configure it (leave it plugged in
for now). If you do not see an OK response
Fig.12. The commands used to configure
then you will need to repeat the checks
one HC-05 as the slave.
Practical Electronics | March | 2020
the Bluetooth link will just
not work. If it is different,
then simply re-enter the
above BIND command, but
this time with the correct
address.
This completes configuration of the
master HC-05. If you used a link to enter
configuration mode, then now is the time
to remove it. Next, temporarily remove
the HC-05 from the adaptor, then reinsert it. This takes the HC-05 module
out of configuration mode, and puts it
into communication mode.
Fig.13. The commands used to configure
the other HC-05 as the master.
T7: Set terminal application
settings back to Micromite
requirements
AT+ROLE=0 Defines slave mode
AT+ADDR? Returns the unique address;
write it down exactly
as shown, for example:
98d3:51:fd967d
AT+UART=115200,0,0
Sets the baud rate which
must match your Micromite
(ie, use the Speed value
noted from the previous
section); 115200 is just an
example, you may be using
a different speed.
The last thing to do before testing the
Bluetooth link is to reinstate the terminal
app settings back to what they were
originally (ie, what they were set to when
used with your MKC/DM). In your terminal
app, first set the correct baud rate (Setup/
Serial port...) so that it matches what
your Micromite uses. Then in Setup/
Terminal, switch off echo (un-tick box)
and also return Transmit: back to CR (and
not CR+LF). Be sure to save the settings
so that they are not lost when you shut
down the terminal app. And that’s it – we
are now ready to test the Bluetooth link.
Once all these steps have been completed,
remove the HC-05 module and insert it
into the MKC adaptor board. If you used
a jumper link on the HC-05 to mimic the
miniature button being pressed, then
remove the link as the configuration for
the slave HC-05 is now complete.
T6: Configure the ‘Master’ HC-05
In a similar fashion to what we have just
done, plug the other HC-05 module into
the DM (configuration) adaptor while
pressing the button (or placing a jumper on
the link). Once you see the slow flashing
red LED to indicate it is in ‘configuration’
mode, type in the following commands,
one at a time, followed by Enter, and
ensuring you see an OK response to each
command (see Fig.13):
AT+ORGL
AT+ROLE=1 Defines master mode
AT+UART=115200,0,0
Use the exact same speed
as you used for the slave
AT+BIND=98d3,51,fd967d
Use the slave address
returned above – NB, use
commas to separate the
address (not colons)
AT+BIND? Shows the address entered in
the previous step. Check that
it exactly matches the slave
address returned in task T5
– this is an important step.
The wrong address means
Practical Electronics | March | 2020
T8: Plugging everything together
If you have been following the tasks stepby-step, then you should currently have the
DM, adaptor, and master HC-05 plugged
into your computer (and powered up); and
your terminal app successfully up and
running. The HC-05’s red LED should be
flashing quickly indicating the Bluetooth
link is waiting to connect to the Micromite
end. The MKC, adaptor, and slave HC-05
should not yet be powered up. If this is not
the case, then simply get to this position.
Now apply 5V USB power to the MKC –
you can use any 5V USB PSU for this, or
even a mobile phone battery pack (you
are aiming to set up all the elements as
shown in Fig.3).
Ideally, position the MKC elements a
short distance away from your computer
(but no more than five metres for now).
You should see signs of life as soon as you
power up the MKC – this will be in the
form of the slave HC-05 red LED initially
flashing quickly. If there are no signs of life,
then check that the MKC’s blue power LED
is lit. If not, then check the power supply.
If it is lit, but there are no signs of life on
the HC-05, then check that the HC-05 is
inserted correctly, and also that the adaptor
is inserted correctly into the MKC. If there
is still an issue, then something has worked
loose from when you tested the adaptor as
part of task T2. In this case, perform the
T2 checks once again.
T9: Wireless Bluetooth link test
If all is well, then in just a few seconds of
powering up both ends, the two modules
should automatically link together. Both
adaptor LEDs being lit will indicate this.
If this is the case then all is good! If both
adaptor LEDs do not light up then you
will need to go back and re-run all the
checks in tasks T1 to T8.
Once both adaptor LEDs are lit you
should find that you can now interact
with your Micromite in the usual manner.
Try typing something like PRINT TIME$
(Enter) and check that all works as
normal. If you don’t see any response (but
the adaptor LEDs are both lit), then is it
because you have a piece of automatically
running code? If so, then use Ctrl-C to
return to the command prompt.
If all has worked out successfully, then
congratulations – you have now ‘set your
Micromite free’. You are now able to use
your Micromite as if it were plugged
directly into your computer. If you do have
any issues that you just can’t resolve, then
simply drop me an email explaining your
situation and I will be happy to help you.
Upgrading your Mood Light to
Bluetooth control
Here’s a quick exercise to demonstrate
remote interaction with the Micromite.
Load the Mood Light software from last
month into your MKC (AUTOSAVE, paste,
Ctrl-Z). Then use four jumper wires to
connect the Blinkt! module to the relevant
MKC pins (via the sockets on the MKC
adaptor) – refer to last month’s article for
the exact pins (SPI Clk, SPI Data, 0V and
5V). Then insert an IR receiver (TSOP) into
the 3-way IR socket that we implemented
on the MKC adaptor board; and finally
type RUN (Enter).
You should now see the Blinkt! light
up green. Press some buttons on the 44button IR remote and you should see that
the Mood Light works as normal. We are
not adding any new features here – all we
are doing is allowing the Mood Light to be
located wherever you want, but with the
power to edit the Mood Light code remotely
from your computer. Try it – press CtrlC, EDIT, and check that you see the code.
Now type in commands at the command
prompt to change the colour of the Mood
Light remotely (this is an exercise for you
to work out...).
Now it’s over to you to think of some
other uses for your wireless Bluetooth
link. Have Fun!
Next month
Next month, we will show you just how
easy it is to add an inexpensive colour
touchscreen to your MKC. We will then
use it to simulate the classic board game
Mastermind – all remotely controlled,
of course!
59
|