Pythonic library for Dogratian USB sensors
Project description
DogRatIan USB-TnH, USB-PA and USB-VOC python lib
This library makes usage of https://www.dogratian.com sensors easy
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dogratian_usb_sensors-1.1.tar.gz
.
File metadata
- Download URL: dogratian_usb_sensors-1.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61526e9dc79b6d1d28d72e1ade9af965e311c5a33587c7bc73182bbdc3e2a82c |
|
MD5 | be3a298861e396cd6f91bd38faed2302 |
|
BLAKE2b-256 | 7a04c6f5d79d81c405d01ea94bcf4c879eb517e86171fd09874c3f6794b36c78 |
File details
Details for the file dogratian_usb_sensors-1.1-py3-none-any.whl
.
File metadata
- Download URL: dogratian_usb_sensors-1.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7bb0aee34ce13689c43bad43d5ea501925fac69fccdfc46910c04e5e014901b |
|
MD5 | c6901757dc903167143cd59fa8240ab5 |
|
BLAKE2b-256 | 517cfae1e1c1fa7cb9337c1458dbb5c53024881b46330e2fb50da9060b10934e |