Scaling an IoT deployment? Join our webinar on May 28th where we dive into real-world scaling pain points and how to overcome them.

Blues Developers
What’s New
Resources
Blog
Technical articles for developers
Newsletter
The monthly Blues developer newsletter
Terminal
Connect to a Notecard in your browser
Developer Certification
Get certified on wireless connectivity with Blues
Webinars
Listing of Blues technical webinars
Blues.comNotehub.io
Shop
Docs
Button IconHelp
Notehub StatusVisit our Forum
Button IconSign In
Sign In
Sign In
Docs Home
What’s New
Resources
Blog
Technical articles for developers
Newsletter
The monthly Blues developer newsletter
Terminal
Connect to a Notecard in your browser
Developer Certification
Get certified on wireless connectivity with Blues
Webinars
Listing of Blues technical webinars
Blues.comNotehub.io
Shop
Docs
Guides & Tutorials
Collecting Sensor Data
IntroductionSet up HardwareCreate a Notehub ProjectWrite FirmwareView Data in NotehubUse Environment VariablesNext Steps
Routing Data to Cloud
Building Edge ML Applications
Best Practices for Production-Ready Projects
Twilio SMS Guide
Fleet Admin Guide
Using the Notehub API
Notecard Guides
Guide Listing
Asset Tracking
Attention Pin Guide
Connecting to a Wi-Fi Access Point
Debugging with the FTDI Debug Cable
Diagnosing Cellular Connectivity Issues
Diagnosing GPS Issues
Encrypting and Decrypting Data with the Notecard
Feather MCU Low Power Management
Minimizing Latency
Notecard Communication Without a Library
Recovering a Bricked Notecard
Remote Command and Control
Sending and Receiving Large Binary Objects
Serial-Over-I2C Protocol
Understanding Environment Variables
Understanding Notecard Penalty Boxes
Updating ESP32 Host Firmware
Using External SIM Cards
Using JSONata to Transform JSON
homechevron_rightDocschevron_rightGuides & Tutorialschevron_rightSensor Tutorial with C/C++ (Arduino/Wiring), Artemis Thing Plus, and Sparkfun Qwiic Cellular

Collecting Sensor Data
- C/C++ (Arduino/Wiring), Artemis Thing Plus, and Sparkfun Qwiic Cellular

Get started with:
C/C++ (Arduino/Wiring)
C/C++ (Arduino/Wiring)C/C++ (STM32Cube)CircuitPythonPython
and
Artemis Thing Plus
Artemis Thing PlusAdafruit Feather M4 ExpressAdafruit HUZZAH32Arduino Nano 33 BLE SenseBlues SwanRaspberry PiSparkFun MicroMod STM32 ProcessorSTM32 DiscoverySTM32 Nucleo
and
Sparkfun Qwiic Cellular
Sparkfun Qwiic CellularNotecarrier ANotecarrier FNotecarrier PiSparkFun MicroMod Cellular Function Board

Don't see your favorite hardware here? Rest assured the Notecard works with virtually every MCU and SBC available. If you can't figure out how to complete this tutorial let us know in our forum and we can help you out.

Introduction

This tutorial should take approximately 40-50 minutes to complete.

In this tutorial, you'll learn how to take sensor readings from a Device and send readings to your Notecard and the Blues Notehub. You'll use C/C++ (Arduino/Wiring) running on a Artemis Thing Plus wired up to Sparkfun Qwiic Cellular hardware. If you would like to use a different language, board, or Notecarrier, modify the dropdowns at the top of this guide. And if you get stuck at any point, the full source code for each example is available on GitHub .

The tutorial uses mock sensor readings for simplicity, but feel free to hook up a physical sensor of your choice and use that instead.

Set up Hardware

First, you'll need to get all of your hardware connected. Follow the instructions below to connect your Artemis Thing Plus and Notecard mounted on a Sparkfun Qwiic Cellular.

