# Getting Started with Microsoft Azure and CircuitPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/112/517/medium800/temperature___humidity_edited_P1380183.png?1655830407)

There are many IoT platforms out there, including Adafruit's own Adafruit.IO, but if you want to build really big projects or run a business using IoT, you'll need to use a platform that provides support for projects that scale. Microsoft Azure has resources for these types of applications and the best news is that you can use it with CircuitPython.

This guide will walk you through how to get started with Microsoft Azure using a Feather ESP32-S2 TFT and a BME688 sensor to monitor temperature, humidity and air pressure. The data is logged to Microsoft Azure every fifteen minutes and can be viewed on a dashboard.

Info: 

The Feather ESP32-S2 TFT's screen displays the data from the BME688 sensor, battery life and the timestamp for the last time the data was sent to Microsoft Azure.

![temperature___humidity_edited_cropP1380183.png](https://cdn-learn.adafruit.com/assets/assets/000/112/516/medium640/temperature___humidity_edited_cropP1380183.png?1655830363)

The project is battery-powered so you can place it exactly where you want it. A large 2500mAh battery provides a very long runtime before needing to recharge.

![temperature___humidity_edited_P1370779.png](https://cdn-learn.adafruit.com/assets/assets/000/112/239/medium640/temperature___humidity_edited_P1370779.png?1654267439)

## Prerequisite Guides
[Adafruit ESP32-S2 TFT Feather](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather)
[Adafruit BME680](https://learn.adafruit.com/adafruit-bme680-humidity-temperature-barometic-pressure-voc-gas)
## Parts
### Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT

[Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT](https://www.adafruit.com/product/5300)
We've got a new machine here at Adafruit, it can uncover your deepest desires. Don't believe me? I'll turn it on right now to prove it to you! What, you want unlimited mozzarella sticks? OK well, that's not something we can provide. But we can provide your...

In Stock
[Buy Now](https://www.adafruit.com/product/5300)
[Related Guides to the Product](https://learn.adafruit.com/products/5300/guides)
![Adafruit ESP32-S2 TFT Feather powered on by a USB- C power source displaying the product tittle in a red, yellow, green, white and blue. ](https://cdn-shop.adafruit.com/640x480/5300-06.jpg)

### Adafruit BME688 - Temperature, Humidity, Pressure and Gas Sensor

[Adafruit BME688 - Temperature, Humidity, Pressure and Gas Sensor](https://www.adafruit.com/product/5046)
The long-awaited BME688 from Bosch gives you&nbsp;_all the environmental sensing you want_&nbsp;in one small package. This little sensor contains&nbsp; **temperature** ,&nbsp; **humidity** ,&nbsp; **barometric pressure,** &nbsp;and&nbsp; **VOC...**

In Stock
[Buy Now](https://www.adafruit.com/product/5046)
[Related Guides to the Product](https://learn.adafruit.com/products/5046/guides)
![Angled shot of BME688 sensor breakout.](https://cdn-shop.adafruit.com/640x480/5046-05.jpg)

### Lithium Ion Polymer Battery - 3.7v 2500mAh

[Lithium Ion Polymer Battery - 3.7v 2500mAh](https://www.adafruit.com/product/328)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of **2500mAh** for a total of about 10 Wh. If you need a smaller battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/328)
[Related Guides to the Product](https://learn.adafruit.com/products/328/guides)
![Lithium Ion Polymer Battery 3.7v 2500mAh with JST 2-PH connector](https://cdn-shop.adafruit.com/640x480/328-06.jpg)

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

### 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)
![Angled shot of coiled pink and purple USB cable with USB A and USB C connectors.](https://cdn-shop.adafruit.com/640x480/5153-02.jpg)

### Black Nylon Machine Screw and Stand-off Set – M2.5 Thread

[Black Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)
Totaling 380 pieces, this **M2.5 Screw Set** &nbsp;is a must-have for your workstation.&nbsp;You'll have enough screws, nuts, and hex standoffs to fuel your maker tendencies&nbsp;for days on end! M2.5 size screws fit almost all of the Adafruit breakout/dev board mounting holes...

In Stock
[Buy Now](https://www.adafruit.com/product/3299)
[Related Guides to the Product](https://learn.adafruit.com/products/3299/guides)
![Black Nylon Screw and Stand-off Set with M2.5 Threads, kit box](https://cdn-shop.adafruit.com/640x480/3299-00.jpg)

# Getting Started with Microsoft Azure and CircuitPython

## 3D Printing

![](https://cdn-learn.adafruit.com/assets/assets/000/112/240/medium800/temperature___humidity_edited_P1370796.png?1654267493)

The project may be mounted on a 3D printed stand, described below. The stand consists of two parts: the Feather mounting stand and the battery cover. Both parts print with no supports.

The STL files can be downloaded directly here.

[featherTFTstand.zip](https://cdn-learn.adafruit.com/assets/assets/000/112/262/original/featherTFTstand.zip?1654286257)
The Feather mounting stand has mounting holes for the Feather ESP32-S2 TFT and the BME688 STEMMA board.

![temperature___humidity_edited_P1370789.png](https://cdn-learn.adafruit.com/assets/assets/000/112/241/medium640/temperature___humidity_edited_P1370789.png?1654267544)

The stand has a jaunty angle for better viewing of the Feather's TFT screen.

![temperature___humidity_edited_P1370798.png](https://cdn-learn.adafruit.com/assets/assets/000/112/242/medium640/temperature___humidity_edited_P1370798.png?1654267574)

Behind the mounting board is a slot for a battery to sit. The battery lid fits loosely over the slot and has a cutout for the battery wire.

![temperature___humidity_edited_P1370800.png](https://cdn-learn.adafruit.com/assets/assets/000/112/243/medium640/temperature___humidity_edited_P1370800.png?1654267616)

# Getting Started with Microsoft Azure and CircuitPython

## Create a Microsoft Azure Account

Before you can get started with Microsoft Azure, you need to create an account. There are multiple tiers of accounts, including a free version.&nbsp;

Go to the [Microsoft Azure website](https://aka.ms/adafruit/tutorial3/AzureSignup) and click on Try Azure for Free.

![temperature___humidity_freeAccount.png](https://cdn-learn.adafruit.com/assets/assets/000/112/187/medium640/temperature___humidity_freeAccount.png?1654115181)

Click on Start Free to proceed in creating a free account.

![temperature___humidity_startFree.png](https://cdn-learn.adafruit.com/assets/assets/000/112/188/medium640/temperature___humidity_startFree.png?1654115270)

You can create a new account, sign-in with your Microsoft account or sign-in with your GitHub account.

![temperature___humidity_InkeduseMicrosoftAccount_LI.jpg](https://cdn-learn.adafruit.com/assets/assets/000/112/190/medium640/temperature___humidity_InkeduseMicrosoftAccount_LI.jpg?1654115351)

![temperature___humidity_signInOptions.png](https://cdn-learn.adafruit.com/assets/assets/000/112/191/medium640/temperature___humidity_signInOptions.png?1654115366)

After signing in, you'll be prompted to enter your information.

![temperature___humidity_createAccount.png](https://cdn-learn.adafruit.com/assets/assets/000/112/192/medium640/temperature___humidity_createAccount.png?1654115425)

Even with the free account, you do need to enter a payment method. Nothing is charged unless you change settings later.

![temperature___humidity_enterCard.png](https://cdn-learn.adafruit.com/assets/assets/000/112/193/medium640/temperature___humidity_enterCard.png?1654115453)

After entering all of your information, your Azure account setup will be complete. You can navigate to the Azure portal to get started with creating an application.

![temperature___humidity_setupComplete.png](https://cdn-learn.adafruit.com/assets/assets/000/112/194/medium640/temperature___humidity_setupComplete.png?1654115529)

# Getting Started with Microsoft 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)

# Getting Started with Microsoft 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!

# Getting Started with Microsoft 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_feather_esp32s2_tft/)
 **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/769/medium800/adafruit_products_FTFT_reset_NeoPixel.jpg?1641925114)

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

Double-click the **reset** button (highlighted in red above), and you will see the **RGB status LED(s)** turn green (highlighted in green above). 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.

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.

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.

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.**

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

&nbsp;

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

![adafruit_products_FTFT_FTHRS2BOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/107/771/medium640/adafruit_products_FTFT_FTHRS2BOOT.png?1641926447)

![adafruit_products_FTFT_drag_UF2.png](https://cdn-learn.adafruit.com/assets/assets/000/107/772/medium640/adafruit_products_FTFT_drag_UF2.png?1641926456)

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)

# Getting Started with Microsoft Azure and CircuitPython

## Coding the Feather ESP32-S2 TFT Azure Display

Once you've finished setting up your Feather ESP32-S2 TFT 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/Feather_ESP32-S2_TFT_Azure/code.py

## Upload the Code and Libraries to the Feather ESP32-S2 TFT

After downloading the Project Bundle, plug your Feather ESP32-S2 TFT 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 Feather ESP32-S2 TFT's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **roundedHeavy-26.bdf**
- **bmeTFT.bmp**
- **code.py**

Your Feather ESP32-S2 TFT&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder, the **bmeTFT.bmp** image file, the **roundedHeavy-26.bdf** bitmap font file, and the&nbsp; **code.py&nbsp;** file.

![circuitpy](https://adafruit.github.io/Adafruit_Learning_System_Guides/Feather_ESP32-S2_TFT_Azure.png )

## **settings.toml**

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

```auto
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 [Connect Your Device](https://learn.adafruit.com/getting-started-with-microsoft-azure/connect-your-device) page in this guide to see the process for accessing the keys.

## How the CircuitPython Code Works
The code begins by connecting to WiFi and grabbing the date and time using the `adafruit_ntp` library. The `tz_offset` can be set to your local timezone.

```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!")

#  ntp clock - update tz_offset to your timezone
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
ntp = adafruit_ntp.NTP(pool, tz_offset=-4)
rtc.RTC().datetime = ntp.datetime
```

## Connect to Microsoft Azure
Next, a connection is established with Microsoft Azure.

```python
esp = None
pool = socketpool.SocketPool(wifi.radio)
device = IoTCentralDevice(
    pool, ssl_context, getenv("id_scope"), getenv("device_id"), getenv("device_primary_key")
)

print("Connecting to Azure IoT Central...")
device.connect()
print("Connected to Azure IoT Central!")
```

## I2C Setup
The BME688 sensor is setup, along with the onboard battery monitor. Variables are created to hold the values of the sensor and the battery monitor. An equation is used to convert the temperature to Fahrenheit.

```python
i2c = board.I2C()  # uses board.SCL and board.SDA
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)

# change this to match the location's pressure (hPa) at sea level
bme680.sea_level_pressure = 1013.25

temperature_offset = -5

# Create sensor object, using the board's default I2C bus.
battery_monitor = LC709203F(board.I2C())

# Update to match the mAh of your battery for more accurate readings.
# Can be MAH100, MAH200, MAH400, MAH500, MAH1000, MAH2000, MAH3000.
# Choose the closest match. Include "PackSize." before it, as shown.
battery_monitor.pack_size = PackSize.MAH2000

temp = int((bme680.temperature * 9/5) + (32 + temperature_offset))
humidity = int(bme680.relative_humidity)
pressure = int(bme680.pressure)
battery = battery_monitor.cell_percent
```

## DisplayIO Setup
There are a series of `displayio` elements being used. The background bitmap has the vector icons for the environmental readings and the battery. `Label` text elements using a `bitmap_font` are added in the code to display the readings from the BME688.

A `vectorio.Rectangle` is using to show battery life since the size of the rectangle can be changed in the loop. It also uses a special `Palette` that includes green and red. Once the battery life goes below a certain threshold, the rectangle is shown as red.

```python
display = board.DISPLAY

palette0 = displayio.Palette(2)
palette0[0] = 0x00FF00
palette0[1] = 0xFF0000

bitmap = displayio.OnDiskBitmap("/bmeTFT.bmp")
tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
group = displayio.Group()
group.append(tile_grid)
rect = vectorio.Rectangle(pixel_shader=palette0, width=22, height=10, x=12, y=116, color_index = 0)
group.append(rect)
font_file = "/roundedHeavy-26.bdf"
font = bitmap_font.load_font(font_file)
temp_text = bitmap_label.Label(font, text="%0.1f° F" % temp, color=0xFFFFFF)
temp_text.x = 20
temp_text.y = 80
humid_text = bitmap_label.Label(font, text="%0.1f %%" % humidity, color=0xFFFFFF)
humid_text.x = 95
humid_text.y = 80
press_text = bitmap_label.Label(font, text="%0.2f" % pressure, color=0xFFFFFF)
press_text.x = 170
press_text.y = 80
time_text = bitmap_label.Label(terminalio.FONT, 
            text="\n".join(wrap_text_to_lines("Data sent on %s/%s/%s at %s:%s" % (mon,day,year,hour,minute), 20)), 
            color=0xFFFFFF)
time_text.x = 125
time_text.y = 105
group.append(temp_text)
group.append(humid_text)
group.append(press_text)
group.append(time_text)
display.root_group = group
```

## Clocks
There are two variables setup for time keeping, `azure_clock` and `feather_clock`. The `azure_clock` counts down to sending data to Microsoft Azure and the `feather_clock` counts down to updating the TFT screen.

```python
azure_clock = 750
feather_clock = 30
```

## The Loop - Sending Data to Microsoft Azure
Once the `azure_clock` count is reached, the data is packed into a JSON message that is sent to Microsoft Azure. `ntp.datetime` is used to grab the date and time that the message is being sent. The `time_text` element is updated to display this timestamp. Finally, the `azure_clock` is reset to `0`.

```python
if azure_clock is 750:
           print("getting msg")
            message = {"Temperature": temp,
                       "Humidity": humidity,
                       "Pressure": pressure,
                       "BatteryPercent": battery}
            print("sending json")
            device.send_telemetry(json.dumps(message))
            print("data sent")
            print("getting ntp date/time")
            cal = ntp.datetime
            year = cal[0]
            mon = cal[1]
            day = cal[2]
            hour = cal[3]
            minute = cal[4]
            time.sleep(2)
            clock_view = "%s:%s" % (hour, minute)
            if minute < 10:
                clock_view = "%s:0%s" % (hour, minute)
            print("updating time text")
            time_text.text="\n".join(wrap_text_to_lines("Data sent on %s/%s/%s at %s" % (mon,day,year,clock_view), 20))
            azure_clock = 0
```

## Updating the TFT
Once the `feather_clock` count is reached, the TFT screen is updated with the current values from the BME688 and the `battery_monitor`. The `feather_clock` is then reset to `0`.

```python
if feather_clock is 30:
      temp = int((bme680.temperature * 9/5) + (32 + temperature_offset))
      humidity = int(bme680.relative_humidity)
      pressure = int(bme680.pressure)
      battery = battery_monitor.cell_percent
      battery_display = round(simpleio.map_range(battery, 0, 100, 0, 22))
      rect.width = int(battery_display)
      if battery_monitor.cell_percent < 20:
        rect.color_index = 1
      print("updating screen")
      temp_text.text = "%0.1f° F" % temp
      humid_text.text = "%0.1f %%" % humidity
      press_text.text = "%0.2f" % pressure
      feather_clock = 0
```

## Keeping Count
Every second, the `feather_clock` and `azure_clock` counts are increased by `1`. `device.loop()` is also called to poll for messages from Microsoft Azure.

```python
feather_clock += 1
azure_clock += 1
device.loop()

time.sleep(1)
```

## Reconnect
If there is a connection error, a connection is reestablished with your WiFi network and Microsoft Azure by reloading the device.

```python
except (ValueError, RuntimeError, OSError, ConnectionError) as e:
        print("Network error, reconnecting\n", str(e))
        supervisor.reload()
        continue
```

# Getting Started with Microsoft 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/112/221/medium800/temperature___humidity_capabilities.png?1654182019)

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

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.

# Getting Started with Microsoft Azure and CircuitPython

## Create a Dashboard

![](https://cdn-learn.adafruit.com/assets/assets/000/112/195/medium800/temperature___humidity_dashboard2.png?1654115654)

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;

![temperature___humidity_makeLineChart1.png](https://cdn-learn.adafruit.com/assets/assets/000/126/001/medium640/temperature___humidity_makeLineChart1.png?1699495348)

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;

![temperature___humidity_makeLineChart2.png](https://cdn-learn.adafruit.com/assets/assets/000/126/002/medium640/temperature___humidity_makeLineChart2.png?1699495166)

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

![temperature___humidity_temp_graph.png](https://cdn-learn.adafruit.com/assets/assets/000/126/000/medium640/temperature___humidity_temp_graph.png?1699494909)

You can add as many tiles as you want to fully customize your dashboard.

# Getting Started with Microsoft Azure and CircuitPython

## Create Alerts

![](https://cdn-learn.adafruit.com/assets/assets/000/112/207/medium800/temperature___humidity_rules.png?1654117856)

You can create Rules to alert you about certain data thresholds. These alerts can be emailed to you or setup with webhooks.

Navigate to the Rules page on the side menu bar.

![temperature___humidity_rulesMenu.png](https://cdn-learn.adafruit.com/assets/assets/000/112/204/medium640/temperature___humidity_rulesMenu.png?1654117769)

Click on New to create a new rule.

![temperature___humidity_newRule.png](https://cdn-learn.adafruit.com/assets/assets/000/112/206/medium640/temperature___humidity_newRule.png?1654117837)

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

![temperature___humidity_rules1.png](https://cdn-learn.adafruit.com/assets/assets/000/112/208/medium640/temperature___humidity_rules1.png?1654118037)

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.

![temperature___humidity_rules2.png](https://cdn-learn.adafruit.com/assets/assets/000/112/209/medium640/temperature___humidity_rules2.png?1654118102)

You can enter multiple telemetry options depending on what you're monitoring for. For example, you could monitor humidity to make sure it never dips below or above certain amounts.

![temperature___humidity_rules4.png](https://cdn-learn.adafruit.com/assets/assets/000/112/212/medium640/temperature___humidity_rules4.png?1654118386)

Under Actions, you'll select either an email or webhook alert.

![temperature___humidity_rules3.png](https://cdn-learn.adafruit.com/assets/assets/000/112/210/medium640/temperature___humidity_rules3.png?1654118293)

The email will let you know which rule has been triggered with the timestamp.

![temperature___humidity_emailWhite.png](https://cdn-learn.adafruit.com/assets/assets/000/112/214/medium640/temperature___humidity_emailWhite.png?1654118567)

![](https://cdn-learn.adafruit.com/assets/assets/000/112/216/medium800/temperature___humidity_webhookRule.png?1654118628)

The webhook option allows you to integrate your application with other Azure and Microsoft services, including [Microsoft Flow (also referred to as Power Automate)](https://aka.ms/adafruit/tutorial1/powerautomate).

# Getting Started with Microsoft Azure and CircuitPython

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/112/244/medium800/temperature___humidity_edited_P1370804.png?1654267649)

Attach M2.5 standoffs to the mounting holes with M2.5 screws.

![temperature___humidity_edited_P1370794.png](https://cdn-learn.adafruit.com/assets/assets/000/112/245/medium640/temperature___humidity_edited_P1370794.png?1654267702)

Secure the Feather ESP32-S2 TFT and BME688 STEMMA board to the standoffs with M2.5 screws.

![temperature___humidity_edited_P1370784.png](https://cdn-learn.adafruit.com/assets/assets/000/112/246/medium640/temperature___humidity_edited_P1370784.png?1654267755)

Connect the BME688 to the Feather ESP32-S2 TFT with a STEMMA QT cable.

![temperature___humidity_edited_P1370788.png](https://cdn-learn.adafruit.com/assets/assets/000/112/247/medium640/temperature___humidity_edited_P1370788.png?1654267812)

Insert a battery into the battery slot. Plug the battery into the Feather ESP32-S2 TFT's JST battery plug.

![temperature___humidity_edited_P1370782.png](https://cdn-learn.adafruit.com/assets/assets/000/112/248/medium640/temperature___humidity_edited_P1370782.png?1654267874)

Place the battery cover over the battery, sliding the battery's wire through the cover's slot. That completes the assembly!

![temperature___humidity_edited_P1370755.png](https://cdn-learn.adafruit.com/assets/assets/000/112/249/medium640/temperature___humidity_edited_P1370755.png?1654267940)

# Getting Started with Microsoft Azure and CircuitPython

## Usage

![](https://cdn-learn.adafruit.com/assets/assets/000/112/250/medium800/temperature___humidity_edited_P1370770.png?1654268033)

Power up the Feather ESP32-S2 TFT with either a fully charged LiPo battery or a USB cable to start displaying and logging your data!

You'll see the current data from the BME688 updated on the TFT screen every 30 seconds.

![temperature___humidity_edited_P1370760.png](https://cdn-learn.adafruit.com/assets/assets/000/112/251/medium640/temperature___humidity_edited_P1370760.png?1654268095)

When battery life runs low, the battery icon will show as red.

![temperature___humidity_edited_P1370745.png](https://cdn-learn.adafruit.com/assets/assets/000/112/252/medium640/temperature___humidity_edited_P1370745.png?1654268210)

You can use all of the Microsoft Azure IoT Central application options to expand on your project with dashboards, alerts, data exports and webhooks.&nbsp;


## Featured Products

### Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT

[Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT](https://www.adafruit.com/product/5300)
We've got a new machine here at Adafruit, it can uncover your deepest desires. Don't believe me? I'll turn it on right now to prove it to you! What, you want unlimited mozzarella sticks? OK well, that's not something we can provide. But we can provide your...

In Stock
[Buy Now](https://www.adafruit.com/product/5300)
[Related Guides to the Product](https://learn.adafruit.com/products/5300/guides)
### Adafruit BME688 - Temperature, Humidity, Pressure and Gas Sensor

[Adafruit BME688 - Temperature, Humidity, Pressure and Gas Sensor](https://www.adafruit.com/product/5046)
The long-awaited BME688 from Bosch gives you&nbsp;_all the environmental sensing you want_&nbsp;in one small package. This little sensor contains&nbsp; **temperature** ,&nbsp; **humidity** ,&nbsp; **barometric pressure,** &nbsp;and&nbsp; **VOC...**

In Stock
[Buy Now](https://www.adafruit.com/product/5046)
[Related Guides to the Product](https://learn.adafruit.com/products/5046/guides)
### Lithium Ion Polymer Battery - 3.7v 2500mAh

[Lithium Ion Polymer Battery - 3.7v 2500mAh](https://www.adafruit.com/product/328)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of **2500mAh** for a total of about 10 Wh. If you need a smaller battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/328)
[Related Guides to the Product](https://learn.adafruit.com/products/328/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/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)
### Black Nylon Machine Screw and Stand-off Set – M2.5 Thread

[Black Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)
Totaling 380 pieces, this **M2.5 Screw Set** &nbsp;is a must-have for your workstation.&nbsp;You'll have enough screws, nuts, and hex standoffs to fuel your maker tendencies&nbsp;for days on end! M2.5 size screws fit almost all of the Adafruit breakout/dev board mounting holes...

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

## Related Guides

- [Adafruit BME680](https://learn.adafruit.com/adafruit-bme680-humidity-temperature-barometic-pressure-voc-gas.md)
- [Adafruit ESP32-S2 TFT Feather](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather.md)
- [MIDI Laser Harp with Time of Flight Distance Sensors](https://learn.adafruit.com/midi-laser-harp-time-of-flight-sensors.md)
- [PyPortal Titano Weather Station](https://learn.adafruit.com/pyportal-titano-weather-station.md)
- [Feather TFT STEMMA Case](https://learn.adafruit.com/feather-tft-stemma-case.md)
- [USB Host to BLE Keyboard Adapter](https://learn.adafruit.com/esp32-s3-usb-to-ble-keyboard-adapter.md)
- [HalloWing M4 Animated Eye Candy Bowl](https://learn.adafruit.com/hallowing-m4-candy-bowl.md)
- [DIY Pico Mechanical Keyboard with Fritzing and CircuitPython](https://learn.adafruit.com/diy-pico-mechanical-keyboard-with-fritzing-circuitpython.md)
- [3D Printed Frame for Adafruit IS31FL3741 LED Glasses](https://learn.adafruit.com/3d-printed-frame-for-led-glasses-is31fl3741.md)
- [Adafruit IO Basics: Digital Output](https://learn.adafruit.com/adafruit-io-basics-digital-output.md)
- [CircuitPython OLED Watch Clock](https://learn.adafruit.com/circuitpython-oled-watch.md)
- [3D Printed Case for Adafruit Feather](https://learn.adafruit.com/3d-printed-case-for-adafruit-feather.md)
- [HalloWing Magic 9 Ball](https://learn.adafruit.com/hallowing-magic-9-ball.md)
- [USB C Power Delivery Monitor](https://learn.adafruit.com/usb-c-benchtop-power-supply.md)
- [Qualia S3 Compass](https://learn.adafruit.com/qualia-s3-compass.md)
- [Circle of Fifths Euclidean Synth with synthio and CircuitPython](https://learn.adafruit.com/circle-of-fifths-euclidean-synth-with-synthio-and-circuitpython.md)
- [QT Py Snap Fit Case](https://learn.adafruit.com/qt-py-snap-fit-case.md)
