Designing an Internet-connected product requires many skillsets. Developers need to know how to write embedded software, build a circuit board, understand how to secure their device, and connect to a network to remotely update and manage their device.
Building out the expertise and the infrastructure for a single IoT product can be challenging, time consuming, and expensive. Development teams require a way to jumpstart their development and minimize what they need to do in a typical design cycle in order to meet cost and time-to-market requirements.
Many different IoT platforms to help with this are beginning to take shape, but one that is particularly interesting comes from Electric Imp, which has pulled together the hardware and software required to get a developer up and running quickly.
This article will describe the Electric Imp IoT Platform and how to go about using it.
Defining the Electric Imp IoT platform
The Electric Imp platform is an IoT platform that provides developers with a complete solution to connect and manage IoT devices. The platform contains all the building blocks that a development team needs in order to quickly get their product up and running. These building blocks include:
- Fully integrated hardware
- Embedded operating system
- Cloud services
- Code libraries
- Security solutions
To start, developers connect their sensors and proprietary hardware to an Electric Imp radio module that contains not only their custom software, but also the ImpOS which manages a secure connection to the Imp Cloud (Figure 1). Both end users and developers are able to provide their Wi-Fi settings to their product or development platform through a mobile device using an application known as BlinkUp. Once the Imp hardware has the Wi-Fi information, it can directly and securely communicate with the Imp Cloud, and from there, to the wider Internet.
Figure 1: The Electric Imp platform comes with proven, fully integrated hardware, software, OS, APIs, cloud services and security for fast IoT device connectivity to the Cloud. (Image source: Electric Imp)
Using a platform such as the Electric Imp provides developers with several advantages that include:
- Significantly decreasing time-to-market
- Focusing on the company’s core expertise rather than Internet connectivity
- Greater product value and differentiation
- Removing the need to build up connectivity infrastructure and expertise
The Electric Imp hardware
The Electric Imp hardware provides developers with a standard hardware set that includes:
- 802.11 b/g/n or a/b/g/n Wi-Fi transceiver
- 32-bit ARM® Cortex® processor
- Robust embedded operating system with fail-safe firmware updates
- User selectable I/O such as GPIO, PWM, and Analog In
- Communication via SPI, UART, and I2C
The modules are made by Murata Electronics. The major differentiator for designers will be the internal processor, the Wi-Fi connectivity options, and the packaging. For example, the imp005 (LBWA1UZ1GC-901) is based on a 320 MHz ARM Cortex-R4-based processor and operates in both the 2.45 GHz and 5 GHz bands. The imp003 (LBWA1ZV1CD-716), on the other hand, is based on a 144 MHz ARM Cortex-M4F-based processor and operates in the 2.45 GHz band only. Both are surface-mount packages (Figure 2).
Figure 2: The imp005 (left) and imp003 (right) modules integrate a Wi-Fi module and ARM Cortex microcontroller to minimize device footprint. (Image source: Murata Electronics)
The surface-mount patterns wouldn’t be easy to access without a break-out board. The imp003 has its IMP003-BREAKOUT, a simple break-out that includes a USB interface for developers to power the device, the phototransistor needed to program the module with Wi-Fi settings using Electric Imp’s unique BlinkUp methodology, and some miscellaneous support components (Figure 3).
Figure 3: The imp003 break-out module is a low-pin-count development board that allows developers to easily get familiar with and use Electric Imp hardware that will eventually be used in the end products. (Image source: Murata Electronics)
The imp005 break-out board is a bit more sophisticated since the imp005 module not only has a larger pin count, but also has the more powerful ARM Cortex-R4 processor (Figure 4). The imp005 break-out board also includes Ethernet, a standard USB interface to power the device and connect to the host, as well as the phototransistor.
Figure 4: The imp005 break-out module provides developers with access to the more powerful imp005, which contains an ARM Cortex-R4 microcontroller in addition to advanced connectivity options such as USB and Ethernet. (Image source: Murata Electronics)
Setting up an Electric Imp using BlinkUp
One problem that every IoT device faces is how to program the device with the local Wi-Fi router information. Electric Imp solved this problem with a unique approach that uses a phototransistor to program the SSID and password information into the device.
Platform and end-product users download the Electric Imp BlinkUp application to their mobile device and then enter their network information into the application. When prompted, the user then presses their mobile device up to the phototransistor. The mobile device’s screen then flashes a command sequence that programs the Electric Imp hardware (Figure 5). Once programming has completed, development can commence.
WARNING! Do not look at the mobile device screen while the network information is being programmed. Doing so can lead to either a really bad headache or an epileptic fit.
Figure 5: The BlinkUp application allows a developer or user to enter their Wi-Fi SSID and password and easily transmit that information to the Electric Imp module through a series of blinks from the mobile device to a phototransistor. This eliminates the need for extra connectivity, such as Bluetooth or USB. (Image source: Electric Imp)
Once a developer has connected the Electric Imp module to the Internet, the module will register a unique ID with the Imp Cloud. That ID can also be found in the BlinkUp application. The unique ID is used to identify the module and connect it to the online development environment. The ID is also used to push firmware updates to the product and also manage the device. A module can be connected to the Cloud by logging into the development environment and then creating a new software application, also known as a model, and then associating the modules ID with the model (Figure 6).
Figure 6: Connection of a module through the Cloud to a software model is done by simply reviewing the list of available Imp modules and then assigning either an existing software model or a new model, to the device. (Image source: Electric Imp)
Once the model has been created, a developer has access to the online development environment. This allows the writing of software for the Electric Imp module and also code that runs in the Cloud to communicate with that module. The server and module application code is written in a scripting language called Squirrel. Squirrel has a similar notation to the C programming language, so for most embedded developers the transition is natural.
The development environment is broken up into three primary pieces. The first is server-side code, also known as agent code. Second is the device code, which can be deployed to a module once the script compiles and is managed by the Imp Cloud. Thirdly, there is a log that can be used to monitor the agent and device behaviors, as well as for debug.
Figure 7: The Electric Imp development environment is a fully integrated environment that allows developers to simultaneously work on their device firmware and cloud software from a single view. (Image source: Electric Imp)
Saying “Hello World” with a Blinky LED program
Getting an application up and running on an Electric Imp module is very straightforward. Objects can be assigned to hardware features from a high level of abstraction. This turns the Imp module and the underlying microcontroller into a black box.
The first step any developer takes is to either print “Hello World” through a terminal or blink an LED. Let’s look at the code that would be necessary to blink an LED.
First, a developer needs to log in to the development environment and create a “Hello World” or “Blinky” model and assign it to their target module. Just like in any application, the developer would assign and configure pins and variables. In this case, if an LED were connected to pin 5, a developer could write the code to configure the LED and create a state variable (Listing 1).
// Create a global variable called 'led' and assign the 'pin' object to it
led <- hardware.pin5;
// Configure 'led' to be a digital output with a starting value of digital 0 (low, 0V)
// Create a global variable to store current state of 'led‘
state <- 0;
Listing 1: Writing software for the Electric Imp module is simple using the pre-existing libraries and the Squirrel scripting language. This script configures the LED and creates a state variable. (Code source: Electric Imp)
A simple application function could then be written to blink the LED (Listing 2).
// Invert the value of state:
// when state = 1, 1-1 = 0
// when state = 0, 1-0 = 1
state = 1 - state;
// Write current state to 'led' (which is pin9)
// Schedule the imp to wakeup in 0.5 seconds and call blink() again
Listing 2: Blinking an LED or controlling hardware is done through a set of libraries that eases development and can dramatically decrease development time. In this example, a simple function is being used to access an LED resource and delay the function execution by 500 milliseconds through ImpOS (Code source: Electric Imp)
That is it! All the Squirrel code necessary to configure an LED and blink it on the hardware. The LED program can be written in less than a dozen lines of code and a developer doesn’t have to know a single ARM core register. Simple accesses to the high-level API and developers are off and running.
Integrating external sensors into an Electric Imp model
Integrating external sensors and components into the Electric Imp platform is also relatively simple. The platform allows a developer to include a library that has already been developed by using the #require directive, which is similar to the #include directive in the C programming language. There are several types of libraries that are developed and ready for developers to use out of the box. These libraries include:
- Web services
- Hardware drivers
Product developers can interface devices such as relays, accelerometers, and magnetometers to the Electric Imp module, and then use the libraries that are already written for those components to jumpstart their design. The libraries are available from the Electric Imp development center website.
Figure 8: Electric Imp has a wide variety of libraries that are ready to be used from the moment development is started. These libraries accelerate development time and provide access to popular hardware devices and software services. (Image source: Electric Imp)
Tips and tricks for using the Electric Imp IoT Platform
There are several considerations that development teams need to consider when using a platform such as Electric Imp’s. First, the Electric Imp module is integrating two major components, the Wi-Fi radio and the microcontroller, into a single package. This integration can save cost and board real estate. Next, developers should review the existing hardware and driver libraries when selecting components for their products. Utilizing existing libraries will help accelerate the development cycle.
Finally, developers need to remember that the Electric Imp platform does not directly connect to the Internet. All communication is first performed through a secure connection to the Imp Cloud. This then uses an agent to direct messages to the wider web. There are also libraries for third-party services such as data storage and analysis that developers can use on the cloud side. Leverage as much existing code from the libraries as possible.
Developing an IoT device can be done very quickly if designers use existing technologies and utilize an IoT platform. Leveraging one of several platforms that are on the market today can help developers focus on their expertise and leave the infrastructure for other companies to handle. As we have seen, the Electric Imp IoT Platform is an interesting and unique solution worthy of further investigation.