In order to complete this guide, you'll need the following:

  • Notecard mounted to Sparkfun Qwiic Cellular Notecarrier.
  • Any Arduino-capable Microcontroller (MCU) with a Qwiic connector. We will be using the SparkFun Artemis Thing Plus , but any MCU that can be programmed with the Arduino IDE will do.
  • USB-C to USB-A cable.
  • 2 Qwiic connector cables .
  • Your sensor of choice. We will be using the SparkFun Environmental Combo Breakout because it includes a BME280 , but you're welcome to use any sensor and adapt the code in this guide to read from your sensor instead.

NOTE: For this tutorial, you'll be powering the Notecard through the USB-C connection of your Artemis Thing Plus. Some Arduino-compatible devices cannot handle 2 Amp pulses from the Notecard when connected to GSM, so if you experience resets or other power-related issues, we suggest powering your Notecard separately through the USB or LiPo connector on the Notecarrier.

Connect the sensor to your Sparkfun Qwiic Cellular Notecarrier

First, let's connect Environmental Combo Breakout to your Sparkfun Qwiic Cellular Notecarrier.

  1. Plug one end of the Qwiic connector cable into one of the Qwiic JST terminals on the Environmental Combo Breakout. You can plug the cable into either terminal and the cable can only be plugged in one way.

  2. Plug the other end of the Qwiic connector cable into either of the Qwiic JST terminals on the Sparkfun Qwiic Cellular Notecarrier.

Connect the Artemis Thing Plus to your Sparkfun Qwiic Cellular Notecarrier

Now, let's connect your Notecarrier using the I2C Qwiic connector.

  1. Plug one end of the Qwiic connector cable into the Qwiic JST terminals on the Artemis Thing Plus. You can plug the cable into either terminal and the cable can only be plugged in one way.

  2. Plug the other end of the Qwiic connector cable into the open Qwiic JST terminal on the Sparkfun Qwiic Cellular Notecarrier.

note

When powering up, the Notecard requires a small burst of energy, which cannot be adequately supplied via the Qwiic connector. The Notecarrier has both a USB port and JST connector (for a battery) to supply power directly to the Notecard and support this burst.

Create a Notehub Project

Now that your hardware is all connected, let's create a new Notehub project to receive sensor readings from your Notecard.

  1. Navigate to notehub.io and log-in, or create a new account.

  2. Using the New Project card, give your project a name and ProductUID.

    How to create a new Notehub project

    note

    The ProductUID must be globally unique, so we recommend a namespaced name like "com.your-company.your-name:your_product".

  3. Take note of your ProductUID. This identifier is used by Notehub to associate your Notecard to your project.

    Where to find your product UID

Write Firmware

Configure the Arduino IDE

For this portion of the guide, we'll be using the Arduino IDE, so be sure to install version 2.0+ if you haven't already.

Once installed, we'll need to add support for your Artemis Thing Plus Board.

Configure the Arduino Boards Manager to use the Artemis Thing Plus

  1. Start the Arduino IDE and open the Preferences menu.

  2. Copy the following path https://raw.githubusercontent.com/sparkfun/Arduino_Apollo3/main/package_sparkfun_apollo3_index.json into the "Additional Board Manager URLs" field. If there's already something in the box, then add a comma to separate the URLs.

  3. Click OK, then open the Boards Manager from the Tools > Board: [board name] > Boards Manager... menu.

  4. Search for "apollo" and click the Install button to add Apollo board support to the Arduino IDE.

  5. Once the installation is complete, click the Close button.

  6. Next, plug your Artemis Thing Plus device back in, open the Arduino IDE, select SparkFun Artemis Thing Plus from the Tools > Board menu, and select the appropriate Port for your device.

Communicating With Your Notecard

When communicating with the Notecard over I2C, you'll want to use the note-arduino library . The code snippets below provide everything you need to talk to the Notecard over I2C in Arduino.

note

