Getting Started with nRF52840-DK
This guide teaches you how to get started using the nRF52840-DK with Atmosphere. This includes creating your first project, programming the project’s firmware into the nRF52840-DK, registering the device to Atmosphere, and having its data displayed on a dashboard.
In the guide you’ll build a simple project that reads temperature and pressure data, displays that data on the mobile app, and then sends the readings to the cloud.
Prerequisite: You should already have an Atmosphere account.
The nRF52840-DK doesn’t include any onboard sensors, so we’re pairing it with the STMicroelectronics X-NUCLEO-IKS01A3 motion and environmental sensor shield to read sensor data from it. Each of this shield’s sensors contains a dedicated element for it, which are located within the Studio Element Library.
- Atmosphere IoT app. The mobile app is used here to register your device, and display and run the project’s interface. You can download the Atmosphere IoT app from its downloads page or through the Apple App Store or Google Play Store.
- Ensure Bluetooth is enabled on the mobile device you’ll use to interact with the nRF52840-DK.
Step 1 of 9: Create a New Project
Navigate to Atmosphere Studio from the side menu. When you visit Studio for the first time in a session, you are brought to the Studio Projects screen.
- Click the button. This displays a New Project window.
- Select the nRF52840-DK project type and give the project a name, then click Create.
This opens a new project in Studio.
This guide walks through the step-by-step process to perform actions in Studio, but doesn't cover the in-depth aspects of Studio itself. To learn more about using Studio, its areas and features, and Studio elements, visit the Atmosphere Studio section.
Step 2 of 9: Import Elements from the Element Library
Prior to building the project, the proper elements have to be added into Studio’s Element Toolbox. The project involves integrating the STTS751 temperature sensor and LPS22HH pressure sensor from the sensor shield, which aren’t native to nRF52840-DK projects. So we’ll add them through the Studio Embedded tab’s Element Library.
- From the Embedded tab, click the Add Element button located in the bottom of the Element Toolbox. This opens the Element Library, which includes numerous elements for sensors and other devices that can be incorporated into a project.
- In the Element Library, locate the X-NUCLEO-IKS01A3 sensor shield element(s), specifically the STTS751 temperature sensor and LPS22HH pressure sensor, and turn on the enable switch in their rows. When done click Save, and the elements are added into the Embedded tab’s toolbox.
Step 3 of 9: Create the Project’s Embedded Firmware
The first aspect of building this sample project is adding elements to the Embedded tab to create the project’s embedded firmware. This involves setting an interval to read embedded data, and to tell the interval to read the sensor shield’s temperature and pressure sensors.
- Add the following elements to the canvas by clicking them in the Element Toolbox:
- Interval element: The interval element sets the project to run at the time set in the element’s properties, which by default is set to once per second (1000 ms).
- STTS751 element: The STTS751 element reads the temperature sensor data from the X-NUCLEO-IKS01A3 sensor shield.
- LPS22HH element: The LPS22HH element reads the pressure sensor data from the X-NUCLEO-IKS01A3 sensor shield. Each of these elements will work as intended by default, so none of their properties need to be changed.
- Connect the interval element to the STTS751 element. This creates an event between them, which can be seen in either the interval element’s properties, or by clicking the connector’s button. The event added is within the
Intervaltrigger. In the STTS751 element’s ability field within the event, set the ability to
Read Temperature (°C). This means that when the interval element is triggered (which is every second), it will read the temperature value.
- Connect the interval element to the LPS22HH element. Like the STTS751, an event is added within the
Intervaltrigger. In the LPS22HH element’s ability field within the event, set the ability to
Read Pressure. Like the temperature sensor, when the interval element is triggered it will read the pressure value.
- Add two BLE characteristic elements to the canvas. This element creates a GATT characteristic to use in your project, and is a coupled element that bridges the project between the Embedded tab and Application tab, meaning it’s included on both tabs. In each BLE characteristic element’s properties, change the Read Data Type and Write Data Type fields to
Floating Point (32-bit). This allows the elements to read and write floating point values, which are the temperature and pressure values that will eventually be sent through them. You’re encouraged to give these elements (as well as any other elements) custom names that represent what they do or what data they are passing through, such as naming them “Temperature” and “Pressure” respectively.
- Connect the STTS751 element to the first BLE characteristic element, which ties the value of the temperature sensor to the Application tab. This creates an event between the two elements in the
Temperature Readtrigger, with the ability
Set Value. This sets a value for the project’s interface after it reads the temperature sensor data.
- Lastly, connect the LPS22HH element to the second BLE characteristic element, which ties the value of the pressure sensor to the Application tab. This creates an event between the two elements in the
Pressure Readtrigger, with the ability
Set Value. This sets a value for the project’s interface after it reads the pressure sensor data.
That wraps up the first aspect of the project within the Embedded tab. To this point, an interval has been set that will run once per second after the project opens, and when run will read the temperature data from the sensor shield’s temperature sensor and pressure data from the shield’s pressure sensor. That data will then be sent from the BLE characteristic elements to the mobile app via the Application tab.
The Embedded tab canvas should resemble the following image:
Step 4 of 9: Create the Project’s Interface
The second aspect of building this sample project is adding elements to the Application tab to create the project’s visual component. Here we’ll create a basic interface, pairing the sensor values sent from the Embedded tab with label elements to display their values on labels inside the mobile app.
Click the Application tab to move to the application area of the project. Notice how the Element Toolbox has changed, and that the coupled BLE characteristic elements are displayed on the canvas.
- Click the button in the Application tab’s toolbar to display the app builder. This area creates the visual interface for your project. By default this uses the smallest display size supported for an interface (320x560), but you can add an interface size by clicking the button. Use the display size that fits best with your mobile device.
- Add an interval element to the canvas, and connect it to both of the BLE characteristic elements. Within the interval element’s trigger properties, set each BLE characteristic’s event ability to
Intervaltrigger, which reads the value of the BLE characteristic element sent from the Embedded tab every time the interval triggers.
- Add two label elements to the canvas. The label element displays text on a project’s interface. Notice when the label is added to the canvas, a corresponding interface component is added to the app builder. The label component can be moved around on the interface wherever you like.
- Connect the BLE characteristic element carrying the STTS751 data to the first label element. This creates an event between the two elements of
Set Textunder the
Readtrigger, which sets the text to the value of the label when the BLE characteristic is read. This correlates the set value from the BLE characteristic element in the Embedded tab to the label on the interface. Within the Set Text event, modify the Text field to
"Temperature:" + readData.toFixed(2). This argument reads the temperature data and truncates the value to two decimal places.
- Connect the BLE characteristic element carrying the LPS22HH data to the second label element. Like the other element, this creates an event of
Set Textunder the
Readtrigger. Within the Set Text event, modify the Text field to
"Pressure:" + readData.toFixed(2).
This is all that needs to be done for the project’s interface, simply using a label to display two text values. To this point, an interval has been set that will read the BLE characteristic values once per second, which will display the read temperature and pressure values on the two interface labels.
The Application tab’s canvas should resemble the following image:
Step 5 of 9: Enable the Project’s Cloud Connectivity
The last aspect of building this sample project is enabling it for cloud connectivity. This is done on both the Application and Cloud tabs.
- While still in the Application tab, add two cloud event elements to the canvas. The cloud event element is a coupled element between the Application and Cloud tabs that enables a project’s data to be sent to Atmosphere.
- Connect the BLE characteristic element carrying the STTS751 data to the first cloud event element. This adds the
Send Eventevent to the
Readtrigger, which sends the set value data to Atmosphere when the BLE characteristic is read. Then connect the second BLE characteristic element carrying the LPS22HH data to the remaining cloud event element, which produces the same event.
- Click the Cloud tab to move to the cloud area of the project. Notice how the Element Toolbox has changed, and that the coupled cloud event elements are displayed on the canvas.
- Add two cloud storage elements to the canvas, and connect a cloud event element to each of them. By default, this creates an event using the
Add Dataability within the cloud event’s
Event Receivedtrigger, which allows Atmosphere to add (and store) data sent to it from the connected cloud event element.
That’s all for creating the project! With the added cloud connectivity, the project will send the temperature and pressure values from the Embedded tab to the Application tab, which then uses two cloud events to send the data to the Cloud tab, where they are connected to cloud storage elements to store the data on Atmosphere.
The final canvas for each tab should resemble the following images:
Step 6 of 9: Compile the Project
Once the project is finished, it needs to be compiled. Compiling readies the entire project’s source code for deployment.
- From any tab, click the button in the project options menu on the top-right of the screen. You’ll see a loading message on the screen indicating compiling has started, and will be notified when the project is compiled.
Step 7 of 9: Program Firmware into the Device
With the project compiled, your nRF52840-DK can be programmed with the project’s embedded firmware.
Powering the Board
Powering the nRF52840-DK involves having the proper settings for the various switches on the board. For reference material, see the Nordic nRF52840-DK User Guide for information on all aspects of the board.
- To power the board on, ensure the following switch states are set:
- nRF Only Switch: set to Default (section 8.4.2 of guide)
- Power Source Switch: set to VDD (section 8.3.4 of guide)
- Power Switch: set to ON
- When powering the board, connect it using the USB port located on the short side of the board (near the battery).
Once the board is powered on, ensure you have the following configuration for programming:
- The nRF52840-DK is connected to the computer via USB to an available communication port. When connected, the nRF52840-DK will expose itself as a drive labeled “DAPLink.”
With setup complete, you can program your board:
- While the Embedded tab is active, click the button from the tab’s toolbar. This downloads a .hex file containing the project’s compiled firmware.
- Locate the downloaded file on your computer, and move it into the DAPLink drive. This initiates programming of the nRF52840-DK.
- Once programming is finished, the DAPLink drive will unmount and then mount again indicating programming is complete. Then press the board’s reset button to start your project.
When complete, the nRF52840-DK is programmed with the project’s embedded firmware.
Step 8 of 9: Register the Device
With firmware installed, the device can now be recognized and connected to Atmosphere. From here, open the Atmosphere IoT app on your mobile device. We’ll use the mobile app to both register the device, and eventually view the label data on the project’s interface.
To register the nRF52840-DK:
- Navigate to the Devices area, and click the button in the top-right of the screen to display the Add Device window. When the window opens it automatically starts scanning for available devices within range.
- Ensure your nRF52840-DK is within range from the mobile device you are attempting to register from, otherwise it may not appear.
- The list of available devices appears. Select your nRF52840-DK you just programmed and it will connect to Atmosphere.
The device is now registered to Atmosphere and added to the Devices area. The app interface you created is displayed on the screen, with device data immediately shown on it.
Step 9 of 9: View Device Data
Now that the device’s data is sent to Atmosphere, let’s view it through one of the many dashboard widgets available. In this guide we’ll use a data glance widget to display the pressure data, and a data graph widget to chart the temperature data.
We’ll do this directly on the device’s console page, so click on the newly-added nRF52840-DK to enter its console.
- To add a widget to the device’s dashboard, click the button on the right side of the screen. This displays the menu of available widgets. Select the data glance widget to add a data glance to the dashboard.
- Once on the dashboard, click the widget’s menu icon to display its menu, then click Settings.
- In the data glance’s settings, modify the following properties:
- Name: Give the widget a name, such as “Pressure Data.”
- Units: Enter
hPafor its unit of measurement.
- Icon: Select an icon that represents the data, such as the
- Color: Give the widget a color that represents the data.
- In the Data Source field, click Select, then choose the following configuration options for the widget:
- Select Cloud Storage: Click the cloud storage (
PressureStorage, or whatever you named your cloud storage) that is storing the LPS22HH pressure data.
- Select Value: Select the pressure dataset (
Pressure, or whatever you named your pressure data).
- Select Cloud Storage: Click the cloud storage (
- When finished click Save. The data glance is then populated with the pressure value, which updates every second.
- Now add a data graph widget to add a graph to the dashboard, then go to its settings.
- Give the data graph a name (such as “Temperature Data”), then in its Data Source field click Select and choose the following configuration options for the widget:
- Cloud Storage: Select the cloud storage (
TemperatureStorage, or whatever you named your cloud storage) that is storing the STTS751 temperature data.
- X-axis Value: Select the timestamp to go along the graph’s x-axis.
- Y-axis Value: Select the temperature dataset to go up the graph’s y-axis.
- Cloud Storage: Select the cloud storage (
- When finished click Save. This populates the data graph plotting the temperature value as time progresses. If you’d like to adjust the graph’s timeline or its bounds, you can edit those properties from the data graph’s menu as well.
Congratulations, you just finished a complete nRF52840-DK project with Atmosphere!