# IoT Food Scale with Azure and CircuitPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/113/304/medium800/projects_edited_P1380403.jpg?1658250722)

In the [NAU7802 Food Scale Learn Guide](https://learn.adafruit.com/nau7802-food-scale), you can build a food scale using CircuitPython, a NAU7802 STEMMA board and a strain gauge. In this guide, you'll take that project and connect it to [Microsoft Azure](https://aka.ms/adafruit/tutorial2/azureportal) to log the weight measurements over time. Additionally, you'll setup a text alert when it looks like you need to refill the food container.

Tracking inventory usage over time is a great way to utilize IoT tools. It can help you see patterns and better plan for the future. In the context of pet food, it can also help you monitor your pet's diet.

![projects_lineWeight.png](https://cdn-learn.adafruit.com/assets/assets/000/113/310/medium640/projects_lineWeight.png?1658252762)

## Prerequisite Guides

- The [Getting Started with Microsoft Azure and CircuitPython Learn Guide](https://learn.adafruit.com/getting-started-with-microsoft-azure-and-circuitpython) goes through everything you need to get up and running with Microsoft Azure and CircuitPython. You'll need to follow along with the steps in that guide to make sure that your Azure account is setup properly to use for CircuitPython Azure IoT Central projects.
- This guide is considered part two to the [NAU7802 Food Scale Learn Guide](https://learn.adafruit.com/nau7802-food-scale). You'll need to follow along with that guide to assemble the electronics and 3D printed parts for the food scale.

The following buttons take you to guides on the major components for reference:

[Adafruit QT Py ESP32-S2](https://learn.adafruit.com/adafruit-qt-py-esp32-s2)
[Adafruit NAU7802 24-Bit ADC](https://learn.adafruit.com/adafruit-nau7802-24-bit-adc-stemma-qt-qwiic)
[Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack/0-54-alphanumeric)
## Parts
### Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT

[Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT](https://www.adafruit.com/product/5325)
What has your favorite Espressif WiFi microcontroller, comes with&nbsp;[our favorite connector - the STEMMA QT](http://adafruit.com/stemma), a chainable I2C port, and has lots of Flash and RAM memory for your next IoT project? What will make your next IoT project flyyyyy? What a...

In Stock
[Buy Now](https://www.adafruit.com/product/5325)
[Related Guides to the Product](https://learn.adafruit.com/products/5325/guides)
![Angled shot of small square purple dev board.](https://cdn-shop.adafruit.com/640x480/5325-12.jpg)

### Adafruit NAU7802 24-Bit ADC - STEMMA QT / Qwiic

[Adafruit NAU7802 24-Bit ADC - STEMMA QT / Qwiic](https://www.adafruit.com/product/4538)
If you are feeling the stress and strain of ~~modern life~~ a Wheatstone bridge and you want to quantify it, this handy breakout will do the job, no sweat! The **Adafruit NAU7802** contains a super-high-resolution 24-Bit differential ADC with extra gain and calibration...

In Stock
[Buy Now](https://www.adafruit.com/product/4538)
[Related Guides to the Product](https://learn.adafruit.com/products/4538/guides)
![Video of a pair of white hand's trying to bend a strain gauge. The gauge is connected to a breakout board which is also connected to an OLED display on a half-size breadboard. The numbers on the OLED display show high digit numbers.](https://cdn-shop.adafruit.com/product-videos/640x480/4538-05.jpg)

### Strain Gauge Load Cell - 4 Wires - 20Kg

[Strain Gauge Load Cell - 4 Wires - 20Kg](https://www.adafruit.com/product/4543)
A&nbsp;strain gauge&nbsp;is a type of electronic sensor used to measure force or strain (big surprise there). They are made of an&nbsp;insulating&nbsp;flexible backing with a metallic foil pattern. The resistance of a&nbsp;strain gauge&nbsp;changes when&nbsp;force&nbsp;is applied and the...

In Stock
[Buy Now](https://www.adafruit.com/product/4543)
[Related Guides to the Product](https://learn.adafruit.com/products/4543/guides)
![Angled shot of a Strain Gauge Load Cell - 4 Wires - 20Kg. ](https://cdn-shop.adafruit.com/640x480/4543-02.jpg)

### Quad Alphanumeric Display - Yellow 0.54" Digits w/ I2C Backpack

[Quad Alphanumeric Display - Yellow 0.54" Digits w/ I2C Backpack](https://www.adafruit.com/product/2158)
Display, elegantly, 012345678 or 9! Gaze, hypnotized, at ABCDEFGHIJKLM - well it can display the whole alphabet. You get the point. This is a nice, bright alphanumeric display that shows letters and numbers in a beautiful yellow hue. It's super bright and designed for viewing from...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2158)
[Related Guides to the Product](https://learn.adafruit.com/products/2158/guides)
![Overhead shot of an assembled 14-segment LED backpack, emitting the follow text in yellow LEDS: "AdaFruit 14-Segment Backpack"](https://cdn-shop.adafruit.com/product-videos/640x480/2158-09.jpg)

### 16mm Illuminated Pushbutton - Green Momentary

[16mm Illuminated Pushbutton - Green Momentary](https://www.adafruit.com/product/1440)
A button is a button, and an LED is a LED, but this LED illuminated button is a lovely combination of both! It's a medium sized button, large enough to press easily but not too big that it gets in the way of your project panel. It has a built in LED that can be controlled separately from...

In Stock
[Buy Now](https://www.adafruit.com/product/1440)
[Related Guides to the Product](https://learn.adafruit.com/products/1440/guides)
![Angled shot of a green 16mm illuminated pushbutton. ](https://cdn-shop.adafruit.com/640x480/1440-00.jpg)

### 16mm Illuminated Pushbutton - Blue Momentary

[16mm Illuminated Pushbutton - Blue Momentary](https://www.adafruit.com/product/1477)
A switch is a switch, and an LED is an LED, but this LED illuminated button is a lovely combination of both! It's a medium sized button, large enough to press easily but not too big that it gets in the way of your project panel. It has a built in LED that can be controlled separately from...

In Stock
[Buy Now](https://www.adafruit.com/product/1477)
[Related Guides to the Product](https://learn.adafruit.com/products/1477/guides)
![Angled shot of a blue round 16mm illuminated pushbutton. ](https://cdn-shop.adafruit.com/640x480/1477-00.jpg)

### Part: USB C Round Panel Mount Extension Cable
quantity: 1
USB C extension
[USB C Round Panel Mount Extension Cable](https://www.adafruit.com/product/4218)

### Part: Pink and Purple Woven USB A to USB C Cable - 1 meter long
quantity: 1
USB C to USB A
[Pink and Purple Woven USB A to USB C Cable - 1 meter long](https://www.adafruit.com/product/5153)

### Part: STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long
quantity: 3
STEMMA QT cable
[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)

### Part: Silicone Cover Stranded-Core Wire - 30AWG in Various Colors
quantity: 1
Stranded-Core Wire
[Silicone Cover Stranded-Core Wire - 30AWG in Various Colors](https://www.adafruit.com/product/2051)

### Part: M4 Screws
quantity: 1
M4 screws
[M4 Screws](https://www.adafruit.com/product/1160)

### Part: Food storage container
quantity: 1
2.6 quart storage container
[Food storage container](https://www.target.com/p/oxo-pop-2-6qt-airtight-food-storage-container/-/A-15420440#lnk=sametab)

### Part: Calibration Weight 1g 2g 5g 10g 20g
quantity: 1
Calibration weights
[Calibration Weight 1g 2g 5g 10g 20g](https://www.amazon.com/dp/B078Q3JZY7?psc=1&ref=ppx_yo2ov_dt_b_product_details)

# IoT Food Scale with Azure and CircuitPython

## Build the Food Scale

The [NAU7802 Food Scale guide](https://learn.adafruit.com/nau7802-food-scale) has everything you need documented to build your own. Please follow along with that guide first before adding in the Azure IoT Central functionality.

[Make sure to follow along with the NAU7802 Food Scale Learn Guide!](https://learn.adafruit.com/nau7802-food-scale)
Follow the Fritzing diagram found on the [Circuit Diagram page](https://learn.adafruit.com/nau7802-food-scale/circuit-diagram) to wire up the food scale. The [Wiring page](https://learn.adafruit.com/nau7802-food-scale/wiring) goes into detail on soldering steps.

![projects_nau7802_scale_fritzing_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/113/259/medium640/projects_nau7802_scale_fritzing_bb.jpg?1658173093)

The [3D Printing page](https://learn.adafruit.com/nau7802-food-scale/3d-printing) details the 3D printed enclosure for the project. The [Assembly page](https://learn.adafruit.com/nau7802-food-scale/assembly) goes through how to mount all of the components properly.

![projects_edited_P1380337.jpg](https://cdn-learn.adafruit.com/assets/assets/000/113/260/medium640/projects_edited_P1380337.jpg?1658173453)

The [Calibration page](https://learn.adafruit.com/nau7802-food-scale/calibration) shows you how to properly calibrate your NAU7802 and strain gauge to get accurate weight measurements.&nbsp;

![projects_calib4.gif](https://cdn-learn.adafruit.com/assets/assets/000/113/309/medium640thumb/projects_calib4.jpg?1658253231)

# IoT Food Scale with Azure and CircuitPython

## Create an IoT Central Application

There are two Azure IoT options: [IoT Hub](https://aka.ms/adafruit/tutorial2/iothub) and [IoT Central](https://aka.ms/adafruit/tutorial2/iotcentral). In this guide, you'll be using IoT Central, which is the simpler of the two options to get started with.

After logging into Microsoft Azure, in the [Azure Portal homepage](https://aka.ms/adafruit/tutorial2/azureportal)search for "IoT Central" and navigate to [IoT Central Applications](https://portal.azure.com/#view/HubsExtension/BrowseResource/resourceType/Microsoft.IoTCentral%2FIoTApps)

![temperature___humidity_iotCentral.png](https://cdn-learn.adafruit.com/assets/assets/000/112/159/medium640/temperature___humidity_iotCentral.png?1654090864)

Create a new application by clicking on **Create**.

![temperature___humidity_createNewApp.png](https://cdn-learn.adafruit.com/assets/assets/000/112/167/medium640/temperature___humidity_createNewApp.png?1654112458)

On the Basics page, you'll enter details about your application. The Application URL is how you will access your application's homepage.

![temperature___humidity_applicationSetup.png](https://cdn-learn.adafruit.com/assets/assets/000/112/160/medium640/temperature___humidity_applicationSetup.png?1654090919)

After creating the application, the deployment of the app will begin. Once it finishes, you'll see a message that deployment is complete. Then, click on **Go To Resource**.

![temperature___humidity_deploymentInProgress.png](https://cdn-learn.adafruit.com/assets/assets/000/112/168/medium640/temperature___humidity_deploymentInProgress.png?1654112836)

![temperature___humidity_deploymentComplete.png](https://cdn-learn.adafruit.com/assets/assets/000/112/170/medium640/temperature___humidity_deploymentComplete.png?1654112972)

This brings you to your application's overview page. Click on the **link on the right-hand side of the screen** to view your app.

![temperature___humidity_iotCentralAppView.png](https://cdn-learn.adafruit.com/assets/assets/000/112/171/medium640/temperature___humidity_iotCentralAppView.png?1654113016)

The link brings you to your app's homepage. Here you can connect devices, create dashboards, view data and control all aspects of the app.

![temperature___humidity_newApp.png](https://cdn-learn.adafruit.com/assets/assets/000/112/172/medium640/temperature___humidity_newApp.png?1654113138)

# IoT Food Scale with Azure and CircuitPython

## Connect Your Device

![](https://cdn-learn.adafruit.com/assets/assets/000/112/218/medium800/temperature___humidity_convertPlan.png?1654180102)

Warning: 

After creating your application, you'll connect a device instance for your development board that you'll be connecting to Azure with CircuitPython. This process will create the keys you need to include in your **settings.toml** file.

To connect your device, click on the **blue New button**.

![temperature___humidity_newDevice.png](https://cdn-learn.adafruit.com/assets/assets/000/112/173/medium640/temperature___humidity_newDevice.png?1654113422)

This opens the new device screen. Name your device. The device ID will be identical to the name. Then click **Create**.

![temperature___humidity_createNewDevice.png](https://cdn-learn.adafruit.com/assets/assets/000/112/174/medium640/temperature___humidity_createNewDevice.png?1654113469)

You'll see your device appear under the All devices list. Click on your **device**.

![temperature___humidity_allDevices.png](https://cdn-learn.adafruit.com/assets/assets/000/112/175/medium640/temperature___humidity_allDevices.png?1654113567)

Click on **Connect**.

![temperature___humidity_connect.png](https://cdn-learn.adafruit.com/assets/assets/000/112/185/medium640/temperature___humidity_connect.png?1654114606)

This opens the Device connection groups window that has all of your secret connection keys. You will need the ID scope, Device ID and Primary key for your **settings.toml** file.

![temperature___humidity_InkedconnectDeviceSecrets_LI.jpg](https://cdn-learn.adafruit.com/assets/assets/000/112/223/medium640/temperature___humidity_InkedconnectDeviceSecrets_LI.jpg?1654182158)

Now you're ready to connect to Microsoft Azure with CircuitPython!

# IoT Food Scale with Azure and CircuitPython

## CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_qtpy_esp32s2/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/129/medium640/install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg?1620922559)

![](https://cdn-learn.adafruit.com/assets/assets/000/107/612/medium800/adafruit_products_QTESP_reset_NeoPixel.jpg?1641246436)

Info: The board above has a chip antenna, not the u.Fl connector, but the process is the same.

Plug your board into your computer, using a known-good data-sync cable, directly, or via an adapter if needed.

Click the **reset** button once (highlighted in red above), and then click it again when you see the **RGB status LED(s)** (highlighted in green above) turn purple (approximately half a second later). Sometimes it helps to think of it as a "slow double-click" of the reset button.

If you do not see the LED turning purple, you will need to reinstall the UF2 bootloader. See the&nbsp; **Factory Reset** &nbsp;page in this guide for details.

On some very old versions of the UF2 bootloader, the status LED turns red instead of purple.

For this board, tap reset and wait for the LED to turn purple, and as soon as it turns purple, tap reset again. The second tap needs to happen while the LED is still purple.

Once successful, you will see the **RGB status LED(s)** turn green (highlighted in green above), and a disk drive ending in " **...BOOT**" should appear on your host computer. If you see red, try another port, or if you're using an adapter or hub, try without the hub, or different adapter or hub.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

Info: 

You will see a new disk drive appear called **QTPYS2BOOT**.

&nbsp;

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **QTPYS2BOOT**.

![adafruit_products_uf2install.png](https://cdn-learn.adafruit.com/assets/assets/000/107/577/medium640/adafruit_products_uf2install.png?1640641747)

Copy or drag the UF2 file you downloaded to the **BOOT** drive.

The **BOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it!

![install_circuitpython_on_most_boards_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/130/medium640/install_circuitpython_on_most_boards_CIRCUITPY.jpg?1620923145)

# IoT Food Scale with Azure and CircuitPython

## Code the IoT Food Scale

Once you've finished setting up your QT Py ESP32-S2 with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Azure_Food_Scale/code.py

## Upload the Code and Libraries to the QT Py ESP32-S2

After downloading the Project Bundle, plug your QT Py ESP32-S2 into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the QT Py ESP32-S2's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **calibration.py**
- **code.py**

Your QT Py ESP32-S2&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder, **calibration.py** file and the&nbsp; **code.py&nbsp;** file.

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/Azure_Food_Scale.png )

## Install the **cedargrove\_nau7802** CircuitPython Library

Follow along with the steps outlined in [this guide](https://learn.adafruit.com/adafruit-nau7802-24-bit-adc-stemma-qt-qwiic/python-circuitpython#circuitpython-usage-3118900) to download the **cedargrove\_nau7802** CircuitPython library and upload it to your QT Py ESP32-S2 **CIRCUITPY** drive **lib** folder. The library is a part of the [CircuitPython Community Bundle](https://circuitpython.org/libraries).

## **calibration.py** File

The **calibration.py** file holds two important values for the main **code.py** file: `offset_val` and `weight`. `weight` is the known weight in grams that you use to calibrate the NAU7802. The `offset_val` is the calibration number used to divide against the raw value from the NAU7802 to find the actual weight on top of the scale.&nbsp;

Each strain gauge is slightly different, so you'll want to edit the **calibration.py** file with your known weight item and the `offset_val` you generate after running the calibration mode in the **code.py** file.

## **settings.toml**

You will need to create and add a **settings.toml** file to your&nbsp; **CIRCUITPY** &nbsp;drive. Your **settings****.toml** file will need to include the following information:

```python
# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it

CIRCUITPY_WIFI_SSID="your-wifi-ssid"
CIRCUITPY_WIFI_PASSWORD="your-wifi-password"
id_scope="YOUR-AZURE-ID-SCOPE-HERE"
device_id="YOUR-AZURE-DEVICE-ID-HERE"
device_primary_key="YOUR-AZURE-DEVICE-PRIMARY-KEY-HERE"
```

You'll gather your ID scope, device ID and device primary key from your device connection groups page in your Azure application. Make sure to refer to the&nbsp;[Connect Your Device](https://learn.adafruit.com/getting-started-with-microsoft-azure/connect-your-device)&nbsp;page in this guide to see the process for accessing the keys.

## How the CircuitPython Code Works

The CircuitPython code is identical to the original [NAU7802 Food Scale CircuitPython code](https://learn.adafruit.com/nau7802-food-scale/code-the-nau7802-food-scale#how-the-circuitpython-code-works-3121534) as far as scale functionality. This version of the code adds functionality for connecting to, and sending data to, Azure.

## Connect to WiFi and Azure
The code begins by connecting to WiFi and grabbing the date and time using the&nbsp;`adafruit_ntp` library.

```python
# Get WiFi details, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")

if None in [ssid, password]:
    raise RuntimeError(
        "WiFi settings are kept in settings.toml, "
        "please add them there. The settings file must contain "
        "'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
        "at a minimum."
    )

print("Connecting to WiFi...")
wifi.radio.connect(ssid, password)

print("Connected to WiFi!")
#  check system time
if time.localtime().tm_year < 2022:
    print("Setting System Time in UTC")
    pool = socketpool.SocketPool(wifi.radio)
    ntp = adafruit_ntp.NTP(pool, tz_offset=-4)
    # NOTE: This changes the system time so make sure you aren't assuming that time
    # doesn't jump.
    rtc.RTC().datetime = ntp.datetime

else:
    print("Year seems good, skipping set time.")
```

Then, a connection is established with Microsoft Azure. The alphanumeric display updates its text to show what is going on with the connection process.

```python
# Create an IoT Central device client and connect
esp = None
pool = socketpool.SocketPool(wifi.radio)
device = IoTCentralDevice(
    pool, esp, getenv("id_scope"), getenv("device_id"), getenv("device_primary_key")
)
display.fill(0)
display.print("DIALING*")
print("Connecting to Azure IoT Central...")
device.connect()
display.print("CONNECTD")
print("Connected to Azure IoT Central!")
```

## Send Data to Azure Function
The `send_to_azure()` function sends the current weight in ounces and grams to Azure with `device.send_telemetry(json.dumps(message))`. It also uses the buttons' LEDs and alphanumeric display to indicate the processes in the code.

```python
#  send data to azure with ounces and grams
def send_to_azure(current_oz, current_grams):
    #  turn on green LED
    green.value = True
    display.print("DIALING*")
    #  connect to azure
    device.reconnect()
    #  turn on blue LED
    blue.value = True
    display.print("CONNECTD")
    time.sleep(1)
    display.print("SENDING!")
    #  send JSON of ounces and grams
    message = {"Ounces": current_oz, "Grams": current_grams}
    device.send_telemetry(json.dumps(message))
    display.fill(0)
    display.print("SENT!")
    #  disconnect and turn off LEDs
    device.disconnect()
    green.value = False
    blue.value = False
```

## Logging Ounces and Grams

The alphanumeric display shows either ounces or grams depending on the mode selected. In the background though, both the ounces and grams are logged in `the_grams` and `the_ounces`.

```python
grams = value / calibration['offset_val']
        oz = grams / 28.35
        avg_grams.append(grams)
        avg_oz.append(oz)
        if show_oz is True:
            #  append reading
            avg_read.append(oz)
            label = "oz"
        if show_grams is True:
            avg_read.append(grams)
            label = "g"
        if len(avg_read) > 10:
            the_avg = find_average(avg_read)
            the_grams = find_average(avg_grams)
            the_ounces = find_average(avg_oz)
            display.print("   %0.1f %s" % (the_avg, label))
            avg_read.clear()
            avg_grams.clear()
            avg_oz.clear()
```

## Send Weight to Azure

The food scale is coded to have a selection of mode functionality. One of the functions in the list is sending the data to Azure. If `mode` is `5` and the blue button is pressed, then `send_to_azure(the_ounces, the_grams)` is called and sends the current weigh in ounces and grams is sent to your Azure IoT Central application. Then, the scale goes back to weighing mode.

```python
if (not blue_btn.value and not blue_btn_pressed) and mode == 5:
        blue.value = False
        display.fill(0)
        #  sends data to azure
        send_to_azure(the_ounces, the_grams)
        time.sleep(1)
        mode = "run"
        #  goes back to weighing mode
        show_oz = True
        label = "oz"
        display.print("   %0.1f %s" % (the_avg, label))
        run_mode = True
        blue_btn_pressed = True
```

# IoT Food Scale with Azure and CircuitPython

## Edit the Data Template

The device's template organizes and categorizes the incoming data so that it can be logged properly.

At the top of your device's page, click on **Manage template -\> Auto-create template**.

![temperature___humidity_audoCreateTemplate.png](https://cdn-learn.adafruit.com/assets/assets/000/112/176/medium640/temperature___humidity_audoCreateTemplate.png?1654113856)

![](https://cdn-learn.adafruit.com/assets/assets/000/113/229/medium800/projects_sort_tele.png?1658159582)

If you've already logged data from the QT Py ESP32-S2, then the template will be auto-filled with the data that you sent to Microsoft Azure which was previously categorized as unmodeled data.

![projects_unmodelled.png](https://cdn-learn.adafruit.com/assets/assets/000/113/230/medium640/projects_unmodelled.png?1658159673)

You can also add the data types that you want to collect by clicking Add capability. The display name is how the data will be categorized on Azure. The name has to match the string in the JSON message that is sent from the CircuitPython code. Capability type needs to match the type of data that is going to be received. If you are receiving sensor data, then you will select Telemetry.&nbsp;

Make sure to click **Save** when you're done editing your template.

![projects_inCP.png](https://cdn-learn.adafruit.com/assets/assets/000/113/231/medium640/projects_inCP.png?1658159764)

# IoT Food Scale with Azure and CircuitPython

## Create a Dashboard

![](https://cdn-learn.adafruit.com/assets/assets/000/113/232/medium800/projects_dash.png?1658159887)

You can create visual dashboards to display your data for easy viewing.

Navigate to the Dashboards page and click **Edit**.

![temperature___humidity_editDash.png](https://cdn-learn.adafruit.com/assets/assets/000/112/196/medium640/temperature___humidity_editDash.png?1654115719)

In edit mode, a tile menu opens on the left. You can drag and drop different tiles into the main dashboard space. There's a variety of graph and display types to choose from.

![temperature___humidity_dashboardOptions.png](https://cdn-learn.adafruit.com/assets/assets/000/112/197/medium640/temperature___humidity_dashboardOptions.png?1654115822)

The tile will be empty when you first bring it to the dashboard. You can click on the **pencil icon** to edit the tile to display your data.

![temperature___humidity_emptyChart.png](https://cdn-learn.adafruit.com/assets/assets/000/112/198/medium640/temperature___humidity_emptyChart.png?1654115914)

The title will be displayed above the tile. You can configure the chart's axes and legend.

&nbsp;

![projects_configLine2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/113/235/medium640/projects_configLine2.jpg?1658160177)

To bring the data into the tile, you'll **select your device from the dropdown**. Then, **add Capability** to bring in different data streams.&nbsp;

![projects_configLine1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/113/236/medium640/projects_configLine1.jpg?1658160201)

Click **Update** and you should see your data populate the tile.

![projects_line.png](https://cdn-learn.adafruit.com/assets/assets/000/113/237/medium640/projects_line.png?1658160262)

You can add as many tiles as you want to fully customize your dashboard. The food scale dashboard utilizes line graph and last known value (LKV) tiles to show the weight over time, the current weight and the change in weight since the last reading.

![](https://cdn-learn.adafruit.com/assets/assets/000/113/238/medium800/projects_lkv.png?1658160424)

# IoT Food Scale with Azure and CircuitPython

## Create a Text Alert

![](https://cdn-learn.adafruit.com/assets/assets/000/113/240/medium800/projects_rule.png?1658162204)

You can create Rules to alert you about certain data thresholds. For this project, you'll setup a text alert using an action group in the Azure Portal.

## Create an Action Group
In the Azure Portal, search "monitor" and click on the **Monitor icon**.

![projects_searchMonitor.png](https://cdn-learn.adafruit.com/assets/assets/000/113/241/medium640/projects_searchMonitor.png?1658162300)

On the Monitor page, click on **Alerts** in the left column and then **Action Groups**.

![projects_alertsPage.png](https://cdn-learn.adafruit.com/assets/assets/000/113/242/medium640/projects_alertsPage.png?1658162364)

On the Action groups page, click on **Create** to create a new action group.

![projects_createAction.png](https://cdn-learn.adafruit.com/assets/assets/000/113/243/medium640/projects_createAction.png?1658162428)

On the basics page, you'll link your subscription and resource group. Then, you'll name the action.

![projects_actionDetails.png](https://cdn-learn.adafruit.com/assets/assets/000/113/244/medium640/projects_actionDetails.png?1658162956)

Under Notifications, you'll choose the notification type and name the notification. Choose Email/SMS message/Push/Voice for text message.

![projects_notificationType.png](https://cdn-learn.adafruit.com/assets/assets/000/113/245/medium640/projects_notificationType.png?1658162995)

A menu for directing the notification will pop-up on the right of the screen. Check off **SMS** for a text message and enter the phone number that you want to receive the text messages.

Afterwards, you can click **"Review and create"** to complete the setup.

![projects_smsSetting.png](https://cdn-learn.adafruit.com/assets/assets/000/113/246/medium640/projects_smsSetting.png?1658163050)

## Create a Rule
Navigate to the **Rules** page on the side menu bar.

![projects_rulesMenu.png](https://cdn-learn.adafruit.com/assets/assets/000/113/248/medium640/projects_rulesMenu.png?1658163271)

Click on **New** to create a new rule.

![projects_newRule.png](https://cdn-learn.adafruit.com/assets/assets/000/113/249/medium640/projects_newRule.png?1658163312)

First, you'll need to name the alert and **toggle the Enable option** to turn it on. Then you can **select the device** to receive alerts for.

![projects_rule1.png](https://cdn-learn.adafruit.com/assets/assets/000/113/250/medium640/projects_rule1.png?1658163385)

You'll setup conditions for the rule. You can have the rule be triggered if all or some of the conditions are true. The Time aggregation option can limit the number of alerts you receive. For example, if you select 60 minutes then you will only be alerted once per hour if a condition is true.

Under Telemetry, you'll select the data feed to monitor, as well as an operator; such as less than, equal to, etc. Under Value, you'll enter the value to watch for.

![projects_conditions.png](https://cdn-learn.adafruit.com/assets/assets/000/113/255/medium640/projects_conditions.png?1658172771)

Under Actions, you'll select Azure Monitor Action Groups.

![projects_azureMonitor.png](https://cdn-learn.adafruit.com/assets/assets/000/113/257/medium640/projects_azureMonitor.png?1658172914)

Select the Action Group that you setup earlier from the dropdown menu. When you're finished, **save your Rule** and you're ready to receive text alerts.

![projects_selectAction.png](https://cdn-learn.adafruit.com/assets/assets/000/113/258/medium640/projects_selectAction.png?1658172953)

# IoT Food Scale with Azure and CircuitPython

## Usage

![](https://cdn-learn.adafruit.com/assets/assets/000/113/305/medium800thumb/projects_dialing.jpg?1658250734)

After [calibrating your NAU7802](https://learn.adafruit.com/nau7802-food-scale/calibration), place your food container on top and begin tracking your pet's food consumption over time.

Send data to Azure by selecting the mode on the alphanumeric displays.

![projects_send_azure.gif](https://cdn-learn.adafruit.com/assets/assets/000/113/306/medium640thumb/projects_send_azure.jpg?1658252952)

View the data over time to estimate when you need to refill the container. You can also see on average how much is being eaten per meal with the last known value chart.

![projects_lkv.png](https://cdn-learn.adafruit.com/assets/assets/000/113/308/medium640/projects_lkv.png?1658252300)

Receive text alerts when the scale drops below a threshold value.

![projects_IMG_5963.jpg](https://cdn-learn.adafruit.com/assets/assets/000/113/307/medium640/projects_IMG_5963.jpg?1658251162)


## Featured Products

### Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT

[Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT](https://www.adafruit.com/product/5325)
What has your favorite Espressif WiFi microcontroller, comes with&nbsp;[our favorite connector - the STEMMA QT](http://adafruit.com/stemma), a chainable I2C port, and has lots of Flash and RAM memory for your next IoT project? What will make your next IoT project flyyyyy? What a...

In Stock
[Buy Now](https://www.adafruit.com/product/5325)
[Related Guides to the Product](https://learn.adafruit.com/products/5325/guides)
### Adafruit NAU7802 24-Bit ADC - STEMMA QT / Qwiic

[Adafruit NAU7802 24-Bit ADC - STEMMA QT / Qwiic](https://www.adafruit.com/product/4538)
If you are feeling the stress and strain of ~~modern life~~ a Wheatstone bridge and you want to quantify it, this handy breakout will do the job, no sweat! The **Adafruit NAU7802** contains a super-high-resolution 24-Bit differential ADC with extra gain and calibration...

In Stock
[Buy Now](https://www.adafruit.com/product/4538)
[Related Guides to the Product](https://learn.adafruit.com/products/4538/guides)
### Strain Gauge Load Cell - 4 Wires - 20Kg

[Strain Gauge Load Cell - 4 Wires - 20Kg](https://www.adafruit.com/product/4543)
A&nbsp;strain gauge&nbsp;is a type of electronic sensor used to measure force or strain (big surprise there). They are made of an&nbsp;insulating&nbsp;flexible backing with a metallic foil pattern. The resistance of a&nbsp;strain gauge&nbsp;changes when&nbsp;force&nbsp;is applied and the...

In Stock
[Buy Now](https://www.adafruit.com/product/4543)
[Related Guides to the Product](https://learn.adafruit.com/products/4543/guides)
### Quad Alphanumeric Display - Yellow 0.54" Digits w/ I2C Backpack

[Quad Alphanumeric Display - Yellow 0.54" Digits w/ I2C Backpack](https://www.adafruit.com/product/2158)
Display, elegantly, 012345678 or 9! Gaze, hypnotized, at ABCDEFGHIJKLM - well it can display the whole alphabet. You get the point. This is a nice, bright alphanumeric display that shows letters and numbers in a beautiful yellow hue. It's super bright and designed for viewing from...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2158)
[Related Guides to the Product](https://learn.adafruit.com/products/2158/guides)
### 16mm Illuminated Pushbutton - Green Momentary

[16mm Illuminated Pushbutton - Green Momentary](https://www.adafruit.com/product/1440)
A button is a button, and an LED is a LED, but this LED illuminated button is a lovely combination of both! It's a medium sized button, large enough to press easily but not too big that it gets in the way of your project panel. It has a built in LED that can be controlled separately from...

In Stock
[Buy Now](https://www.adafruit.com/product/1440)
[Related Guides to the Product](https://learn.adafruit.com/products/1440/guides)
### 16mm Illuminated Pushbutton - Blue Momentary

[16mm Illuminated Pushbutton - Blue Momentary](https://www.adafruit.com/product/1477)
A switch is a switch, and an LED is an LED, but this LED illuminated button is a lovely combination of both! It's a medium sized button, large enough to press easily but not too big that it gets in the way of your project panel. It has a built in LED that can be controlled separately from...

In Stock
[Buy Now](https://www.adafruit.com/product/1477)
[Related Guides to the Product](https://learn.adafruit.com/products/1477/guides)
### USB C Round Panel Mount Extension Cable

[USB C Round Panel Mount Extension Cable](https://www.adafruit.com/product/4218)
If you need to add a panel-mount connection&nbsp;but don't have the time or ability to cut a custom oval or square hole, this **USB C&nbsp;Round Panel Mount Extension Cable&nbsp;** is the easiest and fastest way to panel-ify your project. The adapter can fit holes...

In Stock
[Buy Now](https://www.adafruit.com/product/4218)
[Related Guides to the Product](https://learn.adafruit.com/products/4218/guides)
### Pink and Purple Woven USB A to USB C Cable - 1 meter long

[Pink and Purple Woven USB A to USB C Cable - 1 meter long](https://www.adafruit.com/product/5153)
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also made for USB C for our modernized breakout boards, Feathers, and more.&nbsp;&nbsp;[If you want something just like it but for Micro B, we...](https://www.adafruit.com/product/4111)

Out of Stock
[Buy Now](https://www.adafruit.com/product/5153)
[Related Guides to the Product](https://learn.adafruit.com/products/5153/guides)

## Related Guides

- [Adafruit QT Py ESP32-S2 and QT Py ESP32-S2 with uFL Antenna](https://learn.adafruit.com/adafruit-qt-py-esp32-s2.md)
- [Adafruit NAU7802 24-Bit ADC - STEMMA QT / Qwiic](https://learn.adafruit.com/adafruit-nau7802-24-bit-adc-stemma-qt-qwiic.md)
- [Star Fragment IoT Lamp](https://learn.adafruit.com/star-fragment-iot-lamp.md)
- [NAU7802 Pet Food Scale](https://learn.adafruit.com/nau7802-pet-food-scale.md)
- [Cheekmate - a Wireless Haptic Communication System](https://learn.adafruit.com/cheekmate-wireless-haptic-communication.md)
- [Two Way Telegraph with Analog Feedback Servos](https://learn.adafruit.com/two-way-display-with-analog-feedback-servos.md)
- [No-Code Snowfall Tracker with WipperSnapper and Adafruit IO](https://learn.adafruit.com/no-code-snow-tracker-with-wippersnapper-and-adafruit-io.md)
- [Cartoon Character Clock](https://learn.adafruit.com/cartoon-character-clock.md)
- [NeoPixel Sprite Weather Display](https://learn.adafruit.com/neopixel-sprite-weather-display.md)
- [Wireless ESP32-S2 Touch Screen Controller for Pure Data](https://learn.adafruit.com/wireless-esp32-s2-controller-for-pure-data.md)
- [Raspberry Pi Azure IoT Hub Dashboard with CircuitPython](https://learn.adafruit.com/raspberry-pi-iot-dashboard-with-azure-and-circuitpython.md)
- [QT Py S2 Round Display Compass](https://learn.adafruit.com/qt-py-s2-round-display-compass.md)
- [Traffic Light Conference Badge](https://learn.adafruit.com/traffic-light-conference-badge.md)
- [IoT Moon Phase Guide](https://learn.adafruit.com/moon-phase.md)
- [Circle of Fifths Euclidean Synth with synthio and CircuitPython](https://learn.adafruit.com/circle-of-fifths-euclidean-synth-with-synthio-and-circuitpython.md)
- [Super Simple Sunrise Lamp](https://learn.adafruit.com/super-simple-sunrise-lamp.md)