The SparkFun Qwiic Cellular provides an I2C connection between the Notecard and an MCU host via a built-in Qwiic connector; if you prefer to communicate with the Notecard over a Serial connection, you can use the TX/RX pins on the Qwiic Cellular board.

Install the Notecard Arduino Library

  1. To use the note-arduino library , you'll need to add it to the Arduino IDE.

  2. Click on Tools > Manage Libraries...

  3. Search for "Blues" in the input box and click the "Install" button next to the "Blues Wireless Notecard" result.

    Installing the Blues Wireless Notecard library.

  4. Create a new sketch and select the Sketch > Include Library > Contributed Libraries > Blues Wireless Notecard menu option, to add the following include to your sketch:

    #include <Notecard.h>

Set Up Your Notecard

  1. Now, configure a Serial interface. You'll use this interface to log information later in your code.

    #define usbSerial Serial
  2. Next, add a definition for your ProductUID using the value you specified when creating your Notehub project.

    #define productUID "com.your-company.your-name:your_product"
  3. Above the setup() and loop() functions, declare a global object to represent the Notecard.

    Notecard notecard;
  4. In the setup() function, initialize the usbSerial object and tell the Notecard library to use this serial object for sending debug output.

    delay(2500);
    usbSerial.begin(115200);
  5. Initialize an instance of the Notecard class and initialize an I2C connection to the Notecard using the notecard.begin() function. Then, use setDebugOutputStream() to link the debug output to usbSerial with the following code:

    notecard.begin();
    Wire.setClock(10000); // Artemis I2C requires "slow mode" for clock stability
                         // https://forum.sparkfun.com/viewtopic.php?t=52301#p214140
    notecard.setDebugOutputStream(usbSerial);
  6. Now, we'll configure the Notecard. Using the hub.set request, we associate this Notecard with the ProductUID of your project and set the Notecard to operate in continuous mode, which indicates that the device should immediately make a connection to Notehub and keep it active.

    {
      J *req = notecard.newRequest("hub.set");
      if (req != NULL) {
        JAddStringToObject(req, "product", productUID);
        JAddStringToObject(req, "mode", "continuous");
        notecard.sendRequest(req);
      }
    }

    The lines above build-up a JSON object by adding two string values for product and mode, and then fires the request off to the Notecard with the sendRequest() function.

  7. Open the Arduino Serial Monitor. If everything has been connected and configured properly, you'll see a few debug messages, including the JSON object you sent, as well as the response from the Notecard {}

Read from the sensor

Now that you've configured your Artemis Thing Plus to communicate with the Notecard, let's grab sensor readings from the BME280. First, you'll need to install the SparkFun BME280 library for use in the Arduino IDE.

  1. Click on Tools > Manage Libraries...

  2. Search for "SparkFun BME280" in the input box and click the "Install" button next to the "Blues Wireless Notecard" result.

    Installing the SparkFun BME280 library

  3. Once the installation completes, add an include for the BME280 library header to the top of your project.

    #include <SparkFunBME280.h>
  4. Outside of the setup and loop functions, declare a global object to represent the BME sensor.

    BME280 bmeSensor;
  5. In setup, add the following to initialize the sensor and log a successful connection or failure to the Serial console.

    if (bmeSensor.beginI2C() == false) {
       usbSerial.println("Could not find a valid BME280 sensor...");
    } else {
       usbSerial.println("BME280 Connected...");
    }
  6. Finally, we'll output the readings to the console and wait for 15 seconds before exiting the loop.

    usbSerial.print("Temperature = ");
    usbSerial.print(bmeSensor.readTempC());
    usbSerial.println(" *C");
    usbSerial.print("Humidity = ");
    usbSerial.print(bmeSensor.readFloatHumidity());
    usbSerial.println(" %");
    
    delay(15000);

Send Sensor Readings to the Notecard

