How to Easily Add Multiple Wireless Technologies to an IoT Design

Contributed By Digi-Key's North American Editors

Developers of Internet of Things (IoT) applications need to ensure their wireless sensor systems are able to connect seamlessly to cloud-based software and services. However, this often requires choosing and using multiple wireless interfaces.  Ensuring that they all meet their requirements can distract from the higher level IoT application itself.

To address this, development boards and software from a number of vendors help IoT developers rapidly deploy sensor devices that are able to connect wirelessly through local, medium, and wide area networks.

This article will introduce one such solution from Pycom Ltd., describe its characteristics and features, and then show how to go about applying it.

For most IoT applications, efficient wireless connectivity is a critical requirement for IoT device design. So far, no single wireless technology has emerged as the preferred connectivity solution. In fact, no single wireless technology is likely to gain preeminence as wireless providers work to offer increasingly effective alternatives.

The broad number of use cases for IoT applications further complicates the notion of a single connectivity solution. The same IoT application can dictate different connectivity requirements depending on the user's physical location, data throughput requirements, and other conditions. At times, the same application may require the same IoT device to support Bluetooth to interact with a nearby user, Wi-Fi to interact with other local resources, LTE cellular to maintain connectivity when out of Wi-Fi range, and even LoRaWAN or SigFox to connect with other geographically dispersed IoT devices feeding into a central IoT gateway or controller.

The ability to support flexible connectivity across all of these technologies offers a significant competitive advantage to IoT application developers able to succeed in providing it. Earlier approaches for achieving this kind of multi-technology connectivity have resulted in designs that are too complex, too costly, or just too large to meet IoT design requirements. Even with earlier wireless transceivers, developers found themselves facing challenges associated with RF signal path optimization, noise reduction, physical layout, and more.

For developers, creating an optimized hardware solution for a single wireless technology is difficult enough. The complexity escalates dramatically in hardware designs intended to support multiple wireless technologies. Even after creating suitable hardware, software engineers find themselves juggling multiple protocol stacks and software services contending for the same limited resources in IoT designs.

Not surprisingly, deployment of efficient multi-technology wireless connectivity solutions has been limited at best. Pycom's multi-technology wireless boards and software addresses these challenges by reducing the complexity of wireless IoT development to a matter of combining some hardware and software.

Wireless options

The Pycom FiPy and GPy are 55 x 20 x 3.5 millimeter (mm) boards, each designed to provide a complete multi-technology wireless solution for IoT designs. Unlike most wireless products, the FiPy supports Bluetooth 4.2, IEEE 802.11b/g/n Wi-Fi, narrowband LTE, LoRaWAN, and Sigfox. The GPy board does not include LoRaWAN and Sigfox, but otherwise provides the same features as the FiPy. This article focuses on the FiPy board.

Support for LTE cellular is rapidly emerging among IoT design offerings. Pycom’s LTE solution for its growing family of cellular-enabled boards offers support for both LTE Cat M1 and NB-IoT, which feature reduced power consumption while retaining throughput levels consistent with most IoT device requirements. By leveraging these diverse connectivity options, developers can optimize their wireless implementation to meet static or dynamic application demands for range, throughput, and power consumption.

The board provides a suitable platform for IoT design requirements beyond connectivity. At the heart of the FiPy is an Espressif ESP32 SoC that integrates dual processors, 8 Mbytes of flash memory, 4 Mbytes of RAM, and an RF radio subsystem that provides Bluetooth and Wi-Fi connectivity. While the networking processor executes the communications protocol stack, the main processor is available to run user code.

The SoC supports basic IoT sensing requirements with a multi-channel 12-bit analog-to-digital converter (ADC) and a pair of 8-bit digital-to-analog converters (DACs). Along with standard serial interfaces and GPIOs and serial interfaces, Pycom brings out analog and RF functionality through the board’s configurable ports (Figure 1).

Diagram of Pycom FiPy board (click to enlarge)

Figure 1: The Pycom FiPy board brings out its processor’s pins, which developers can map to the processor’s integrated analog and digital functionality. (Image source: Pycom)

Along with its broad functionality, the FiPy provides energy saving features needed to meet power conservation requirements for battery powered IoT designs. For example, developers can put the processor in deep sleep mode and use a dedicated ultra-low-power (ULP) processor to handle I/O activity, drawing as little as 25 microamps (μA). Designed to work independently of the main processor, the ULP processor can execute user code to access GPIOs or perform data conversion with the SoC's integrated ADCs or DACs, providing developers with a flexible platform for low-power operation without compromising peripheral operations.

