Creating IoT Devices You Can Control With Your Smartphone or Tablet - Embedded.com

Creating IoT Devices You Can Control With Your Smartphone or Tablet

I'm currently performing my Happy Dance (stop laughing, it's not my fault I caper and cavort this way) because the Simblee by RF Digital officially launched this morning.

Just to set the scene, let's remind ourselves that, a few years ago, the folks at RF Digital created a fingertip-sized, wireless-enabled, Arduino-compatible microcontroller called the RFduino.


(Source: RF Digital)

The RFdunio is supported by an ecosystem of plug-in shields, including Switch/LED, Relay, Servo, microSD, USB, Prototyping, and Power/Battery shields (all of these shields also work with the Simblee breakout boards discussed below).

Now we have the Simblee module, which is 10mm x 7mm x 2mm in size, and which contains two main functions: A 32-bit ARM Cortex-M0 processor (with 128KB of Flash and 24KB of RAM running at 16MHz) and a Bluetooth Smart engine.


(Source: RF Digital)

If you are creating commercial or industrial products from the ground up, then you will almost certainly decide to mount Simblee modules directly on your circuit boards. By comparison, when it comes to prototyping or hobbyist applications, you may find it more advantageous to use one of the Simblee breakout boards. There are currently two such boards; one offers seven GPIO (general-purpose input/output) pins while the other provides 29 GPIOs.


(Source: Max Maxfield/Embedded.com)

Each of these breakout boards has a Simblee module (shown in the upper-right-hand corners of the boards in the photograph above) along with 0.1″ pitch headers on top for connecting shields, and 0.1″ pitch pins on the bottom for plugging into breadboards or soldering to printed circuit boards.


(Source: Max Maxfield/Embedded.com)

One point that may be confusing at first is that the 29-GPIO board appears to boast 31 GPIOs numbered 0 through 30. Closer examination, however, reveals that GPIOs 26 and 27 are not exposed (they are used internally), and are therefore not available to the end user.

Now, I love Arduinos — I use them for all sorts of things, but I have to say that it can be a bit of pain remembering which pins can act as digital inputs and outputs, which can act as analog inputs, which can act as pseudo-analog (PWM) outputs, which are dedicated to acting as a UART, which can be used as an SPI bus, which can be used as an I2C bus, and so on and so forth.

In the case of the Simblee, GPIOs 1 through 6 can act as analog inputs, and all of the GPIOs can act as digital inputs and outputs or pseudo-analog (PWM) outputs. Furthermore, any of the GPIOs can be configured to act as UART, SPI, or I2C signals. Suddenly, my life just got a whole lot easier.

Creating User Interfaces for Smartphones and Tablets
A Simblee module or breakout board can be programmed using the Arduino IDE and used as a standalone microcontroller. In this case, the Simblee can be visualized as being “Just another flavor of Arduino with a different footprint or form factor.”

Where the Simblee really comes into its own is when we start controlling it using a smartphone or tablet computer. This is probably a good time to mention that the term SimbleeForMobile encompasses any software, tools, and applications used to control Simblee-enabled devices using a mobile platform such as a smartphone or tablet. Now, this next part can be a bit tricky to wrap your brain around, so take a deep breath and I'll try to be gentle.

As I just mentioned, users create sketches (programs) to run on their Simblees using the Arduino Integrated Development Environment (IDE). The thing is that these sketches can include user interfaces (UIs), which can be displayed on the user's smartphone or tablet, and which can be used to monitor the Simblee's inputs and control its outputs.

We'll talk about how we create a Simblee user interface shortly. For the moment, let's just say that both your application and your user interface are loaded into your Simblee module (that little 10mm x 7mm x 2mm beauty we introduced earlier).

Next, you download a free Simblee app onto your smartphone or tablet. If you are using an Apple platform running the iOS operating system, you will download the Simblee For Mobile app from the Apple's App Store; if you are using an Android platform, you will download the Simblee For Mobile app from Google Play (formally known as the Google Play Store or the Android Market).

