Exemplo n.º 1
0
def getDevice():
    # This function is used to query the OneWireBus (OWB) to grab a list
    # of devices. This function expects that the sensor is wired up to
    # Digital pin 2. If you used a different pin, change the following
    # line of code:
    owb = OneWireBus(board.D2)

    devices = owb.scan()
    for device in devices:

        idString = "ROM = {} \tFamily = 0x{:02x}".format(
            [hex(i) for i in device.rom], device.family_code)
        #
        # This is the particular sensor identification string returned by the DS18B20 that I am using.
        # You might have to modify this string if it doesn't work for you. You can log output to Mu serial console
        # to see the idStrings for all your OneWire devices.
        # e.g.
        # print idString
        if idString == "ROM = ['0x28', '0xaa', '0x81', '0x2', '0x38', '0x14', '0x1', '0xfe'] 	Family = 0x28":
            ds18b20 = adafruit_ds18x20.DS18X20(owb, device)
            #
            # There are several resolution settings (e.g. how many significant digits of temperature are sent)
            # The settings are 9,10,11,12. Just FYI, the larger the resolution, the longer the time to generate
            # the data (we're talking 100-700ms) but for our purposes I would rather have ALL THE SIGNIFICANT DIGITS!
            # See here for more info: https://www.maximintegrated.com/en/app-notes/index.mvp/id/4377 or https://cdn-shop.adafruit.com/datasheets/DS18B20.pdf
            # So, 12 it is. :-)
            ds18b20.resolution = 12
            return ds18b20
    return None
Exemplo n.º 2
0
def measure_temps(sensor_list=None):
    names = sensors.keys() if sensor_list is None else sensor_list
    readings = OrderedDict()
    pixel[0] = READING
    for s_name in names:
        readings[s_name] = sensors[s_name]()
    pixel[0] = BLACK
    return readings


i2c = board.I2C()
ow_bus = OneWireBus(DS18X20_PIN)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
sht31d = adafruit_sht31d.SHT31D(i2c)
ds18b20 = adafruit_ds18x20.DS18X20(ow_bus, find_DS18X20(ow_bus,
                                                        verbose=VERBOSE))
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)

ntc_ain = AnalogIn(NTC_PIN)
tmp36_ain = AnalogIn(TMP36_PIN)
lm35_ain = AnalogIn(LM35_PIN)

vref = ntc_ain.reference_voltage

### Review PAD_TO_LEN if extending this dict
sensors = OrderedDict([("bmp280", lambda: bmp280.temperature),
                       ("sht31d", lambda: sht31d.temperature),
                       ("cpu", lambda: microcontroller.cpu.temperature),
                       ("ds18b20", lambda: ds18b20.temperature),
                       ("tmp36",
                        lambda: get_voltage(tmp36_ain) * 100.0 - 50.0),
Exemplo n.º 3
0
import busio
import digitalio
from digitalio import DigitalInOut
import time
import gc
import adafruit_bme280
from adafruit_onewire.bus import OneWireBus
ow_bus = OneWireBus(board.A5)

devices = ow_bus.scan()
for device in devices:
    print("ROM = {} \tFamily = 0x{:02x}".format([hex(i) for i in device.rom],
                                                device.family_code))

import adafruit_ds18x20
ds18b20 = adafruit_ds18x20.DS18X20(ow_bus, devices[0])

# Get Wifi and FarmOS details
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

WIFI_ESSID = secrets['ssid']
WIFI_PASS = secrets['password']
farmos_pubkey = secrets['farmos_pubkey']
farmos_privkey = secrets['farmos_privkey']

base_url = "https://edgecollective.farmos.net/farm/sensor/listener/"