pyupm_ds18b20 module¶
-
class
pyupm_ds18b20.
DS18B20
(uart=0)[source]¶ Bases:
object
API for the DS18B20 1-Wire Temperature Sensor.
ID: ds18b20
Name: Programmable Resolution 1-Wire Digital Thermometer
Category: uart
Manufacturer: maxim
Connection: uart
Link:https://www.sparkfun.com/products/11050 This driver supports, and was tested with, a DS18B20 with external power.
Multiple DS18B20 devices can be connected to this bus. This module will identify all such devices connected, and allow you to access them using an index starting at 0.
Parasitic power is not currently supported due to the very tight 10us limit on switching a GPIO properly to supply power during certain operations. For this reason, you should use external power for your sensors.
Setting the alarm values (Tl, Th) is also not supported, since this is only useful when doing a 1-wire device search looking for devices in an alarm state, a capability not yet supported in MRAA. In reality, this is trivial to handle yourself in your application.
This device requires the use of a TTL level UART (specifically through the UartOW MRAA context class) to provide access to a Dallas 1-wire bus. It is important to realize that the UART is only being used to provide an interface to devices on a Dallas 1-wire compliant bus.
A circuit like the following should be used for the UART interface (ASCII schematic - best viewed in a fixed monospace font):
-| U| (D1) A| TX|<+ R| | T| RX—-o—–o >to 1-wire data bus -|
Vcc | o————+ | | R1 | | o(+) >1-wire—o—–o[ DS18B20] o(-) | GND
D1 = 1N4148 R1 = 4.7K
The cathode of D1 is connected to the UART TX.
C++ includes: ds18b20.hpp
-
copyScratchPad
(index)[source]¶ void copyScratchPad(unsigned int index)
Copy the device’s scratchpad memory to the EEPROM. This includes the configuration byte (resolution).
index: The device index to access (starts at 0).
-
devicesFound
()[source]¶ int devicesFound()
This method will return the number of DS18B20 devices that were found on the bus by init().
number of DS18B20’s that were found on the bus
-
getId
(index)[source]¶ string getId(unsigned int index)
Return an 8 byte string representing the unique device ID (1-wire romcode) for a given device index.
index: The device index to access (starts at 0).
8 byte string representing the 1-wire device’s unique romcode.
-
getTemperature
(index, fahrenheit=False)[source]¶ float getTemperature(unsigned int index, bool fahrenheit=false)
Get the current temperature. update() must have been called prior to calling this method.
index: The device index to access (starts at 0).
fahrenheit: true to return the temperature in degrees fahrenheit, false to return the temperature in degrees celsius. The default is false (degrees Celsius).
The last temperature reading in Celsius or Fahrenheit
-
init
()[source]¶ void init()
Deprecated This method is deprecated. It’s functionality is handled in the constructor now.
-
recallEEPROM
(index)[source]¶ void recallEEPROM(unsigned int index)
Copy the device’s EEPROM memory to the scratchpad. This method will return when the copy completes. This operation is performed by the device automatically on power up, so it is rarely needed.
index: The device index to access (starts at 0).
-
setResolution
(index, res)[source]¶ void setResolution(unsigned int index, DS18B20_RESOLUTIONS_T res)
Set the device resolution for a device. These devices support 9, 10, 11, and 12 bits of resolution, with the default from the factory at 12 bits.
index: The device index to access (starts at 0).
res: One of the RESOLUTIONS_T values
-