Python interface to Loadstar Sensors USB devices.
Project description
About
- Python Package Name: loadstar_sensors_interface
- Description: Python interface to Loadstar Sensors USB devices.
- Version: 0.10.0
- Release Date: 2023-01-21
- Creation Date: 2022-08-16
- License: BSD-3-Clause
- URL: https://github.com/janelia-pypi/loadstar_sensors_interface_python
- Author: Peter Polidoro
- Email: peter@polidoro.io
- Copyright: 2023 Howard Hughes Medical Institute
- References:
- https://pyserial-asyncio.readthedocs.io/en/latest/
- https://tinkering.xyz/async-serial/
- https://www.loadstarsensors.com/
- https://www.loadstarsensors.com/di-100u-di-1000u-command-set.html
- Dependencies:
- pyserial-asyncio
- click
Example Usage
Python
from loadstar_sensors_interface import LoadstarSensorsInterface
dev = LoadstarSensorsInterface() # Try to automatically detect port
dev = LoadstarSensorsInterface(port='/dev/ttyUSB0') # GNU/Linux specific port
dev = LoadstarSensorsInterface(port='/dev/tty.usbmodem262471') # Mac OS X specific port
dev = LoadstarSensorsInterface(port='COM3') # Windows specific port
device_info = dev.get_device_info()
dev.tare()
sensor_value = dev.get_sensor_value()
sensor_values = dev.get_sensor_values_for_duration(4)
dev.set_averaging_window_in_samples(5) # 1-1024 samples
averaging_window = dev.get_averaging_window_in_samples()
dev.set_averaging_threshold_in_percent(25) # 1-100 percent
averaging_threshold = dev.get_averaging_threshold_in_percent()
Command Line
loadstar --help
# Usage: loadstar [OPTIONS]
loadstar --info
loadstar -p /dev/ttyUSB0 --tare -s LB_TO_GM -w 1 -t 25 -f 2 -d 10
Installation
https://github.com/janelia-pypi/python_setup
GNU/Linux
Drivers
GNU/Linux computers usually have all of the necessary drivers already installed, but users need the appropriate permissions to open the device and communicate with it.
Udev is the GNU/Linux subsystem that detects when things are plugged into your computer.
Udev may be used to detect when a loadstar sensor is plugged into the computer and automatically give permission to open that device.
If you plug a sensor into your computer and attempt to open it and get an error such as: "FATAL: cannot open /dev/ttyUSB0: Permission denied", then you need to install udev rules to give permission to open that device.
Udev rules may be downloaded as a file and placed in the appropriate directory using these instructions:
-
Download rules into the correct directory
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
-
Restart udev management tool
sudo service udev restart
-
Ubuntu/Debian users may need to add own “username” to the “dialout” group
sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER
-
After setting up rules and groups
You will need to log out and log back in again (or reboot) for the user group changes to take effect.
After this file is installed, physically unplug and reconnect your board.
Python Code
The Python code in this library may be installed in any number of ways, chose one.
-
pip
python3 -m venv ~/venvs/loadstar_sensors_interface source ~/venvs/loadstar_sensors_interface/bin/activate pip install loadstar_sensors_interface
-
guix
Setup guix-janelia channel:
https://github.com/guix-janelia/guix-janelia
guix install python-loadstar-sensors-interface
Windows
Drivers
Download and install Windows driver:
Loadstar Sensors Windows Driver
Python Code
The Python code in this library may be installed in any number of ways, chose one.
-
pip
python3 -m venv C:\venvs\loadstar_sensors_interface C:\venvs\loadstar_sensors_interface\Scripts\activate pip install loadstar_sensors_interface
Development
Install Guix
Clone Repository
git clone https://github.com/janelia-pypi/loadstar_sensors_interface_python
cd loadstar_sensors_interface_python
Make alias
source .metadata/.alias
Edit metadata.org
,make metadata-edits
Tangle metadata.org
,make metadata
Test Python package using ipython shell
,make ipython-shell # PORT=/dev/ttyUSB0
# ,make PORT=/dev/ttyUSB1 ipython-shell
import loadstar_sensors_interface
exit
Test installation of Guix package
,make installed-shell # PORT=/dev/ttyUSB0
# ,make PORT=/dev/ttyUSB1 installed-shell
exit
Upload Python package to pypi
,make upload
Test direct device interaction using serial terminal
Low Speed
DI-100, DI-1000
,make serial-shell # PORT=/dev/ttyUSB0
# ,make PORT=/dev/ttyUSB1 serial-shell
? # help
settings
[C-a][C-x] # to exit
High Speed
DI-1000UHS
,make serial-shell-hs # PORT=/dev/ttyUSB0
# ,make PORT=/dev/ttyUSB1 serial-shell-hs
? # help
settings
[C-a][C-x] # to exit
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
Hashes for loadstar_sensors_interface-0.10.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e411c80fed7ae12b87f5928dec3ccde4047c5ece9b01ce4d97a755478bfb319 |
|
MD5 | 5bd71a0a1d0b420b5002c8c92ed26c4d |
|
BLAKE2b-256 | 37037e60c14ae8c67a20b45e7f6dcd64bdf991a91b83f2bf4f8f4ffe048bf789 |
Hashes for loadstar_sensors_interface-0.10.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bb8149b6bc6c9f8d6b3f3e785f6fcf140893ae81a4c286b2fbbc8b8ca420ad8 |
|
MD5 | d1ec7d06a881623113ac6814a3ef2657 |
|
BLAKE2b-256 | 5375c6efea7307278867d26bbb7e302323d0fe44fdbfb88794dc0f49ffa1d98c |