Ejemplo n.º 1
0
 def __init__(self, conf, controller, ow_list):
     SensorDevice.__init__(self, conf, controller)
     print('ds18x20 init')
     self.rom = None
     self._ow = None
     self._ds = None
     _ow = ow_list[conf['ow']]
     if _ow:
         self._ow = Onewire(Pin(ow_list[conf['ow']]))
         ow_roms = self._ow.scan()
         if ow_roms:
             self.rom = ow_roms[0]
             print('ds18x20 rom found ' + str(self.rom))
             self._ds = Onewire.ds18x20(self._ow, 0)
         else:
             print('no ds18x20 rom found')
     else:
         print('invalid onewire settings')
     self._convert = False
Ejemplo n.º 2
0
def main():

    for i, rom in enumerate(ow.scan()):
        if rom[-2:] == '10' or rom[-2:] == '28':
            r2 = rom[-2:] + '-' + rom[:-4]
            roms.append([r2, Onewire.ds18x20(ow, i)])

    while True:
        temp = get_temp_lobo()
        for t in temp:
            print('sensor: ' + t[0] + ' température: ' + t[1])
        print()
        sleep(5)

    for r in roms:
        r[1].deinit()
    ow.deinit()
Ejemplo n.º 3
0
class SensorDeviceDS18x20(SensorDevice):
    "ds18x20 sensor handler"

    def __init__(self, conf, controller, ow_list):
        SensorDevice.__init__(self, conf, controller)
        print('ds18x20 init')
        self.rom = None
        self._ow = None
        self._ds = None
        _ow = ow_list[conf['ow']]
        if _ow:
            self._ow = Onewire(Pin(ow_list[conf['ow']]))
            ow_roms = self._ow.scan()
            if ow_roms:
                self.rom = ow_roms[0]
                print('ds18x20 rom found ' + str(self.rom))
                self._ds = Onewire.ds18x20(self._ow, 0)
            else:
                print('no ds18x20 rom found')
        else:
            print('invalid onewire settings')
        self._convert = False

    def convert(self):
        "requests sensor readings"
        if self.rom:
            try:
                self._ds.convert(False)
                self._convert = True
            except Exception as exc:
                LOG.exc(exc, 'onewire error')

    def read(self):
        "reads sensors data and stores in into controller data field"
        if self._convert:
            try:
                self._controller.data[self._sensors_ids[0]] =\
                    round(self._ds.read_temp(), 1)
            except Exception as exc:
                LOG.exc(exc, 'onewire error')
                self._controller.data[self._sensors_ids[0]] = None
            finally:
                self._convert = False
Ejemplo n.º 4
0
# M5Stack ESP32
# Mesure de température avec le capteur CTN PlugUino
# Ro = 10 kOhm reliée à la masse
# CAN 16 bits I2C AS1115

from machine import I2C, Pin, Onewire
from ads1x15 import ADS1115
from time import sleep_ms
from math import log
from m5stack import lcd, buttonA

i2c = I2C(freq=400000, sda=21, scl=22)
adc = ADS1115(i2c, 0x48, 0)  # Gain value - 0 : 6.144V # 2/3x

ow = Onewire(26)
ds = Onewire.ds18x20(ow, 0)

# Coefficients de Steinhart-Hart
A = 1.0832e-3
B = 2.1723e-4
C = 3.2770e-7

Nmax = 26860  # 5/6.144*32765 = 26664
Ro = 10e3


def mesure_resistance_up():
    return Ro * (Nmax / adc.read() - 1)


while not buttonA.wasPressed():
def ReadTDS(voltage, temp):
    # Temperature compensation to 25 °C reference value
    comp_Coefficente = 1 + 0.02 * (temp - 25)

    # compensated electrical conductivity
    comp_Voltage = voltage / comp_Coefficente

    # convert voltage value to tds value
    tds_value = ((133.42 * comp_Voltage**3) - (255.86 * comp_Voltage**2) +
                 (857.39 * comp_Voltage)) * 0.5

    return tds_value


