Server Incomiiiing
This commit is contained in:
4
PlantBox.Server/Requirements.txt
Normal file
4
PlantBox.Server/Requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Temperature Sensors -> I2C Port (Address 0x18 and 0x19)
|
||||
Moisture Sensor -> Analog0 Port
|
||||
Luminance Sensors -> Analog2 and Analog4 Ports
|
||||
Led Button -> Digital 0 Port
|
||||
7
PlantBox.Server/common.py
Normal file
7
PlantBox.Server/common.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from sensors_pi import temperature_pi, luminance_pi, moisture_pi
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
86
PlantBox.Server/sensors_pi/luminance_pi.py
Normal file
86
PlantBox.Server/sensors_pi/luminance_pi.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from grove.adc import ADC
|
||||
from time import sleep as delay
|
||||
VoutArray = [ 0.0011498, 0.0033908, 0.011498, 0.041803,0.15199, 0.53367, 1.3689, 1.9068, 2.3]
|
||||
LuxArray = [ 1.0108, 3.1201, 9.8051, 27.43, 69.545, 232.67, 645.11, 73.52, 1000]
|
||||
|
||||
|
||||
|
||||
class LuminanceSensorPI:
|
||||
"""
|
||||
Represents a luminance sensor created with an analog channel
|
||||
In this projet, it is supposed to be exactly 2 LuminanceSensorPI for 1 PlantPI
|
||||
"""
|
||||
def __init__(self,channel):
|
||||
self.channel = channel
|
||||
|
||||
def _readVout(self):
|
||||
vout = ADC().read(self.channel) * (3.0 / 1023.0)
|
||||
# Above 2.3V , the sensor value is saturated
|
||||
return vout
|
||||
|
||||
def readLuminance(self):
|
||||
# MeasuredVout = ADC Value * (Vcc / 1023) * (3 / Vcc)
|
||||
# Vout samples are with reference to 3V Vcc
|
||||
# The above expression is simplified by cancelling out Vcc
|
||||
measuredVout = self._readVout()
|
||||
luminance = self.FmultiMap(measuredVout, VoutArray, LuxArray, 9)
|
||||
|
||||
"""
|
||||
|
||||
The Luminance in Lux is calculated based on APDS9002 datasheet -- > Graph 1
|
||||
( Output voltage vs. luminance at different load resistor)
|
||||
The load resistor is 1k in this board. Vout is referenced to 3V Vcc.
|
||||
|
||||
The data from the graph is extracted using WebPlotDigitizer
|
||||
http://arohatgi.info/WebPlotDigitizer/app/
|
||||
|
||||
VoutArray[] and LuxArray[] are these extracted data. Using MultiMap, the data
|
||||
is interpolated to get the Luminance in Lux.
|
||||
|
||||
This implementation uses floating point arithmetic and hence will consume
|
||||
more flash, RAM and time.
|
||||
|
||||
The Luminance in Lux is an approximation and depends on the accuracy of
|
||||
Graph 1 used.
|
||||
|
||||
"""
|
||||
return luminance
|
||||
|
||||
|
||||
|
||||
# This code uses MultiMap implementation from http://playground.arduino.cc/Main/MultiMap
|
||||
|
||||
def FmultiMap(self,val, _in, _out, size):
|
||||
"""
|
||||
The method wich convert the Tension VOut to an accurate corresponding value in Lux
|
||||
"""
|
||||
|
||||
# take care the value is within range
|
||||
# val = constrain(val, _in[0], _in[size-1])
|
||||
if val <= _in[0]:
|
||||
return _out[0]
|
||||
if val >= _in[size-1]:
|
||||
return _out[size-1]
|
||||
|
||||
# search right interval
|
||||
pos = 1 # _in[0] allready tested
|
||||
while val > _in[pos]:
|
||||
pos += 1
|
||||
|
||||
# this will handle all exact "points" in the _in array
|
||||
if val == _in[pos]:
|
||||
return _out[pos]
|
||||
|
||||
#interpolate in the right segment for the rest
|
||||
return (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1]
|
||||
|
||||
|
||||
def main():
|
||||
sensor1 = LuminanceSensorPI(2)
|
||||
while True:
|
||||
print("[Tension capteur] {}".format(sensor1._readVout()))
|
||||
print("[Lux] {}".format(sensor1.readLuminance()))
|
||||
delay(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
24
PlantBox.Server/sensors_pi/moisture_pi.py
Normal file
24
PlantBox.Server/sensors_pi/moisture_pi.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from time import sleep as delay
|
||||
from grove.adc import ADC
|
||||
|
||||
class MoistureSensorPI:
|
||||
def __init__(self,channel):
|
||||
self.channel = channel
|
||||
|
||||
def ReadMoisture1024(self):
|
||||
value = ADC().read(self.channel)
|
||||
return value
|
||||
|
||||
def ReadMoisture100(self):
|
||||
value = self.ReadMoisture1024()*(100/1023)
|
||||
return value
|
||||
|
||||
def main():
|
||||
sensor = MoistureSensorPI(0)
|
||||
while True:
|
||||
print("[Moisture1024] {} / 1024".format(sensor.ReadMoisture1024()))
|
||||
print("[Moisture100] {} %".format(sensor.ReadMoisture100()))
|
||||
delay(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
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