When you launch the Simblee app on your mobile platform, it uses Bluetooth to announce itself to the surrounding world and ask if any Simblee-enabled devices are in the vicinity. When each of those devices replies “I'm here,” the Simblee app lists their names and descriptions on the screen (from the perspective of the user, this process is essentially instantaneous). Once the user taps the desired item on the screen, the Simblee app sends a message to that device saying “You're up” ; the device then uploads its user interface to the Simblee app, which renders it as a graphical user interface (GUI) on the screen. Due to the way in which this works, the Simblee app may also be thought of as being a Simblee Browser or a Simblee Renderer.

Now, I have to say that when I first heard about creating a user interface with the Arduino IDE, I was a bit puzzled — I really couldn’t see how this could be achieved — but once you get the idea, you say “Wow! That's Brilliant! (Why didn’t I think of that?)”

Let's start by reminding ourselves that A simple Arduino sketch includes two functions called setup() and loop() as illustrated below:

void setup() {  // Put your setup code here, to run once}void loop() {  // Put your main code here, to run repeatedly}

Well, a simple SimbleeForMobile sketch contains four functions (also, we include the SimbleeForMobile library). In addition to the traditional setup() and loop() functions, we also have the ui() and ui_event() functions as illustrated below:

#include <simbleeformobile.h>void setup() {  // Put your setup code here, to run once}void loop() {  // Put your main code here, to run repeatedly}void ui() {  // Put your user interface code here}void ui_event(event_t &event) {  // Put your event-related code here}

The ui() function is where the majority of the SimbleeForMobile User Interface (UI) is defined in textual format. For example, we might call a function (from the SimbleeForMobile library) that says “Draw a switch at this XY location on the screen and make its ON-color green,” and so on for other objects like buttons, sliders, and so forth. This is the interface that will be uploaded to the mobile platform, where it will be rendered (presented) as a Graphical User Interface (GUI).

The ui_event() function provides the callback mechanism by which the GUI on the mobile platform can communicate any actions back into the body of the sketch. We might think of this as acting a bit like an interrupt service routine (ISR). When the user performs some action on the mobile platform's screen, the system communicates this information back to a function in the Simblee Library. In turn, this function calls the ui_event() function in our sketch.

Each graphical object we instantiate is automatically assigned its own unique identifier (ID). The ui_event() function supports a single parameter of type event_t, which is defined in the Simblee Library. The parameter itself is the address of a structure, which contains all sorts of information, including the ID of the object being affected, the type of event, the value associated with the object, and so forth.

There's so much to talk about here, but I think we'll leave that for another column. In the meantime, let's look at a real-world example…

A Real-World Example
As I've mentioned on occasion, I'm involved in a Cunning Chronograph competition. My entry is coming along in leaps and bounds, but I ran into a problem because I'm experimenting with lots of different effects.


(Source: Max Maxfield/Embedded.com)

One solution is to hard-code an effect I want to play with into the sketch, and then compile this and upload it into the Chronograph, but this is painful and time-consuming. Another option is to define a set of digital pins as being of type INPUT_PULLUP, and to then use flying leads to pull them down to 0V as required.


(Source: Max Maxfield/Embedded.com)

This is the technique I was using for a long time… until the Simblee came along. Remembering that the Simblee contains a 32-bit Cortex-M0 processor along with its Bluetooth Smart engine, the majority of users will almost certainly use the Simblee as a standalone solution to monitor and control things. In my case, however, I already have everything running on an Arduino Mega. Furthermore, my Cunning Chronograph is based on NeoPixels, whose critical timing is controlled using assembly code for the Arduino's Atmel processor. Thus, in this case, I simply used my Simblee to replace my hard-wired controls as illustrated below.


(Source: Max Maxfield/Embedded.com)

Now I can use my iPad to control my Simblee, which — in turn — controls my Arduino. The best way to wrap your brain around this is to see it in action, so I just uploaded this video for your delectation and delight.

When I first conceived my BADASS Display, I thought it would be a good idea to locate the control panel at the bottom of the main front panel. This was a decision I've come to regret because I have to keep on bending down to swap effects. Now I can add a Simblee to mirror the actions of the control panel on my iPad's screen, so I can configure the display from the embrace of my comfy chair. The bottom line is that I'm planning on sticking Simblees in all of my hobby projects. I love these things!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.