#####----- DS18X20 LOBORIS-----#####
ds18_pin = Onewire(15)
ds18_sensor = Onewire.ds18x20(ds18_pin, 0)

ds18_temp = ReadDS18(ds18_sensor)

#addrs = ds18_sensor.scan()
#addr = addrs.pop()

#ds_read = ds18_sensor.convert_temp()
#sleep_ms(750)
#ds18_temp = ds18_sensor.read_temp(addr)

print("Temperature: {0:.1f}°C".format(ds18_temp))

#####----- ph -----#####
pH = ADC(34)
Ejemplo n.º 6
0
from machine import Onewire
from time import sleep

ds = []
ow = Onewire(13)  # Initialize onewire & DS18B20 temperature sensor
print(ow)

ds0 = Onewire.ds18x20(ow, 0)
ds1 = Onewire.ds18x20(ow, 1)

print('OW', ow)
print('DS', ds)
print('ow.scan()', ow.scan())


def get_temp_lobo():
    try:
        while True:
            temp0 = ds0.convert_read()
            print("Temperature0: {0:.1f}°C".format(temp0))
            temp1 = ds1.convert_read()
            print("Temperature1: {0:.1f}°C".format(temp1))
            print('\n')
            sleep(4)
    except KeyboardInterrupt:
        print('\nCtrl-C pressed.  Cleaning up and exiting...')
    finally:
        ds0.deinit()
        ds1.deinit()
        ow.deinit()
Ejemplo n.º 7
0
from machine import Onewire
from time import sleep

ow = Onewire(15)  # Initialize onewire & DS18B20 temperature sensor
ds = Onewire.ds18x20(ow, 0)


def get_temp_lobo(ds):
    try:
        while True:
            temp = ds.convert_read()
            print("Temperature: {0:.1f}°C".format(temp))
            sleep(4)
    except KeyboardInterrupt:
        print('\nCtrl-C pressed.  Cleaning up and exiting...')
    finally:
        ds.deinit()
        ow.deinit()


get_temp_lobo(ds)
Ejemplo n.º 8
0
from machine import Onewire
from time import sleep
import ubinascii
import machine

DS18X20_PIN = const(13)
ow = Onewire(DS18X20_PIN)  # Initialize onewire & DS18B20 temperature sensor
roms = []


def get_temp_lobo():

    v_ret = []
    for rom in roms:
        sx = []
        sensor_id = rom[0]
        sensor_temp = '{:.1f}'.format(rom[1].convert_read())
        sx.append(sensor_id)
        sx.append(sensor_temp)
        v_ret.append(sx)
    return v_ret


def main():

    for i, rom in enumerate(ow.scan()):
        if rom[-2:] == '10' or rom[-2:] == '28':
            r2 = rom[-2:] + '-' + rom[:-4]
            roms.append([r2, Onewire.ds18x20(ow, i)])

    while True:
        current_position = 1
        for measurement in sensor.get_measurements():
            if sensor.get_model() is DS18B20:
                tp = self._temp_to_pixel(measurement)
                self.tft.line(current_position, tp,
                              current_position + step_size, tp,
                              sensor.get_color())
                current_position += step_size
            else:
                # Not implemented yet:
                pass


# dht = DHT(Pin(25), DHT.DHT2X)
ow = Onewire(33)

sensors = [
    DS18B20Sensor(name="Luft", sensor=Onewire.ds18x20(ow, 0), color=TFT.RED),
    DS18B20Sensor(name="Bakke", sensor=Onewire.ds18x20(ow, 1),
                  color=TFT.GREEN),
    DS18B20Sensor(name="Inne", sensor=Onewire.ds18x20(ow, 2), color=TFT.BLUE)
]

vis = Visualization(min_temp=-20, max_temp=40, sensors=sensors)


def cb(pin):
    vis.next_render_mode()
    print("Changing rendering mode to: {}".format(vis.render_mode), pin)