Beispiel #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
from adafruit_onewire.bus import OneWireBus

# Create the 1-Wire Bus
# Use whatever pin you've connected to on your board
ow_bus = OneWireBus(board.D2)

# Reset and check for presence pulse.
# This is basically - "is there anything out there?"
print("Resetting bus...", end="")
if ow_bus.reset():
    print("OK.")
else:
    raise RuntimeError("Nothing found on bus.")

# Run a scan to get all of the device ROM values
print("Scanning for devices...", end="")
devices = ow_bus.scan()
print("OK.")
print("Found {} device(s).".format(len(devices)))

# For each device found, print out some info
for i, d in enumerate(devices):
    print("Device {:>3}".format(i))
    print("\tSerial Number = ", end="")
    for byte in d.serial_number:
        print("0x{:02x} ".format(byte), end="")
    print("\n\tFamily = 0x{:02x}".format(d.family_code))

# Usage beyond this is device specific. See a CircuitPython library for a 1-Wire
# device for examples and how OneWireDevice is used.
Beispiel #3
0
import time
import board
from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

# Initialize one-wire bus on board D5.
ow_bus = OneWireBus(board.GP2)
# Scan for sensors and grab them all
ds18 = [DS18X20(ow_bus, found) for found in ow_bus.scan()]
# 12-bit resolution (default)
ds18.resolution = 10

# read (request) the temperature every 5 seconds
TEMPERATURE_DELAY = 5

# time when the next read should occur.
ds18_next = time.monotonic()
# should we start the async read or do the actual read ?
ds18_do_read = False
# delay for async read (default, real value will be set later)
ds18_async_delay = 1

# Main loop to print the temperature every 5 second.
while True:
    now = time.monotonic()

    # Is it time to read ?
    if now > ds18_next:
        # if we did request the temperature, now do the read
        if ds18_do_read:
            # fetch the temperatures from the sensor
Beispiel #4
0
import board
import busio
import digitalio
import time
from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

# Initialize one-wire bus on board pin D5.
ow_bus = OneWireBus(board.D5)

ds18_bus = ow_bus.scan()
print(ds18_bus)

ds18 = []
for probe in ds18_bus:
    print(probe)
    ds18.append(DS18X20(ow_bus, probe))

print(ds18)
Beispiel #5
0
# SPDX-License-Identifier: MIT

# This example shows how to access the DS2413 pins and use them for both input
# and output. In this example, it is assumed an LED is attached to IOA and a
# button is attached to IOB. See the datasheet for details about how to
# interface the external hardware (it is different than most Arduino examples).
import time
import board
from adafruit_onewire.bus import OneWireBus
import adafruit_ds2413

# Create OneWire bus
ow_bus = OneWireBus(board.D2)

# Create the DS2413 object from the first one found on the bus
ds = adafruit_ds2413.DS2413(ow_bus, ow_bus.scan()[0])

# LED on IOA
led = ds.IOA

# button on IOB
button = ds.IOB
button.direction = adafruit_ds2413.INPUT

# Loop forever
while True:
    # Check for button press
    if button.value:
        # Print a message.
        print("Button pressed!")
        # Toggle LED
Beispiel #6
0
# This example shows how to access the DS2413 pins and use them for both input
# and output. In this example, it is assumed an LED is attached to IOA and a
# button is attached to IOB. See the datasheet for details about how to
# interface the external hardware (it is different than most Arduino examples).
import time
import board
from adafruit_onewire.bus import OneWireBus
import adafruit_ds2413

# Create OneWire bus
ow_bus = OneWireBus(board.D2)

# Create the DS2413 object from the first one found on the bus
ds = adafruit_ds2413.DS2413(ow_bus, ow_bus.scan()[0])

# LED on IOA
led = ds.IOA

# button on IOB
button = ds.IOB
button.direction = adafruit_ds2413.INPUT

# Loop forever
while True:
    # Check for button press
    if button.value:
        # Print a message.
        print("Button pressed!")
        # Toggle LED
        led.value = not led.value
        # A little debounce