Plug-in hardware enhancement

For IoT designs with more extensive sensing requirements, developers can combine the FiPy with Pycom’s Pysense sensing board and Pytrack location tracking board.

For sensing applications, the Pysense board provides an STMicroelectronics LIS2HH12 accelerometer, a Silicon Labs SI7006-A20 temperature/humidity sensor, a Lite-On LTR-329ALS-01 ambient light sensor, and an NXP Semiconductors MPL3115A2 pressure sensor – all connected through the board’s shared I2C serial bus (Figure 2). In normal operation, each of these sensors consumes minimal power. For example, the NXP MPL3115A2 pressure sensor consumes only 40 μA in normal sampling mode, while the most power hungry sensor, the Lite-On LTR-329ALS-01 ambient light sensor, consumes about 250 μA. The other two sensors each consume about 150 μA.

Image of plugging the FiPy into the Pysense board

Figure 2: By plugging the FiPy into the Pysense board, developers can create a multi-sensor IoT device able to use multiple options for wireless connectivity. (Image source: Pycom)

Thanks to the relatively low power requirements of the Pysense and the FiPy, developers can run their Pycom-based designs on batteries for years. The Pysense board includes a Texas Instruments BQ24040 battery charger IC and connector for powering the design using a suitable rechargeable battery with a JST connector such as the TinyCircuits ASR00007 270 milliamp hour (mAh) lithium ion polymer (LiPo) battery.

For location tracking applications, the Pytrack board combines an accurate Global Navigation Satellite System (GNSS) GPS sensor and accelerometer along with the same LiPo battery charging subsystem used in the Pysense.

Headers on the Pysense and Pytrack sensor boards offer a simple solution for creating a hardware platform specific to each IoT application. Developers simply plug the FiPy board into the appropriate expansion board to create specific hardware configurations. For applications that do not require LoRaWAN or Sigfox connectivity, developers can instead use the GPy board.

Plug-in software enhancement

The ability to combine boards to extend overall hardware functionality is a familiar and important capability for prototype development. In the past, however, hardware enhancements to a base design could bring significant challenges on the software side as developers worked to find and integrate different software drivers and middleware required to support specific hardware configurations. With its support of MicroPython, Pycom makes application software development just as straightforward as plug-in boards do for IoT device hardware implementation.

Based on the Python language, MicroPython augments it with hardware oriented support. At the same time, MicroPython eliminates Python features not needed in embedded systems, enhancing performance while reducing the memory footprint for resource-constrained embedded designs.

As with Python, MicroPython lets developers add specific software functionality simply by importing a module. For example, developers can program the FiPy’s integrated ADC simply by loading the ADC module and reading values (Listing 1).

Copy

import machine

 

adc = machine.ADC()             # create an ADC object

apin = adc.channel(pin='P16')   # create an analog pin on P16

val = apin()                    # read an analog value

Listing 1: As with Python, MicroPython lets developers enhance their software functionality by importing a software module, providing a simple approach for adding hardware specific features such as reading data from an analog-to-digital converter (ADC) as shown here. (Code source: Pycom)

Just as developers can easily enhance their designs with add-on boards, they can add complementary support by importing the appropriate module. After plugging their wireless board into an expansion board, developers simply need to add the corresponding MicroPython module into their code.

MicroPython’s programming model lets developers use these modules seamlessly to rapidly implement IoT applications. As with software support for ADC hardware as shown in Listing 1, software support for hardware extensions such as Pysense only requires developers to import the appropriate module. A full set of sensor-specific modules as well as sample software that demonstrates their use in typical software applications are readily available. To read the Pysense’s SI7006A20 temperature and humidity sensor, for example, developers need only import the Pysense module along with sensor-specific modules before instantiating the SI7006A20 object (SI7006A20(py)) used to read the sensor’s temperature (si.temperature()) and humidity values (si.humidity()) (Listing 2).

Copy

from pysense import Pysense

from LIS2HH12 import LIS2HH12

from SI7006A20 import SI7006A20

from LTR329ALS01 import LTR329ALS01

from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE

 

py = Pysense()

mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters. Mode may also be set to PRESSURE, returning a value in Pascals

si = SI7006A20(py)

lt = LTR329ALS01(py)

li = LIS2HH12(py)

 

print(mp.temperature())

print(mp.altitude())

mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in Pa. Mode may also be set to ALTITUDE, returning a value in meters

print(mpp.pressure())

print(si.temperature())

print(si.humidity())

print(lt.light())

print(li.acceleration())

print(li.roll())

print(li.pitch())

 