Now that we're getting sensor readings, let's send these to our Notecard.

  1. To send a sensor reading to the Notecard, we'll need to construct a new JSON request to the note.add API that includes a new Notefile name (sensors.qo), sets the sync field to true to instruct the Notecard to sync to Notehub immediately, and finally, sets the body to the sensor temperature and humidity. Add the following in loop right after the usbSerial commands to print out readings.

    {
      J *req = notecard.newRequest("note.add");
      if (req != NULL) {
        JAddStringToObject(req, "file", "sensors.qo");
        JAddBoolToObject(req, "sync", true);
        J *body = JCreateObject();
        if (body != NULL) {
          JAddNumberToObject(body, "temp", bmeSensor.readTempC());
          JAddNumberToObject(body, "humidity", bmeSensor.readFloatHumidity());
          JAddItemToObject(req, "body", body);
        }
        notecard.sendRequest(req);
    }

note

If you're using a Notecard for LoRa to complete this tutorial you have one additional step. Because the Notecard for LoRa requires a template for every Notefile you use, you must define a template for the sensors.qo Notefile in your setup() function. You can add the following code to the bottom of your setup() function to fix the problem.

{
  J *req = notecard.newRequest("note.template");
  if (req != NULL) {
    JAddStringToObject(req, "file", "sensors.qo");
    JAddNumberToObject(req, "port", 1);
    JAddStringToObject(req, "format", "compact");
    J *body = JCreateObject();
    if (body != NULL) {
      JAddNumberToObject(body, "temp", 14.1);
      JAddNumberToObject(body, "humidity", 14.1);
      JAddItemToObject(req, "body", body);
      notecard.sendRequest(req);
    }
  }
}

Learn more about Notefile templates in Working with Note Templates.

note

Concerned about the size of note-arduino? You can communicate with the Notecard without using the library.

View Data in Notehub

Once you start capturing readings, your Notecard will initiate a connection to Notehub and will start transferring Notes. Depending on signal strength and coverage in your area, it may take a few minutes for your Notecard to connect to Notehub and transfer data.

  1. Return to notehub.io and open your project. You should see your notecard in the Devices view.

    The new device in Notehub

  2. Now, click on the Events left menu item. Once your sensor Notes start syncing, they'll show up here.

    The event list in Notehub

Use Environment Variables

Environment variables are a Notehub state and settings management feature that allow you to set variables in key-value pairs, and intelligently synchronize those values across devices and fleets of devices.

In this section you'll learn how environment variables work by creating a variable that determines how often your firmware should take sensor readings.

Using Environment Variables in Firmware

The Notecard provides a set of requests for working with environment variables. The most common of these requests is env.get, which allows you to retrieve the value of an environment variable.

Complete the steps below to use the env.get request to retrieve and use the reading_interval environment variable.

  1. In setup(), adjust your existing hub.set configuration to set the inbound argument to 5. This tells your Notecard to look for inbound changes from Notehub every 5 minutes.

    {
      J *req = notecard.newRequest("hub.set");
      if (req != NULL) {
        JAddStringToObject(req, "product", productUID);
        JAddStringToObject(req, "mode", "continuous");
        JAddNumberToObject(req, "inbound", 5); // ADD THIS LINE
        notecard.sendRequest(req);
      }
    }
  2. Next, place the following new function at the bottom of your sketch.

    // This function assumes you’ll set the reading_interval environment variable to
    // a positive integer. If the variable is not set, set to 0, or set to an invalid
    // type, this function returns a default value of 60.
    int getSensorInterval() {
      int sensorIntervalSeconds = 60;
      J *req = notecard.newRequest("env.get");
      if (req != NULL) {
        JAddStringToObject(req, "name", "reading_interval");
        J* rsp = notecard.requestAndResponse(req);
        int readingIntervalEnvVar = atoi(JGetString(rsp, "text"));
        if (readingIntervalEnvVar > 0) {
          sensorIntervalSeconds = readingIntervalEnvVar;
        }
        notecard.deleteResponse(rsp);
      }
      return sensorIntervalSeconds;
    }
  3. Then, add this line after the #include lines at the top of the file.

    int getSensorInterval();
  4. Next, find the delay(15000) line at the bottom of your loop() function, and replace it with the code below.

    int sensorIntervalSeconds = getSensorInterval();
    usbSerial.print("Delaying ");
    usbSerial.print(sensorIntervalSeconds);
    usbSerial.println(" seconds");
    delay(sensorIntervalSeconds * 1000);
    note

    Notecard for LoRa requires a template for each environment variable you use. If you're using a Notecard for LoRa to complete this tutorial, add the code below to your setup() to provide a template for the reading_interval variable.

    {
      J *req = notecard.newRequest("env.template");
      if (req != NULL) {
        J *body = JCreateObject();
        if (body != NULL) {
          JAddNumberToObject(body, "reading_interval", 21);
          JAddItemToObject(req, "body", body);
          notecard.sendRequest(req);
        }
      }
    }

With this code in place, your firmware now uses the reading_interval environment variable to determine how many seconds to delay in between sensor readings. If you flash this updated code to your device and open your serial monitor, you can see the device using the default value for reading_interval of 60 seconds.

Setting an Environment Variable

Now we have our device programmed to retrieve an Environment Variable from Notehub, we will create that variable. Environment variables can be set in the Notehub UI or through the Notehub API. In this tutorial you'll learn how to set the values through the Notehub UI. If you'd like to instead set environment variables through the Notehub API, refer to environment variable requests in the Project API.

  1. Return to your Notehub project, go the the Devices page, and double click your device. You should see a screen that looks like this.

    The Notehub device screen

  2. Click the Environment tab.

  3. Under the Device environment variables header, define a new environment variable named reading_interval and set its value to 30.

    The environment screen with a new value set

Now that you have an environment variable set, you'll see it reflected on your device after your configured inbound interval has passed.

The environment screen with a new value set

note

On cellular and Wi-Fi-based Notecards you can use the hub.set request's sync argument to immediately receive inbound updates instead of relying on the inbound interval.

And with that, you've used your first environment variable on your Notecard! To see the real power of environment variables in action, try returning to Notehub and updating your device's reading_interval with your serial monitor open.

note

This tutorial had you use several configuration settings that are best used when you have your Notecard connected to mains power.

  • In the hub.set request, setting mode to "continuous" tells the Notecard to maintain an active network connection.

  • In the hub.set request, setting sync to true tells the Notecard to immediately synchronize inbound Notes and environment variables from Notehub.

  • In the note.add request, setting sync to true tells the Notecard to immediately synchronize all outbound Notes to Notehub.

Because each of these settings cause the Notecard to use more power, you may wish to disable them if you plan to transition your project to battery power. You can run the command below to put your Notecard into periodic mode with the sync argument turned off.

{
 "req": "hub.set",
 "mode": "periodic",
 "sync": false,
 "outbound": 60,
 "inbound": 120
}

Learn more about optimizing the Notecard for low-power scenarios in Low Power Design.

Next Steps

Congratulations! You've successfully connected your Artemis Thing Plus to your Notecard and built a basic IoT project.

If you're following the Blues Quickstart, next we recommend learning how to send (and visualize) your data in a cloud application:

  1. Use the Notecard to Send Data
  2. Set Up Your Microcontroller
  3. Build Your First IoT App With Blues
  4. Send Data to Your Cloud

At any time, if you find yourself stuck, please reach out on the community forum .

Can we improve this page? Send us feedback
© 2025 Blues Inc.
© 2025 Blues Inc.
TermsPrivacy
Notecard Disconnected
Having trouble connecting?

Try changing your USB cable as some cables do not support transferring data. If that does not solve your problem, contact us at support@blues.com and we will get you set up with another tool to communicate with the Notecard.

Advanced Usage

The help command gives more info.

Connect a Notecard
Use USB to connect and start issuing requests from the browser.
Try Notecard Simulator
Experiment with Notecard's latest firmware on a Simulator assigned to your free Notehub account.

Don't have an account? Sign up