DEGREES_F ) temperature_in_all_units = await sensor. get_temperature () temperature_in_fahrenheit = await sensor. The w1thermsensor package implements an async interface AsyncW1ThermSensor for asyncio.įor example: from w1thermsensor import AsyncW1ThermSensor, Unit sensor = AsyncW1ThermSensor () temperature_in_celsius = await sensor. Note: the examples above also apply for the CLI tool usage. export W1THERMSENSOR_NO_KERNEL_MODULE = 1 # set it just for your Python process W1THERMSENSOR_NO_KERNEL_MODULE = 1 python my_awesome_thermsensor_script.pyĮvery other values assigned to W1THERMSENSOR_NO_KERNEL_MODULE will case w1thermsensor to load the kernel modules. You can disable the auto loading feature by setting the W1THERMSENSOR_NO_KERNEL_MODULE environment variable to 1: # set it globally for your shell so that sub-processes will inherit it. Sometimes that's not what you want, thus you can disable the auto loadingĪnd load the kernel module yourself prior to talk to your sensors with w1thermsensor. This requires the python process to run as root. Upon import of the w1thermsensor package the w1-therm and w1-gpio kernel modules get loaded automatically. Note: this requires root privileges Disable kernel module auto loading Note: this is supported since Linux Kernel 4.7 Since the EEPROM has a limitedĪmount of writes (>50k), this command should be used wisely. If the persist argument is set to True the current set Is "only" stored in the volatile SRAM, so it is reset when If the persist argument is set to False this value W1thermsensor enables to do so with the t_resolution() method: sensor = W1ThermSensor ( Sensor. Some w1 therm sensors support changing the resolution for the temperature reads. get_temperature ())) Set sensor resolution get_available_sensors (): print ( "Sensor %s has temperature %.2f " % ( sensor. Only sensors of a specific therm sensor type: from w1thermsensor import W1ThermSensor, Sensor for sensor in W1ThermSensor. from w1thermsensor import W1ThermSensor for sensor in W1ThermSensor. With the get_available_sensors class-method you can get the ids of all available sensors. from w1thermsensor import W1ThermSensor, Sensor sensor = W1ThermSensor ( Sensor. The DS18B20 sensor with the ID 00000588806a will be taken. The first found sensor will be taken Basic usage with one sensor (explicit) If something went wrong an exception is raised. The need kernel modules will be automatically loaded in the constructor of the W1ThermSensor class. DEGREES_F ) temperature_in_all_units = sensor. get_temperature () temperature_in_fahrenheit = sensor. Basic usage with one sensor (implicit) from w1thermsensor import W1ThermSensor, Unit sensor = W1ThermSensor () temperature_in_celsius = sensor. The usage is very simple and the interface clean.Īll examples are with the DS18B20 sensor - It works the same way for the other supported devices. Manually build and install the debian package debuild -us -uc Note: For older versions of this package you might get the following error: ImportError: No module named 'pkg_resources' which indicates that you need to install python-setuptools or python3-setuptools respectively. If you are using the w1thermsensor module on a Rasperry Pi running Raspbian you can install it from the official repository: sudo apt-get install python3-w1thermsensor Use the async extra to add support for asyncio and AsyncW1ThermSensor: pip install w1thermsensor This possibility is supported on all distributions: pip install w1thermsensor Hardware-connection Raspi VCC (3V3) Pin 1 - VCC DS18B20 The default data pin is GPIO4 (RaspPi connector pin 7), but that can be changed from 4 to x with dtoverlay=w1-gpio,gpiopin=x.Īfter that, don't forget to reboot. On the Raspberry Pi, you will need to add dtoverlay=w1-gpio" (for regular connection) or dtoverlay=w1-gpio,pullup="y" (for parasitic connection) to your /boot/config.txt.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |