Skip to main content

DogRatIan USB-TnH, USB-PA and USB-VOC python lib

This library makes usage of https://www.dogratian.com sensors easy

License Percentage of issues still open linux-tests windows-tests GitHub Release

Setup: pip install dogratian_usb_sensors

Quick Usage:

from dogratian_usb_sensors import USBSensor

# Returns serial port names for every connected DogRatIan device
sensor_ports = USBSensor.find_sensors()

# Read data for every sensor on system
for sensor_port in sensor_ports:
    sensor = USBSensor(sensor_port)
    print(sensor.model)
    print(sensor.version)
    print(sensor.temperature)       # Only on USB-PA and USB-TnH sensors
    print(sensor.humidity)          # Only on USB-PA and USB-TnH sensors
    print(sensor.name)
    print(sensor.pressure)          # Only on USB-PA sensor
    print(sensor.voc)               # Only on USB-VOC sensor
    print(sensor.co2eq)             # Only on USB-VOC sensor
    print(sensor.identification)

Reading all possible measurement values from a sensor

for sensor_port in USBSensor.find_sensors():
    sensor = USBSensor(sensor_port)
    print(sensor.all)

Sensor differences

DogRatIan uses USB-TnH (temperature and humidity), USB-PA (temperature, humidity and atmospheric pressure) as well as USB-VOC (volatile organic compounds) sensors. All three sensors are returned by USBSensor.find_sensors().

Depending on the sensor you have, not all commands will run. You can identify a sensor by using sensor.model property.

Basic usage

from time import sleep
from dogratian_usb_sensors import USBSensor

sensor_ports = USBSensor.find_sensors()

for sensor_port in sensor_ports:
    print("Found sensor at port {}".format(sensor_port))
    sensor = USBSensor(sensor_port, state_led=True)
    print("Sensor model is {}".format(sensor.model))

    count = 0
    while count < 10:
        print("Current temperature: {}".format(sensor.temperature))
        print("Current humidity: {}".format(sensor.humidity))
        sleep(.1)
        count += 1

Writing data to the sensor

As DogRatIan suggests, you can set Name sensor to a max 8 char string, and turn on/off led. The light will always flash when data is read on the sensor, regarless if it has been turned off. USBSensor class has write methods implemented as setter properties, eg:

from dogratian_usb_sensors import USBSensor

sensor = USBSensor('/dev/ttyUSB2')
sensor.name = 'MYSENSOR'
sensor.led = True
# Some code
sensor.led = False

State led

By default, DogRatIan sensors will turn on their standby light when plugged in. USBSensor will disable the standby light by default, unless initialized with Optionally, we can automatically enable the led indicator while reading with state_led=True.

from dogratian_usb_sensors import USBSensor

sensor = USBSensor('COM4', state_led=True)
print(sensor.name)  # Light flashes while reading value

Error handling

USBSensor class will raise two types of exceptions:

  • ValueError when invalid opcode is given to sensor
  • OSError when serial communication fails (most time you need to be root/administrator to have permissions over serial ports, and ports must not already been open by another application)

Metadata

Release files for dogratian-usb-sensors 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dogratian-usb-sensors 1.1
File Size Uploaded
dogratian_usb_sensors-1.1.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dogratian-usb-sensors 1.1
File Interpreter ABI Platform
dogratian_usb_sensors-1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / dogratian_usb_sensors-1.1.tar.gz

Download URL dogratian_usb_sensors-1.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
61526e9dc79b6d1d28d72e1ade9af965e311c5a33587c7bc73182bbdc3e2a82c
BLAKE2b-256 checksum
How to use checksums
7a04c6f5d79d81c405d01ea94bcf4c879eb517e86171fd09874c3f6794b36c78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Release files / dogratian_usb_sensors-1.1-py3-none-any.whl

Download URL dogratian_usb_sensors-1.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7bb0aee34ce13689c43bad43d5ea501925fac69fccdfc46910c04e5e014901b
BLAKE2b-256 checksum
How to use checksums
517cfae1e1c1fa7cb9337c1458dbb5c53024881b46330e2fb50da9060b10934e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page