Giter VIP home page Giter VIP logo

purpleair-for-magtag's Introduction

A PurpleAir Dashboard For MagTag

MagTag Display

PurpleAir air quality sensors are great but their readings aren't as accessible as they could be. The MagTag is a battery powered E-Ink display with magnetic feet that sticks to your fridge and talks to purpleair.com over WiFI so it can display your sensor's current air quality reading. Its a complete package so you don't need to do any soldering. You just need to install software and edit a text file.

The dashboard shows the current AQI, the name of the sensor, a low battery warning as well as the date stamp of the sensor reading. The E-Ink display will remain readable even after the battery dies so if the time stamp is ever more than 15 minutes old then either the sensor or the MagTag stopped updating.

Install the Code

If you're not a git user, you can download the dashboard code by clicking on the green Code button above and choose Download ZIP.

Plug the MagTag into your computer and it will show up as a USB drive called CIRCUITPY. Copy the file code.py and the fonts folder to the drive. If the battery is plugged in you may need to hit the reset button first.

Follow the directions in this tutorial to install the necessary libraries from the latest bundle. You need a version of the library dated February 27, 2021 or later. https://learn.adafruit.com/creating-magtag-projects-with-circuitpython/magtag-specific-circuitpython-libraries

If things aren't working you might also need to install a new version of CircuitPython. If the face of your MagTag is black then its a newer version and you can do the UF2 installation and ignore the part about bin files. https://learn.adafruit.com/creating-magtag-projects-with-circuitpython/install-circuitpython

For further information see the Adafruit's MagTag learning guide. https://learn.adafruit.com/adafruit-magtag

Secrets File

secrets = {
    'ssid' : 'Your WiFi Network Name',
    'password' : 'Your WiFI Password',
    'sensor_id' : "Your PurpleAir Sensor's ID",
    'thingspeak_key': "Your Sensor's Key",
    'timezone_offset' : "-8",
}

Create a file called secrets.py in the top level of your CIRCUITPY drive containing your WiFi credentials and information about your sensor.

  1. Find your sensor on the PurpleAir map https://www.purpleair.com/map
  2. Click on the marker and when you mouse over Get This Widget another layer pops up. Click the link to the JSON file.
  3. The ID field is your sensor_id and if your sensor is private you'll need the THINGSPEAK_PRIMARY_ID_READ_KEY too.
'timezone_offset' : "-8",

Add a time zone offset for your location. In the US, Eastern Standard time has an offset of -5, Central is -6, Mountain is -7 and Pacific Standard time is -8. Other offsets can be found at
https://en.wikipedia.org/wiki/List_of_UTC_time_offsets

'sensor_alias' : "PurpleAir",

When you registered your sensor you gave it a name and that name will be shown on the display. You can make it say something else by adding an entry for sensor_alias, which can be up to 25 characters.

'update_frequency': '20'

This is the number of minutes between updates. When my MagTag sleeps 10 minutes between updates a battery charge me about a week. The battery lasts considerably longer if you only update once per hour. Be kind to the PurpleAir site and don't update more often than every ten minutes.

Finally

As you make changes to things on your CIRCUITPY drive, the MagTag will restart automatically. You can force it by pressing the reset button above the USB port. After resetting, it will take several seconds for the screen to update. After that it should update every 10 minutes.

If you have trouble getting it to update, it may be having trouble connecting to the network so try moving it closer to your WiFI router. Also, make sure that the power switch on the top left corner is in the on position to the right.

See Also

MagTag product page
https://www.adafruit.com/product/4819

Adabox 17 Unboxing showing assembly and other projects
https://www.youtube.com/watch?v=_YfmqJiznDY

Getting started with the MagTag
https://learn.adafruit.com/adafruit-magtag

Creating Projects with the MagTag
https://learn.adafruit.com/creating-magtag-projects-with-circuitpython

Deep Sleep and Battery Usage
https://learn.adafruit.com/deep-sleep-with-circuitpython

CircuitPython Display Support Using displayio
https://learn.adafruit.com/circuitpython-display-support-using-displayio

Getting Started With CircuitPython
https://learn.adafruit.com/welcome-to-circuitpython

Source Sans Pro font family
https://fonts.google.com/specimen/Source+Sans+Pro?query=source+sa

Creating custom fonts for CircuitPython
https://learn.adafruit.com/custom-fonts-for-pyportal-circuitpython-display

PurpleAir PM2.5 performance across the U.S.#2
https://cfpub.epa.gov/si/si_public_record_report.cfm?Lab=CEMM&dirEntryId=348236

PurpleAir PM2.5 U.S. Correction and Performance During Smoke Events 4/2020
https://cfpub.epa.gov/si/si_public_record_report.cfm?Lab=CEMM&dirEntryId=349513

purpleair-for-magtag's People

Contributors

endico avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

purpleair-for-magtag's Issues

PurpleAir turning down the json API

The endpoint this code uses is going away. The replacement requires the API key to be in a header. I think this means updating to a new version of the MagTag libraries. Has anyone already done this?

When should the "Battery Low" warning appear?

Ideally it would be nice to have the battery warning appear maybe 12 hours before the MagTag dies due to low power. That should give plenty of time to notice the problem and recharge the MagTag.

I originally had the warning appear when the battery reached 3.8 volts but that guess is way too high. I think the MagTag has lasted a week so far since the warning appeared. I have a battery testing script running and 3.3 is about the point where the battery drain accelerates so I'll set it there for now but I may lower it some more later when testing is complete.

https://io.adafruit.com/endico/feeds/battery
https://github.com/endico/Magtag-Battery-Test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.