Server Incomiiiing
This commit is contained in:
35
PlantBox.Server/sensors_pi/temperature_pi.py
Normal file
35
PlantBox.Server/sensors_pi/temperature_pi.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#! python3.5
|
||||
from grove.factory import Factory
|
||||
from grove.temperature import Temper
|
||||
from upm.pyupm_mcp9808 import MCP9808
|
||||
import time
|
||||
|
||||
class TemperatureSensorPI:
|
||||
"""
|
||||
Represents a temperature sensor created with an I2C address
|
||||
In this projet, it is supposed to be exactly 2 TemperatureSensorPI for 1 PlantPI
|
||||
The precision of this sensor is about ± 0.0625
|
||||
|
||||
:param address: A string representing the address in hexadecimal, it'll be converted into int
|
||||
:type address: str
|
||||
"""
|
||||
def __init__(self,address):
|
||||
self.address = address
|
||||
self.Processor = MCP9808(0,int(address,16))
|
||||
self.Processor.setMode(True)
|
||||
self.Processor._resolution = Temper.RES_1_16_CELSIUS
|
||||
|
||||
def ReadTemperatureCelsius(self):
|
||||
self.Processor.getTemp()
|
||||
|
||||
|
||||
def main():
|
||||
sensor1 = TemperatureSensorPI(18) # The hexadecimal 18 address
|
||||
sensor2 = TemperatureSensorPI(19) # The hexadecimal 19 address
|
||||
while True:
|
||||
print("[Temperature 1] {} Celsius".format(sensor1.ReadTemperatureCelsius()))
|
||||
print("[Temperature 2] {} Celsius".format(sensor2.ReadTemperatureCelsius()))
|
||||
time.sleep(1)
|
||||
|
||||
if __name__== "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user