# Simple demo of printing the temperature from the first found DS18x20 sensor every second.
# Author: Tony DiCola

# A 4.7Kohm pullup between DATA and POWER is REQUIRED!

import time
import board
from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

# Initialize one-wire bus on board pin D5.
ow_bus = OneWireBus(board.D5)

# Scan for sensors and grab the first one found.
ds18 = DS18X20(ow_bus, ow_bus.scan()[0])

# Main loop to print the temperature every second.
while True:
    print("Temperature: {0:0.3f}C".format(ds18.temperature))
    time.sleep(1.0)
Beispiel #8
0
# Simple demo of printing the temperature from the first found DS18x20 sensor every second.
# Author: Tony DiCola
import time

import board

from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20


# Initialize one-wire bus on board pin D5.
ow_bus = OneWireBus(board.D5)

# Scan for sensors and grab the first one found.
ds18 = DS18X20(ow_bus, ow_bus.scan()[0])

# Main loop to print the temperature every second.
while True:
    print('Temperature: {0:0.3f}C'.format(ds18.temperature))
    time.sleep(1.0)
import board
import busio
import digitalio
import time
from adafruit_onewire.bus import OneWireBus

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.RFM9X_CS)
reset = digitalio.DigitalInOut(board.RFM9X_RST)
import adafruit_rfm9x
rfm9x = adafruit_rfm9x.RFM9x(spi, cs, reset, 868.0)

ow_bus=OneWireBus(board.D5)
devices=ow_bus.scan()
import adafruit_ds18x20
ds18b20 = adafruit_ds18x20.DS18X20(ow_bus, devices[0])

while True:
    temp=ds18b20.temperature
    rfm9x.send(str(temp))
    time.sleep(5)
Beispiel #10
0
import board
import time
from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20
import digitalio

bus = OneWireBus(board.D5)
sensor = DS18X20(bus, bus.scan()[0])

rele = digitalio.DigitalInOut(board.D6)
rele.direction = digitalio.Direction.OUTPUT

while True:
    t = sensor.temperature
    print('Temperatura: {0:0.3f} °C'.format(t))

    if t < 60:
        rele.value = False
    else:
        rele.value = True

    time.sleep(1.0)
Beispiel #11
0
#构建I2C对象
i2c = busio.I2C(board.SCK, board.MOSI)

#构建oled对象,01Studio配套的OLED地址为0x3C
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)

#清屏
display.fill(0)
display.show()

# 初始化单总线对象,引脚为D5.
ow = OneWireBus(board.D5)

# 搜索传感器,返回第1个
ds = DS18X20(ow, ow.scan()[0])

while True:

    temp = round(ds.temperature, 2)  #保留2位小数

    display.fill(0)  #清屏
    display.text('01Studio', 0, 0, 1, font_name='font5x8.bin')
    display.text('Temp Test', 0, 20, 1, font_name='font5x8.bin')
    display.text(str(temp) + ' C', 0, 40, 1, font_name='font5x8.bin')
    display.show()

    print(str(temp) + ' C')

    time.sleep(1)
Beispiel #12
0
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

try:
    from data import data
except ImportError:
    print("Metadata is kept in Data.py, please add it there!")
    raise

location = data['location']
latitude = data['latitude']
longitude = data['longitude']
# Initialize one-wire bus on board pin D5.
ow_bus = OneWireBus(board.A3)
oneWire = ow_bus.scan()

# Scan for sensors and grab the first one found.
sensors = []

#Fill sensors array with oneWire objects
for i, d in enumerate(oneWire):
    serial = ""
    for byte in d.serial_number:
        #print("{:02x}".format(byte), end='')
        serial = serial + "{:02x}".format(byte)
    sensor = {"Serial Number": serial, "ow": DS18X20(ow_bus, ow_bus.scan()[i])}
    sensors.append(sensor)
    t = '{0:0.3f}'.format(DS18X20(ow_bus, ow_bus.scan()[i]).temperature)
    ds18 = DS18X20(ow_bus, ow_bus.scan()[i])
    ds18.resolution = 12