print(py.read_battery_voltage())

Listing 2: Developers can study the Pycom Pysense API and associated software samples for use of MicroPython modules specific to sensors integrated in the Pycom Pysense hardware board. (Code source: Pycom)

Thanks to this modular approach, implementing wireless connectivity is just as straightforward. Developers need only import the appropriate module for the desired wireless technology along with other modules for protocols such as HTTPS or MQTT. Along with those wireless communications modules, Pycom sample software demonstrates how developers can quickly set up a Wi-Fi connection and use MQTT to interact with a cloud-based service such as Adafruit IO (Listing 3). Available in a free tier for prototype development, Adafruit IO is a simple cloud resource designed for creating IoT data flow processes including input data streaming, data management, and analytics.

Copy

from mqtt import MQTTClient

import machine

import time

from network import WLAN

 

 

def sub_cb(topic, msg):

   print(“Received: “ + msg)

 

wlan = WLAN(mode=WLAN.STA)

wlan.connect("yourwifinetwork", auth=(WLAN.WPA2, "wifipassword"), timeout=5000)

 

while not wlan.isconnected(): 

    machine.idle()

print("Connected to Wifi\n")

 

client = MQTTClient("device_id", "io.adafruit.com",user="your_username", password="your_api_key", port=1883)

 

client.set_callback(sub_cb)

client.connect()

client.subscribe(topic="youraccount/feeds/lights")

 

while True:

    print("Sending ON")

    client.publish(topic="youraccount/feeds/lights", msg="ON")

    time.sleep(1)

    print("Sending OFF")

    client.publish(topic="youraccount/feeds/lights", msg="OFF")

 

    time.sleep(1)

Listing 3: Pycom’s sample software demonstrates how developers can use a few simple Wi-Fi module calls (yellow highlight) to interact via MQTT with a cloud-based resource such as Adafruit IO as shown here. (Code source: Pycom)

The combination of Pycom multi-technology wireless boards and MicroPython offer a powerful platform for developing wireless IoT designs able to respond dynamically to a changing connectivity environment. Many IoT applications require readily available access to incoming data streams. Yet, an IoT device designed to interact with the cloud through a Wi-Fi LAN, for example, would be lost to the application each time the LAN fails or the local Wi-Fi signal strength drops due to interference or network events. With the Pycom boards, however, developers can simply switch to another wireless connectivity option.

For example, to connect through LTE cellular services, developers simply use the MicroPython LTE module. The same underlying approach allows developers to switch between Wi-Fi and LTE cellular connectivity without changing higher level code created to interact with the host or provide application level features. To use LTE connectivity, for example, developers just load the LTE module, instantiate a corresponding LTE object, and connect to the provider service. As a result, developers need make only minor changes to switch to LTE connectivity in an application (Listing 4).

Copy

from mqtt import MQTTClient

import machine

import time

from network import LTE

 

def sub_cb(topic, msg):

   print(“Received: “ + msg)

 

lte = LTE()

lte.connect()

 

while not lte.isconnected(): 

    machine.idle()

print("Connected to LTE\n")

 

client = MQTTClient("device_id", "io.adafruit.com", user="your_username", password="your_api_key", port=1883)

 

client.set_callback(sub_cb)

client.connect()

client.subscribe(topic="youraccount/feeds/lights")

 

while True:

    print("Sending ON")

    client.publish(topic="youraccount/feeds/lights", msg="ON")

    time.sleep(1)

 

    print("Sending OFF")

    client.publish(topic="youraccount/feeds/lights", msg="OFF")

    time.sleep(1)

Listing 4: Pycom sample software demonstrates how developers can perform the same higher level operations to interact with cloud resources using LTE connectivity (blue highlight) instead of Wi-Fi (yellow highlight in Listing 3). (Code source: Pycom)

This same general approach applies to switching connectivity to Bluetooth, LoRaWAN, or Sigfox in response to changing conditions. Consequently, developers can create IoT devices that are able to easily support a broad array of wireless connectivity technologies. When operational or functional requirements dictate the need to switch to a different connectivity option even during runtime, developers can easily implement dynamic switching capabilities required to maintain availability or meet changing performance requirements.

Conclusion

Developers can rapidly meet emerging requirements for wireless connectivity using Pycom boards built specifically to support multiple wireless technologies including Bluetooth, Wi-Fi, LTE, LoRaWAN, and Sigfox. By combining these boards with MicroPython-based software, developers can quickly implement IoT devices able to respond fluidly to changing wireless connectivity requirements.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this publisher

Digi-Key's North American Editors