To post comments on this article and find any associated files and/or downloads, go to
if (tbuf.size > 0)
term.str(string(13, “—> “))
■ FIGURE 1. HM- 10 setup.
At the top, we check to see if there is a character in
the terminal buffer; if no, we jump back to the main loop.
If yes — and that character is not a carriage return — we
check for backspace; this allows us to fix typos. If not a
CR or backspace, the character is put into a text buffer.
The HM- 10 commands are case-sensitive, so the
character is converted to uppercase first. Yes, this will
force the name we give the module to uppercase. You can
change that if you like; just remember to use the Caps
Lock key when entering the command.
When we do press Enter, the command is displayed in
the terminal and sent to the HM- 10. Once the command
is sent, we clean up the buffer and return to the main
loop. Again, note that this method doesn’t block the
program while waiting on a command. You’ll see why in a
The show_response() method checks for input from
the HM- 10 and displays it:
Figure 1 is a capture of the terminal window in a
setup session. Have a look at the last line. What is that?
pub show_response : c
It’s the reason the get_command() method is nonblocking. In this case, I connected to the HM- 10 using my
c := ble.rxtime(2)
if (b => 32)
phone and an app called BLE Scanner
which is available for the Android and
iOS. After connecting to the module, I
was able to write a test string to the
device through the custom service FFE0
using the FFE1 characteristic.
This method looks to see if there
are any bytes available from the HM- 10.
Figure 2 is a screenshot from my
phone after writing (W button) to the
HM- 10. What makes me happy is that
we can use a sub-$10 module to receive
text commands from any device that
If there are, it puts up a response
indicator, then pulls bytes from the HM-
10 for display.
Okay, back to John’s project. As
you’re probably aware, a Ouija board is
a rectangular panel with the alphabet,
digits 0 through 9, and the words “Yes,”
You may wonder why we’re using
the rxtime() method here. The reason is
that we could call this method just after
the first byte arrives from the HM- 10,
and then outrun the serial input (which
is fairly slow at 9600 baud). The short
timeout ensures that once we see
something coming in from the HM- 10,
we get it all.
No,” and “Goodbye” printed on it. A
standard Ouija board uses a small
device called a planchette to spell out
messages; John’s is back-lit with the RGB
lamps, and controlled via BLE from a
smartphone or tablet.
When the program starts, the entire
board fades up to the background color.
■ FIGURE 2. BLE scanner app.
With a connection between the phone
January 2018 17