Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jwillikers/humidity-sensor-circuitpython

A portable humidity sensor using an RP2040 Feather and eInk display
https://github.com/jwillikers/humidity-sensor-circuitpython

adafruit adafruit-feather circuitpython eink embedded htu31d humidity humidity-sensor python rp2040

Last synced: about 1 month ago
JSON representation

A portable humidity sensor using an RP2040 Feather and eInk display

Awesome Lists containing this project

README

        

= Humidity Sensor CircuitPython
Jordan Williams
:experimental:
:icons: font
ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]
:Adafruit-CircuitPython-framebuf: https://github.com/adafruit/Adafruit_CircuitPython_framebuf[Adafruit CircuitPython framebuf]
:Adafruit-Feather-RP2040: https://learn.adafruit.com/adafruit-feather-rp2040-pico[Adafruit Feather RP2040]
:Asciidoctor_: https://asciidoctor.org/[Asciidoctor]
:CircuitPython: https://circuitpython.org/[CircuitPython]
:just: https://github.com/casey/just[just]
:pip-tools: https://github.com/jazzband/pip-tools[pip-tools]
:pipkin: https://github.com/aivarannamaa/pipkin[pipkin]
:pre-commit: https://pre-commit.com/[pre-commit]
:Python: https://www.python.org/[Python]

image:https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white[pre-commit, link=https://github.com/pre-commit/pre-commit]
image:https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json[Ruff, link=https://github.com/astral-sh/ruff]

A simple humidity sensor using the {Adafruit-Feather-RP2040}, monochrome eInk Display FeatherWing, and HTU31D humidity sensor, written in {CircuitPython}.

ifdef::env-github[]
++++


Humidity Sensor



Humidity Sensor Demo


++++
endif::[]

ifndef::env-github[]
image::pics/Humidity Sensor Top.jpg[Humidity Sensor, align=center]
image::pics/Humidity Sensor Demo.gif[Humidity Sensor Demo, align=center]
endif::[]

== Hardware

The hardware components comprising the humidity sensory are listed below.

.Humidity Sensor Components
* https://www.adafruit.com/product/4195[Adafruit 2.13" Monochrome eInk / ePaper Display FeatherWing - 250x122 Monochrome with SSD1680]
* https://www.adafruit.com/product/4884[Adafruit RP2040 Feather]
* https://www.adafruit.com/product/1570[Lithium Ion Polymer Battery - 3.7v 100mAh]
* https://www.adafruit.com/product/4832[HTU31D Humidity Sensor]
* https://www.adafruit.com/product/2830[Stacking Headers for Feather - 12-pin and 16-pin female headers]
* https://www.adafruit.com/product/4399[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long]

Programming will require a USB-C cable and a computer.

== How it Works

The humidity sensor samples the relative humidity and temperature once every second.
After five minutes, it finds the median of these values and updates the readings shown on the display.
A median is simple and accounts for outliers, making the displayed readings more consistent than one-off samples.
When the humidity sensor starts up, it immediately displays the value of a single reading from sensor.
This avoids undue delays for users.

== Shortcomings

Efficiency::
The battery life is abysmal.
The 105 mAh battery fails to sustain this power-hungry machine for more than several hours.
I'm hoping to get closer to a week's worth of life out of a single battery life.
Improvements to energy efficiency include the following.
+
.Power Optimizations
- [ ] Lower the clock speed.
- [ ] Store sensor readings with Direct Memory Access, aka _DMA_, to avoid waking the microcontroller as frequently.
Unfortunately, I don't believe this functionality is available in CircuitPython at this time.
- [ ] Put the RP2040 into deep sleep, waking only to refresh the screen.
If values must be stored in non-volatile memory, consider using an FRAM breakout instead of the onboard EEPROM.
- [ ] Increase the interval between updates of the screen.
- [ ] Cut the line to the LED on the humidity sensor breakout.

Deployment::
The required libraries are deployed with {pipkin}.
The required font bitmap used by this project is from the {Adafruit-CircuitPython-framebuf} example.
Simply install the `code.py` file and `font/font5x8.bin` to the board's root directory.

== Getting Started

The instructions here setup the software for the Feather RP2040.
It is assumed that you are on and familiar with Linux and using CircuitPython on microcontrollers.

[TIP]
====
To access the serial connection to the Feather RP2040 without requiring superuser privileges, add your user to the `dialout` group.

[,sh]
----
sudo usermod --append --groups dialout $USER
----

Now restart for the change to take effect.
====

. Install {just} by following the instructions in the https://github.com/casey/just?tab=readme-ov-file#installation[installation section].

. Clone this project's repository.
+
[,sh]
----
git clone https://github.com/jwillikers/humidity-sensor-circuitpython.git
----

. Change to the project's root directory.
+
[,sh]
----
cd humidity-sensor-circuitpython
----

. Install {just} by following the instructions in the https://github.com/casey/just?tab=readme-ov-file#installation[installation section].

. Hold down the button marked _bootsel_ on the Feather RP2040 while plugging it in to your computer with a USB-C cable.

. To download and install CircuitPython, run `just install-circuitpython`.
+
[,sh]
----
just install-circuitpython
----

. Now copy over the U2F bootloader to the RP2040.
+
[,sh]
----
cp ~/Downloads/adafruit-circuitpython-adafruit_feather_rp2040-en_US-7.2.5.uf2 /run/media/$USER/RPI-RP2
----

. Wait for the file to finish copying, after which the Feather RP2040's onboard storage should automatically be mounted.
This is mounted at `/run/media/jordan/CIRCUITPY` on my machine.

. Run `just init` to initialize the venv.
+
[,sh]
----
just init
----

. Mount the Feather RP2040 if needed.
+
[,sh]
----
udisksctl mount --block-device /dev/sda1
----

. Run `just install` to install everything to the Feather.
+
[,sh]
----
just install
----

== Development

It's recommended to use the provided {pre-commit} checks when developing.

. Run `just init-dev` to initialize the virtual environment for development.
This will install all of the necessary dependencies and the {pre-commit} hooks.
+
[,sh]
----
just init-dev
----

. To update dependencies, run `just update`.
+
[,sh]
----
just update
----

. Use `just --list` to list other available tasks.
+
[,sh]
----
just --list
----

== Documentation

.CircuitPython Documentation
* https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html[alarm]
* https://circuitpython.readthedocs.io/projects/epd/en/latest/[epd]
* https://circuitpython.readthedocs.io/projects/framebuf/en/latest/[framebuf]
* https://circuitpython.readthedocs.io/projects/htu31d/en/latest/[htu31d]
* https://circuitpython.readthedocs.io/en/latest/shared-bindings/neopixel_write/index.html[neopixel_write]

== Contributing

Contributions in the form of issues, feedback, and even pull requests are welcome.
Make sure to adhere to the project's link:CODE_OF_CONDUCT.adoc[Code of Conduct].

== Open Source Software

This project is built on the hard work of countless open source contributors.
Several of these projects are enumerated below.

* {Asciidoctor_}
* {CircuitPython}
* {pip-tools}
* {pipkin}
* {pre-commit}
* {Python}

== Code of Conduct

Refer to the project's link:CODE_OF_CONDUCT.adoc[Code of Conduct] for details.

== License

The font bitmap, link:font/font5x8.bin[font/font5x8.bin], is © 2021 ladyada for Adafruit Industries and licensed under the MIT license.

This repository is licensed under the https://www.gnu.org/licenses/gpl-3.0.html[GPLv3], a copy of which is provided link:LICENSE.adoc[here].

© 2021-2024 Jordan Williams

== Authors

mailto:{email}[{author}]