Welcome to the maker train workshop at FAB25.
Before we begin, if you just unbox your Thingy:91 X for the first time. You might want to try the preloaded firmware that already come with the device.
Chris Wilson already made an excellent guide on how you could use the preloaded firmware on this page. I recommend you to try this before we are starting with our workshop to get the better understanding of the Device that we are going to use for this workshop.
This workshop will be focused on the programming for Thingy:91 X using nRF Connect SDK.
The nRF Connect SDK is a software development kit for building low-power wireless applications based on Nordic Semiconductor’s nRF54, nRF53, nRF52, nRF70, or nRF91 Series devices.
It integrates the Zephyr Real-Time Operating System (RTOS) and a wide range of complete applications, samples, and protocol stacks such as Bluetooth Low Energy, Bluetooth mesh, Wi-Fi, Matter, Thread/Zigbee and LTE-M/NB-IoT/GPS, TCP/IP. It also includes middleware such as CoAP, MQTT, LwM2M, various libraries, hardware drivers, Trusted Firmware-M for security, and a secure bootloader (MCUBoot).
Zephyr RTOS is an open-source real-time operating system for connected and resource-constrained embedded devices. It includes a scheduler that ensures predictable/deterministic execution patterns and abstracts out the timing requirements.
Before starting this workshop there are few prerequisite things that you need to do on your own before you hop on the train.
0. Prerequisite1. Installl SEGGER J-Link v8.18 from this link based on your platform/operating system.
when you reach this page be sure to select ‘Install Legacy USB Driver for J-Link’, this is necessary driver for the Thingy:91 X
2. Install nrfutil and the nrfutil device command
Download the binary compatible with your OS from this link and store it somewhere on your disk drive (For example C:\nrfsdk\nrfutil.exe
for Windows)
(Windows) Update your system’s PATH to include the location where nrfutil is stored. Open Edit environment variable for your account and add the path where you stored the nrfutil binary, as shown below:
If you are running on macOS or Linux, you can store it in a folder that is already added in the system’s PATH (E.g. /usr/bin/ )
And for linux user be sure to check the requirement based on this page
Make sure we have the latest nrfutil version, run the following command in a terminal (Command Prompt or PowerShell)
nrfutil self-upgrade
next we need the device command to install the binaries to the Thingy91: X. in the same terminal type
nrfutil install device
You should the following output
[00:00:03] ###### 100% [Install packages] Install packages
3. Install VS Code with nRF Extension Pack
Visit this link and install VS Code based on your operating system.
Open the VS Code application, In the Activity Bar, click the Extensions icon, then type nRF Connect for VS Code Extension Pack in the search field, and click on Install, as shown in the illustration below:
It’s important to install the nRF Connect for VS Code Extension Pack, in order to get all the available features. And to move on for the next step
4. Install Toolchain
Click on Install Toolchain. It will list the available versions of toolchains that can be downloaded and installed on your machine. For this workshop we will be using the toolchain that have support for the Thingy:91 X, so you need Select the toolchain version 3.0.1 for this part
5. Install nRF Connect SDK
In nRF Connect for VS Code, click on Manage SDKs. Click on Install SDK. It will list the available versions of the nRF Connect SDK that can be downloaded and installed on your machine. Choose the nRF Connect SDK version 3.0.0.
If you have opened the SDK folder in VS Code, the Manage SDKs menu option will not be present, and you will instead see Manage west workspace. To fix this, open another window or folder in VS Code.If you don’t see either options, make sure you have the latest version of the nRF Connect for VS Code extension pack.
With this, you have completed the installation of nRF Connect SDK and VS Code.
6. Install nRF Connect for Desktop
Since the Thingy:91 X Serial Port can't be recognized directly in VS Code We are going to need install nRF Connect Desktop to view the serial output data.
Go to this link and install the desktop app
Open the nRF Connect for Desktop and install these App
Do remember to do this setup before you start because the installation process could take quite some time to do.
7. Download the sample code
Once you are done with the installation open this github page and download it as zip. Extract it on your local drive and we will use this code for our workshop
1. Building your first applicationCreate a new folder close to the root of your directory and name it "makertrain" so it will look like C:\workshop\makertrain. This folder will be use to store our exercise for this workshop.
In VS Code, click on the nRF Connect Extension icon. In the WELCOME View, click on Create a new application.
In the Create new application, select Copy a sample
Type blinky in the search field and select the second Blinky sample (with the path zephyr/samples/basic/blinky
) like below.
Input the full path for where you want the application to be stored and name it as "blink". for example "C:\workshop\makertrain\blink"
When you have input the full path, press enter.
VS Code will ask if you want to open the application in the same VS Code instance or open a new VS Code instance. Select Open to open the application in the same VS Code instance.
This will make a copy of the template selected “Blinky sample”, store it in the application directory you specified, and add an unbuilt application to VS Code as shown below:
Before we build the application we need to enable mcuboot. Open the explorer menu on vscode and open the prj.conf file and add this line to the file
CONFIG_BOOTLOADER_MCUBOOT=y
This part is necessary for flashing the Thingy:91 X with our new application
One of the many advantages of the nRF Connect SDK is the high decoupling between the application source code and the software configuration/hardware description, making it extremely easy to switch the build for a new hardware or software configuration.
In the APPLICATIONS view, click on Add Build Configuration under the application name.
at the build configuration page make sure you choose the setup just like the image below
and then at the bottom of the configuration screen click the Generate and Build Button.
This part could take a while. While we wait I will briefly share about zephyr and nrf connect SDK.
After the build is done you should see a new folder called build is created.
Click the the three dots. and choose StartNewTerminal.
now We are going to flash our blink app that we just build to the Thingy:91X. in the terminal type the following command
nrfutil device list
The Nordic Thingy:91 X will be listed as a Thingy:91 X UART product and have the following details: mcuboot
, nordicUsb
, serialPorts
, and usb
traits.
A 21-character J-Link serial number, for example, THINGY91X_CA407B37EF1.
take note on your J-link Serial Number, we are gonna use it for the following command
nrfutil device program --firmware dfu_application.zip --serial-number <J-Link Serial number> --traits mcuboot --x-family nrf91 --core Application
Change the J-Link Serial Number with your own Serial Number
Press enter and now you should see the LED is blinking on your device.
Now let's try to make the LED blink faster by manipulating the delay timing. Go back the explorer menu and open main.c file in src folder.
Change the SLEEP_TIME_MS value to 100.
Go back to nrf connect menu and rebuild the application by clicking this icon
after the build is finish do the same flashing command again then you will see The LED is blinking faster
2. Reading button to control LEDFrom the Welcome View in the nRF Connect extension, click on Open an existing application.
Select the base code for this exercise, found in of whichever version you are using, and click on Select Folder.
Open main.c
from the Explorer in VS Code as shown in the screenshot below:
Get the node identifier for button 1 through its alias sw0
.
Recall from the Devicetree section, that the /aliases
node in the DK devicetree defined the alias sw0
for node &button0
. The line below uses the macro call DT_ALIAS()
to access the node identifier for the node through its alias
#define SW0_NODE DT_ALIAS(sw0)
The GPIO API has the struct called gpio_dt_spec that encapsulates all this information, and can be retrieved using GPIO_DT_SPEC_GET()
.
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET(SW0_NODE, gpios);
This line uses the macro GPIO_DT_SPEC_GET()
to populate the members of the gpio_dt_spec
variable with:
- The device pointer:
const struct device *port
- The pin number:
gpio_pin_t pin
- The pin’s flags:
gpio_dt_flags_t dt_flags
It is important to verify that the device is ready to use by calling device_is_ready()
before using it.
if (!device_is_ready(button.port)) {
return -1;
}
Configure the pin connected to the button to be an input pin and set its hardware specifications.
ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
if (ret < 0) {
return -1;
}
In the main loop of our exercise, we will indefinitely poll the CPU to read the status of the button (pressed = 1, unpressed = 0) and update the LED to the status of the button.
Using gpio_pin_get_dt()
, read the current status of button.pin
and save it in the variable val
.
bool val = gpio_pin_get_dt(&button);
Update the LED to reflect the current status of the button that was saved in the variable val
in the previous step, using gpio_pin_set_dt()
.
gpio_pin_set_dt(&led,val);
after
everything is set don't forget to enable the mcuboot in prj.conf file
Add a build configuration, like we did in the previous section
Build the exercise and flash it to the board as we have done in the previous lesson.
Make sure you are in the right build folder
Observe that when button 1 is pressed, LED1 is turned ON.
3. Read the onboard sensor DataThe Thingy:91 X is packed with a lot additional components. And one of it is the Air Quality BME 680 Sensor.
In this session we are going to try to read the sensor data using nRF Connect SDK.
Before building the application we need to install the driver for the sensor. Open the terminal in vscode from previous the previous section and type these two command.
west config manifest.group-filter +bsec
west update
After the installation is finished open the airquality
folder from this menu
Open the prj.conf in the explorer menu and you can see that there a lot of necessary configuration that need to be enable in order to use the sensor
And also there's a new folder called boards.
This folder contain the overlay file that is necessary for us to build this application.
Go back to the nRF SDK connect and build the application with the following configuration.
Notice that we are adding the Devicetree overlays file. Make sure you choose the Thingy:91 X and build it.
After the buiild is finished Start new terminal in build folder from the airquality parent folder and flash it to the Thingy:91 X
To see the sensor reading data open nRF Connect for Desktop App and choose the Serial Terminal
In the serial terminal click the SELECT DEVICE
button and choose Thingy:91 X
wait for a few seconds and you will see the air quality data presented on the screen.
The Nordic Thingy:91 X has a low-power three-axis accelerometer, a six-axis inertial measurement unit (IMU), and a three-axis magnetometer for sensing motion and orientation.
In this part we are going to focus on reading the IMU data.
An inertial measurement unit (IMU) is a device that uses various sensors to capture data about an object's motion, location and orientation.
.Just like the previous part open a new application
Open the imureading
folder and you will your new app ready to build and configure
Click the add build configuration button do the same setup just like the previous excercise then build the application
While we wait for the application to finish its build, let's take a look at few part of the code and configuration.
The sensor is using SPI interface and we can see in.overlay file it uses the SPI3 bus.
in the main.c code we also doing a calibration to get the precise data of the IMU
After the build is finished repeat the flashing command just like before
Open the serial terminal in the nRF Connect for desktop and you should this result
now try to move or shake the Thingy:91 X and you should see the numbers changing based on your movement.
ConclusionThat wraps up our "On Track with Thingy:91 X" workshop! We've covered a lot, from setting up your development environment with nRF Connect SDK and VS Code, to building your first "blinky" application. You've also learned how to read button inputs, extract data from the BME 680 air quality sensor, and interpret readings from the IMU.
If you are planning to learn more than we are covering today, take the nRF Connect SDK Fundamental and Celullar IOT Fundamental course at:Nordic Developer Academy
Hopefully, this workshop has equipped you with the foundational skills and confidence to continue exploring the vast possibilities of IoT development with the Nordic Thingy:91 X. Remember, the nRF Connect SDK is a powerful tool, and there's always more to learn and build.
Comments