# PyPortal IoT Data Logger with Analog Devices ADT7410, Adafruit IO and CircuitPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/072/075/medium800thumb/adafruit_io_ezgif.com-video-to-gif_%288%29.jpg?1551373616)

_Connected your PyPortal to the internet, but do you want to do more with your data?_

This guide will get your PyPortal communicating with our Internet of Things service - Adafruit IO using the easy-to-use&nbsp;[Adafruit IO CircuitPython library](https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO).

Aside from being a fantastic internet-connected display, the PyPortal includes a light sensor and a temperature sensor. Using these two sensors, we can capture and send data to _the best data service in the world_ - [Adafruit IO](http://io.adafruit.com) - for real-time data visualization and logging.&nbsp;

We'll be using the [Analog Devices ADT7410](https://www.analog.com/en/products/adt7410.html) built into the PyPortal to measure the ambient temperature over I2C

![adafruit_io_adt.jpg](https://cdn-learn.adafruit.com/assets/assets/000/072/108/medium640/adafruit_io_adt.jpg?1551410134)

## **Adafruit IO**

**Adafruit IO is the easiest way to stream, log, and interact with your data.** &nbsp;It's built from the ground up to be easy to use - we do the hard stuff so you can focus on the fun stuff.

Data such as temperature and light levels can be hard to visualize and quantify - Adafruit IO makes it simple. Send IO your data and it can store and display it using charts, graphs, gauges, and more!

![adafruit_io_IO_-_PyPortal_Logger.png](https://cdn-learn.adafruit.com/assets/assets/000/071/958/medium640/adafruit_io_IO_-_PyPortal_Logger.png?1551202743)

## CircuitPython Code

Adafruit's CircuitPython is great for building Internet-of-Things projects. Using the [Adafruit IO CircuitPython module](https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO), you can easily send data to Adafruit IO, receive data from Adafruit IO, and easily manipulate data with the powerful Adafruit IO API.

You can rapidly update your code without having to compile and store WiFi and API secret keys on the device. This means that there's no editing code and re-uploading whenever you move the PyPortal to another network - just update a file and you're set.&nbsp;

![adafruit_io_circuitpython_for_guide.png](https://cdn-learn.adafruit.com/assets/assets/000/071/949/medium640/adafruit_io_circuitpython_for_guide.png?1551200980)

## Prerequisite Guides

If you're new to Adafruit IO or CircuitPython, take a moment to walk through the following guides to get you started and up-to-speed:

- [Welcome to Adafruit IO](https://learn.adafruit.com/welcome-to-adafruit-io/)
- [Welcome to CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython)

## Parts
You only need a PyPortal for this guide - you'll be using the temperature and light sensors included with the PyPortal. No other sensors or external circuitry required!

### Adafruit PyPortal - CircuitPython Powered Internet Display

[Adafruit PyPortal - CircuitPython Powered Internet Display](https://www.adafruit.com/product/4116)
 **PyPortal** , our easy-to-use IoT device that allows you to create all the things for the “Internet of Things” in minutes. Make custom touch screen interface GUIs, all open-source, and Python-powered using&nbsp;tinyJSON / APIs to get news, stock, weather, cat photos,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4116)
[Related Guides to the Product](https://learn.adafruit.com/products/4116/guides)
![Front view of a Adafruit PyPortal - CircuitPython Powered Internet Display with a pyportal logo image on the display. ](https://cdn-shop.adafruit.com/640x480/4116-00.jpeg)

## Materials
You'll need some extra supplies to finish this project. If you do not have them already, pick some up from Adafruit:

### Part: USB Cable
quantity: 1
USB cable - USB A to Micro-B - 3 foot long
[USB Cable](https://www.adafruit.com/product/592)

# PyPortal IoT Data Logger with Analog Devices ADT7410, Adafruit IO and CircuitPython

## Adafruit IO Setup

## Feed Setup

If you do not already have an Adafruit IO account set up, head over to [io.adafruit.com](http://io.adafruit.com/) to link your Adafruit.com account to Adafruit IO.

The first step is to create a new Adafruit IO feed to hold the data from the PyPortal's temperature sensor. Navigate to the [feeds page](https://io.adafruit.com/feeds) on Adafruit IO. Then click **Feeds -\> +New Feed** and name this feed&nbsp;_temperature_.

- If you do not already know how to create a feed, head over to [Adafruit IO Basics: Feeds](https://learn.adafruit.com/adafruit-io-basics-feeds).

![](https://cdn-learn.adafruit.com/assets/assets/000/071/951/medium800/adafruit_io_weather_tmp_Feed.png?1551201999)

You'll also want a second feed to store the value of the light sensor - **create another feed named&nbsp;_light_.**

## Dashboard Setup

Next, you'll create a dashboard to display the values from the feeds you created.

- If you do not know how to create or use Dashboards in Adafruit IO, head over to the [Adafruit IO Basics: Dashboards](https://learn.adafruit.com/adafruit-io-basics-dashboards) guide.

From your dashboard, **&nbsp;select the Gauge block.&nbsp;**

![adafruit_io_weather_IO_-_Feather_Huzzah___ADT7410_Gauge.png](https://cdn-learn.adafruit.com/assets/assets/000/071/952/medium640/adafruit_io_weather_IO_-_Feather_Huzzah___ADT7410_Gauge.png?1551202362)

 **Select the _temperature_ feed**

![adafruit_io_weather_temperature.png](https://cdn-learn.adafruit.com/assets/assets/000/071/955/medium640/adafruit_io_weather_temperature.png?1551202401)

In the Block Settings step,&nbsp;set the **Block Title** to **Temperature** , set the **Gauge Min/Max Values** to the upper and lower temperature thresholds&nbsp;you want to measure.

You can label the gauge by setting the **Gauge Label** - this example assumes temperature is to be measured in Degrees C.

_Uncomfortably hot or cold?&nbsp;_You can optionally set the gauge change color to warn you if the temperature goes above (or below) a certain value.

![adafruit_io_weather_IO_-_Feather_Huzzah___ADT7410.png](https://cdn-learn.adafruit.com/assets/assets/000/071/956/medium640/adafruit_io_weather_IO_-_Feather_Huzzah___ADT7410.png?1551202443)

After adding the gauge element, your dashboard will look like the following:

![](https://cdn-learn.adafruit.com/assets/assets/000/071/957/medium800/adafruit_io_dash_gauge_only.png?1551202538)

Next, **create another gauge block for the _light feed_** :

![](https://cdn-learn.adafruit.com/assets/assets/000/071/960/medium800/adafruit_io_both_gauges.png?1551202810)

While displaying the current values of the temperature is useful, Adafruit IO stores data so you can monitor how it changes a long period of time.

To do this, we'll use the **Line Chart** block - a block used to graph one or more feeds - and set it up to show both the light value and the temperature value over a long period of time.&nbsp;&nbsp;

 **Create a new block and check the light feed, and then the temperature feed.** &nbsp;You can select up to five different feeds to display using this block.

![adafruit_io_block_settings_line.png](https://cdn-learn.adafruit.com/assets/assets/000/071/961/medium640/adafruit_io_block_settings_line.png?1551203182)

Your finished dashboard should look like the following:

![](https://cdn-learn.adafruit.com/assets/assets/000/071/962/medium800/adafruit_io_active_chart_dash.png?1551203794)

You are also going to need your Adafruit IO username and secret API key.

**Navigate to your profile and click the View AIO Key button** to retrieve them. Write them down in a safe place, you'll need them for the next step.

![](https://cdn-learn.adafruit.com/assets/assets/000/071/959/medium800thumb/weather_3d_printing_adafruit_io_username_and_password.jpg?1551202777)

# PyPortal IoT Data Logger with Analog Devices ADT7410, Adafruit IO and CircuitPython

## CircuitPython Code

## CircuitPython Library Installation
The [Adafruit\_CircuitPython\_AdafruitO module](https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO)&nbsp;allows you to easily write CircuitPython code which can interact with Adafruit IO.

You'll need to install the&nbsp;[Adafruit CircuitPython Adafruit IO](https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO)&nbsp;and the [Adafruit CircuitPython ADT7410](https://github.com/adafruit/Adafruit_CircuitPython_ADT7410) libraries on your PyPortal.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://github.com/adafruit/circuitpython/releases) for your board.

Next&nbsp;[connect to the board's serial REPL&nbsp;](https://learn.adafruit.com/welcome-to-circuitpython/kattni-connecting-to-the-serial-console)so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

Once you have your CircuitPython libraries installed, let's get your PyPortal connected to Adafruit IO and the internet. To this, you'll create&nbsp;a _settings_ file.

## Settings File Setup
If you have not yet set up a settings.toml file in your `CIRCUITPY` drive and connected to the internet using it, [follow this guide and come back when you've successfully connected to the internet](https://learn.adafruit.com/adafruit-pyportal/internet-connect#whats-a-secrets-file-15-1).&nbsp;

Next, you should add your Adafruit IO Username and Adafruit IO Key to the **settings.toml** file.

Your **settings.toml** file should look like this:

```auto
CIRCUITPY_WIFI_SSID="your-wifi-ssid"
CIRCUITPY_WIFI_PASSWORD="your-wifi-password"
ADAFRUIT_AIO_USERNAME="my_username"
ADAFRUIT_AIO_KEY="my_key"
timezone="America/New_York" # http://worldtimeapi.org/timezones
```

 **Change** `my_username` and `my_key` **to your Adafruit IO username and the secret key**.

After you finish editing **settings.toml** , make sure to **save the file** &nbsp;(cmd/ctrl+s).

## Code

Using a text-editor (we like&nbsp;[Mu](https://codewith.mu/)&nbsp;since it has a built-in serial REPL), copy the code below to your CircuitPython board,and save it as **code.py.**

Click the Download Project Bundle button below to download a zip containing all of the required project files and libraries. Unzip it and copy the files to the **CIRCUITPY** drive.

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

Warning: 

Before running the code, verify&nbsp; **CIRCUITPY** &nbsp;looks like the following.

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

From the Mu Editor, **click the Serial button** to open the REPL. You should see the REPL displaying the temperature and light values from the PyPortal's onboard sensors, and sending the data to Adafruit IO:

```auto
Light Level:  37376
Temperature: 31.60 C
Sending to Adafruit IO...
Sent to Adafruit IO!
Delaying 30 seconds...
```

Your PyPortal should also display what is currently printed to the REPL.

![adafruit_io_ezgif.com-video-to-gif_(8).gif](https://cdn-learn.adafruit.com/assets/assets/000/072/074/medium640thumb/adafruit_io_ezgif.com-video-to-gif_%288%29.jpg?1551370625)

 **Open the Adafruit IO Dashboard you created earlier**. Notice that the fill and values of the gauges change as values are sent from your PyPortal to Adafruit IO.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/072/004/medium800thumb/adafruit_io_ezgif.com-gif-maker_%283%29.jpg?1551219278)

Then, leave the PyPortal running for a while and come back later to see new data appear on the line graph.

![](https://cdn-learn.adafruit.com/assets/assets/000/072/005/medium800thumb/adafruit_io_ezgif.com-gif-maker_%284%29.jpg?1551219607)

### 

Change&nbsp;the&nbsp;`IO_DELAY`&nbsp;value at the top of the program.

For example, if you wish to send data to Adafruit IO every minute, **&nbsp;change the following line from** :

`IO_DELAY = 30`

**to**

`IO_DELAY= 60`

**Note:** &nbsp;Setting this value lower than 30 seconds will likely cause Adafruit IO to throw a throttling error - you can only send 30 data points per minute (or 60 data points per minute with Adafruit IO Plus) to Adafruit IO.

### 

By default, Adafruit IO supports six points of precision (decimal places). However, in the code, you are only sending two .

To increase the precision of the temperature values you're sending&nbsp; **from 2 to 4** , modify the following line from:

`io.send_data(temperature_feed['key'], temperature, precision=2)`

to:

`io.send_data(temperature_feed['key'], temperature, precision=4)`

## Taking it Further
For more examples and ideas - [check out the Adafruit IO category on the Adafruit Learning System](https://learn.adafruit.com/category/adafruit-io).

On the CircuitPython Adafruit IO library repository, you'll find [we've included lots of examples](https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO/tree/main/examples) for sending data, interacting with your CircuitPython board's digital inputs and outputs, feed/group/data interaction, and _more_.&nbsp;


## Featured Products

### Adafruit PyPortal - CircuitPython Powered Internet Display

[Adafruit PyPortal - CircuitPython Powered Internet Display](https://www.adafruit.com/product/4116)
 **PyPortal** , our easy-to-use IoT device that allows you to create all the things for the “Internet of Things” in minutes. Make custom touch screen interface GUIs, all open-source, and Python-powered using&nbsp;tinyJSON / APIs to get news, stock, weather, cat photos,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4116)
[Related Guides to the Product](https://learn.adafruit.com/products/4116/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

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

## Related Guides

- [Adafruit PyPortal - IoT for CircuitPython](https://learn.adafruit.com/adafruit-pyportal.md)
- [PyPortal Twitter Follows Trophy](https://learn.adafruit.com/pyportal-twitter-follows-trophy.md)
- [PyPortal Reddit Stats Trophy](https://learn.adafruit.com/pyportal-reddit-stats-trophy.md)
- [PyPortal Hurricane Tracker](https://learn.adafruit.com/pyportal-hurricane-tracker.md)
- [PyPortal Voice Controlled Smart Switch and Time Display](https://learn.adafruit.com/pyportal-voice-controlled-smart-switch-and-time-display.md)
- [Adafruit IO Basics: Schedule Actions](https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers.md)
- [PyPortal 2FA TOTP Authentication Friend](https://learn.adafruit.com/pyportal-2fa-totp-authentication-friend.md)
- [League of Legends Level Trophy for PyPortal](https://learn.adafruit.com/league-of-legends-level-trophy-for-pyportal.md)
- [PyPortal IoT Plant Monitor with Google Cloud IoT Core and CircuitPython](https://learn.adafruit.com/pyportal-iot-plant-monitor-with-google-cloud-iot-core-and-circuitpython.md)
- [PyPortal WFH Busy Sounds Simulator](https://learn.adafruit.com/pyportal-wfh-busy-sounds-simulator.md)
- [PyPortal Halloween Countdown](https://learn.adafruit.com/pyportal-halloween-countdown.md)
- [PyPortal Tides Viewer](https://learn.adafruit.com/pyportal-tides-viewer.md)
- [CircuitPython Neko Kitty with Displayio](https://learn.adafruit.com/circuitpython-neko-kitty-with-displayio.md)
- [PyPortal Discord Online Counter](https://learn.adafruit.com/pyportal-discord-online-count.md)
- [CircuitPython Turtle Graphics](https://learn.adafruit.com/circuitpython-turtle-graphics.md)
