Connecting the NXP LPC54018 IoT Module to Medium One IoT Cloud
By Greg Toth for Mouser Electronics
The NXP Semiconductors LPC54018 IoT Module is a
self-contained, high performance, IEEE 802.11 enabled microcontroller module for the development of IoT products
that can interface with cloud-based IoT platforms. The module can be used as a standalone unit or plugged into a
base board for rapid prototyping and product development. The Medium One IoT Prototyping Sandbox is a
cloud-based IoT platform designed to help early-stage developers prototype IoT projects or connect existing
hardware to the cloud. In this project, we’ll set up an IoT development environment using the LPC54018
module and companion baseboard to read hardware sensors and send the data to the Medium One cloud using Message
Queuing Telemetry Transport (MQTT). Once the data is in Medium One, it can be processed and viewed using
programmable workflows and configurable widget dashboards.
Project Materials and Resources
The project BOM lists components used in this project. Additional hardware and software development tools are
also identified.
Accounts and Software
- Web browser for accessing software download sites and Medium One IoT Prototyping Sandbox
- Login account for NXP.com to allow downloading tools and software
- Login account for the Medium One IoT Prototyping Sandbox
- NXP MCUXpresso Integrated Development Environment (IDE)
- NXP MCUXpresso Software Development Kit (SDK)
- Application project files available in a GitHub repository
Project Technology Overview
NXP LPC54018 IoT Module (OM40007)
The NXP LPC54018 IoT Module (Figure 1) is a development board that can be used to develop and
test IoT applications in either stand-alone or cloud-connected environments. The board lets developers create
IoT applications using a variety of input/output interfaces available on the LPC540xx MCU family of
microcontrollers.
Figure 1: LPC54018 IoT Module (OM40007)
More detailed information about the board can be found here.
NXP IoT Module Base Board (OM40006)
The NXP IoT Module Base Board (Figure 2) is designed to provide easy access to the peripherals
on the LPC54018 IoT Module. It also provides additional sensors, actuators, input/output devices, and expansion
connectors, making it a flexible and versatile tool for prototyping IoT applications.
Figure 2: IoT Module Base Board (OM40006)
More detailed information about the board can be found here.
NXP MCUXpresso Integrated Development Environment (IDE)
Firmware programs that run on microcontrollers are typically developed and tested using an Integrated Development
Environment (IDE) running on a personal computer. The IDE provides an editor, compiler, linker, debugger, and a
mechanism for transferring binary program images to the microcontroller.
The LPC54018 module can be programmed using NXP MCUXpresso, an Eclipse-based IDE that runs on Windows, Mac, and
Linux computers. It connects to the OM40006 baseboard using a USB cable that supports programming and debugging
as well as a serial console port connected to the microcontroller. MCUXpresso can be downloaded for free from
the MCUXpresso
site.
NXP MCUXpresso SDK Builder
The MCUXpresso tool suite includes the MCUXpresso SDK Builder
-- a web-based tool used to select and assemble software components and example programs for a particular NXP
target board. We’ll use the SDK Builder to add LPC54018 support code and libraries to our application
project.
Project Application Source Code Files
For this project, the MCUXpresso SDK Builder was used to create an initial set of project source code files that
have been modified and extended to work with the Medium One IoT Prototyping Sandbox. The resulting files are in
a GitHub repository
that you can download and use
for this project. The project files will be imported into the MCUXpresso IDE where they’ll be compiled and
downloaded to the LPC54018 IoT Module. The project files consist of a main application program and supporting
functions for TCP/IP and MQTT protocol processing.
Medium One IoT Prototyping Sandbox
The Medium One IoT Prototyping Sandbox (Figure 3) is designed to help early-stage developers
prototype their IoT project or connect their existing hardware to the cloud. It offers an IoT Data Intelligence
platform, enabling customers to quickly build IoT applications with less effort. Programmable workflows allow
you to quickly build processing logic without having to create your own complex software stack. Configurable
dashboards allow you to visualize application data and view real-time data in a variety of formats.
Figure 3: Medium One IoT Prototyping Sandbox (Source: Author)
IoT devices can exchange data with Medium One through either a REST API or MQTT. More detailed information about
the Medium One IoT Prototyping Sandbox can be found here and you can learn more
about Medium One here.
The Setup (Hardware)
LPC54018 IoT Module (OM40007) and IoT Module Base Board (OM40006)
Remove both boards from their packaging and place on a suitable work surface. Carefully connect the smaller
LPC54018 OM0007 board to the larger OM40006 baseboard using the dual expansion connectors. More detailed
documentation about board setup can be found on the OM40007
and OM40006
websites.
Connect two Type-A to Micro-B USB cables to the J1 and J7 Micro-USB connectors on the OM40006 baseboard and
connect the other ends to the PC. After the USB cables are plugged in. you should see red LEDs illuminate on the
OM40006 baseboard. Connect an Ethernet cable from the RJ45 jack on the OM40006 baseboard to your Ethernet LAN
switch or wall jack.
The Setup (Software)
There are four major parts to the software setup:
- Download and install the MCUXpresso IDE and MCUXpresso SDK
- Download the project application source code files and import them into MCUXpresso
- Set up the Medium One IoT Prototyping Sandbox
- Update the project application source code files to connect to your Medium One IoT Prototyping Sandbox
account
Download and Install MCUXpresso
Web browse to the MCUXpresso
website and navigate to the Downloads section, then click the Download
button. If you don’t already have a NXP login account, register for a new account (free) and complete the
registration process. Once you’re signed in, review and accept the license agreement and you’ll be
taken to the download page. Click MCUXpresso IDE and download the installation package for your
type of PC (Windows, Mac, or Linux). Run the downloaded installer to install MCUXpresso on your computer. After
installation completes, run MCUXpresso to confirm that it is working. You can use the default workspace location
suggested by MCUXpresso. After it launches, you should see the main IDE workspace (Figure 4).
Figure 4: Screen image of the MCUXpresso Main Workspace (Source:
Author)
Download and Import MCUXpresso SDK
Web browse to the MCUXpresso SDK
Builder web site and click
Select Development Board. Expand the Boards > LPC
category, click LPC54018-IoT-Module and then click Build MCUXpresso SDK.
Select your Host OS type and leave Toolchain/IDE set for MCUXpresso
IDE. Click Add software component and click the dropdown menu that initially says
“3 items selected.” Click Select All to select all available components, then click
Save changes. Click Download SDK to initiate the SDK build process. Review and
accept the terms and conditions and then a .zip file should automatically download to your computer. Sometimes,
if many people are building SDKs, it may take some time for the SDK build to complete and the download file to
become available.
Make sure the MCUXpresso Installed SDKs tab is active in the bottom portion of the IDE and drag
& drop the downloaded SDK .zip file into the Installed SDKs tab area. This will import the
SDK into MCUXpresso and afterwards the Installed SDKs list should look like Figure 5.
Figure 5: Screen image after importing the SDK into MCUXpresso (Source:
Author)
Download and Import the Project Application Source Code Files
Web browse to the GitHub repository https://github.com/Mouser-Electronics/ma4_files
and find the lpc54018iotmodule_medium_one_bm_1.0.0.zip file. Click the .zip file, then click
Download to download it to your computer.
In MCUXpresso, select File > Import… > General
> Existing Projects into Workspace and click Next. Checkmark Select
archive file and click Browse… to pick the .zip file you downloaded from
GitHub. Make sure lpc54018iotmodule_medium_one_bm project is check marked and click
Finish. After completing the import, the Project Explorer tab should look like
Figure 6.
Figure 6: After Importing the Project Source Code Files Into MCUXpresso
(Source: Author)
We’ll come back to the source code files after setting up Medium One.
Set Up the Medium One IoT Prototyping Sandbox
Web browse to the Medium One IoT
Prototyping Sandbox and log in,
after which you should see a dashboard resembling Figure 3. Click Setup > Manage
Users > Add New User. Set Username to
lpc54018, create a password of your choice and enter it in both password fields, then click
Save. In the Manage API Users list you should see a new user account having Login ID =
lpc54018 and an auto-generated user MQTT ID like Figure 7.
Figure 7: Newly Created User ID With Auto-Generated MQTT ID (Source:
Author)
Click Setup > MQTT and you should see a Project MQTT ID and a set
of port numbers like Figure 8.
Figure 8: Project MQTT ID (Source: Author)
Medium One uses MQTT usernames and passwords for authentication. The MQTT username is created by combining the
Project MQTT ID, a forward slash, and the user MQTT ID. For example, if the Project MQTT ID is
“ZHxxxxxxx0Y” and the user MQTT ID is “uJxxxxxxxtE” the corresponding MQTT username
would be “ZHxxxxxxx0Y/uJxxxxxxxtE”.
Next we’ll create the MQTT password. Navigate to Setup > Manage API
Keys > Add New API Key. Set the description to lpc54018, make
sure Enabled is check marked, and click Save. The result should look like
Figure 9.
Figure 9: Newly Created API Key (Source: Author)
The MQTT password is created by combining the API Key, a forward slash, and the lpc54018 user password.
For example, if the API Key is “ECxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMBQ” and the lpc54018
user password is “AaaaBbbb3” the corresponding MQTT password would be
“ECxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMBQ/AaaaBbbb3”.
The MQTT topic has the following format: “0/Project MQTT ID/User MQTT ID/Device ID”.
The Device ID field can be anything. We’ll use “lpc54018” as the Device ID. For example, if the
Project MQTT ID is “ZHxxxxxxx0Y” and the user MQTT ID is “uJxxxxxxxtE” the corresponding
MQTT topic would be “0/ZHxxxxxxx0Y/uJxxxxxxxtE/lpc54018”.
The MQTT username, MQTT password, and MQTT topic strings will get added to the project source code in the next
step.
Update Application Source Code Files for Your Medium One Account Parameters
In the MCUXpresso Project Explorer tab, open the source/medium_one.h file and change the string
values for MQTT_USERNAME, MQTT_PASSWORD, and MQTT_TOPIC to
the corresponding strings generated in the previous step.
*** NOTE *** The current version of the SDK libraries do not provide MQTT over TLS and this project uses
unencrypted MQTT communications between the LPC54018 and Medium One MQTT broker. The MQTT username and
password are sent over the Internet and credentials are not encrypted.
Save the modified file, then click lpc54018iotmodule_medium_one_bm under Project
Explorer to select it. In the Quickstart Panel click Build. You should see
compilation messages in the Console tab and the build should finish successfully. At this
point, the application binary is ready to be downloaded to the LPC54018 board.
Run the Application
In the MCUXpresso Quickstart Panel, click Debug. The first time you should see a “Probes
discovered” dialog like Figure 10.
Figure 10: Debug Probe Selection (Source: Author)
Click OK. Debugger download messages should appear in the Console tab and the debugger should
stop at the first line of the main() function. Select menu command Run >
Resume to proceed with program execution. When the program runs, status messages will be
printed to the MCUXpresso console like Figure 11. If you stop the debugger (Run >
Terminate) the program should continue running on the LPC54018 board until it’s powered
off.
Figure 11: Status Messages While the Application Program is Running (Source:
Author)
How the Application Program Works
This program is derived from the lwip_ping_bm example application included in the MCUXpresso SDK. The following
changes and enhancements were made for this project:
- Initialize the LPC54018 and OM40006 base board LEDs and buttons
- Initialize the Accelerometer sensor on the OM40006 baseboard
- Initialize TCP/IP networking and get an Ethernet address using DHCP
- Resolve the Medium One MQTT broker hostname to an IP address
- Connect to the Medium One MQTT broker
- Periodically read the User Button and Accelerometer on the OM40006 baseboard
- Generate a JSON formatted MQTT payload message and send to Medium One MQTT broker
- Wait for the beginning of the next transmission interval (default is 10 seconds)
The program also interacts with push buttons on the OM40006 baseboard:
- Pressing the User Button immediately jumps to the next transmission interval without waiting for the current
time interval to complete
- Pressing the ISP2 button causes transmissions to stop until the User Button is pressed
MQTT Payload Format
MQTT messages are formatted as JSON strings according to the Medium One MQTT payload specification. Here’s
an example message:
{"event_data":{"device":"lpc54018","iteration":7,"clock":516528,"button":false,"x":15,"y":10,"z":518}}
Fields:
- device = the board name
- iteration = application loop counter
- clock = application timer tick counter
- button = status of the User Button: true = pressed, false = released
- x,y,z = accelerometer readings
Try pressing the User button and moving the board around to see the message values change.
View Data in the Medium One Dashboard
In the Medium One dashboard navigate to Data Viewer > Data Streams and click
raw Events. You should see raw messages (Figure 12) being received from the
LPC54018. Click the “+” sign to view message details.
Figure 12: Raw Message Display (Source: Author)
Click Dashboard on the top left, then click Add Widget > Single User
Real Time Events Stream to add an event stream widget to the dashboard.
In the Select user dropdown, select lpc54018. You should now see messages
appearing in the Real Time Events Stream widget (Figure 13). Click the save icon in the upper right corner to
save your modified dashboard.
Figure 13: Real Time Events Stream Widget Display (Source: Author)
Add More Widgets
To display more widgets, we need to enable specific data fields contained in the message payload. Navigate to
Config > Data Streams and click on raw Events. The Schema
Map should be pre-populated with fields detected in the incoming messages, though they are currently disabled.
Checkmark the Active box on raw.button, raw.clock,
raw.iteration, raw.x, raw.y, and raw.z, then
click Save Data Stream. These fields are now available for use in other dashboard widgets.
Back on the dashboard, click the Single User Last Value Table widget and select the
lpc54018 user within the widget. Click the widget’s Tag Config icon to
the right of lpc54018 user selection and check-mark raw:button, raw:clock,
raw:iteration, raw:x, raw:y, and raw:z
values, then click Save. The Last Value Table should now populate with the most recent received
values for each field (Figure 14). Click the Save icon towards the upper right corner to save
the updated dashboard.
Figure 14: Last Value Table Widget Display (Source: Author)
Now let’s add dashboard widgets for the 3-axis accelerometer. Click Single User Real Time
Gauge and select the lpc54018 user. Click the widget’s Tag
Config icon and checkmark the raw:iteration, raw:x,
raw:y, and raw:z rows, then click Save. The updated dashboard
should look like Figure 15. Click the dashboard save icon to save the updated dashboard. Try
rotating the OM40006 base board to see the accelerometer values change.
Figure 15: Real Time Gauge Widgets Added to Dashboard (Source: Author)
Remember to power off the OM40006 baseboard when you’re done, otherwise the board will continue to send
messages to Medium One and consume daily message allotments.
Where to Go Next
This project created an end-to-end sensor-to-cloud application that sends real-time sensor data to the Medium One
IoT Prototyping Sandbox. It can be modified and extended in a number of ways and here are a few examples:
- Dive deeper into the application code by reading the MCUXpresso SDK documentation and studying the source
code
- Learn more about the LPC54018 IoT Module (OM40007) and IoT Module Base Board (OM40006) by reading the User
Manuals and studying the source code
- Use the Wi-Fi interface on the LPC54018 IoT Module
- Add more widgets to the Medium One dashboard
- Learn about the Medium One Workflow Studio, which lets you create data processing workflows to transform
your sensor data
- Experiment with the Medium One mobile apps
- Implement bi-directional communications with the Medium One cloud
- Modify the sensor data publishing interval by modifying the LPC54018 application source code
- Read other sensors on the OM40006 base board and include the data in MQTT messages
- Display information on the OM40006 base board’s LCD display
- Include a timestamp in the sensor data message
- Enhance the MQTT communications to support MQTT over TLS
Greg is an architect, engineer and
consultant with more than 30 years experience in sensors, embedded systems, IoT, telecommunications, enterprise
systems, cloud computing, data analytics, and hardware/software/firmware development. He has a BS in Electrical
Engineering from the Univ. of Notre Dame and a MS in Computer Engineering from the Univ. of Southern California.