# Simple demo of printing the temperature from the first found DS18x20 sensor every second.
# Using the asynchronous functions start_temperature_read() and
# read_temperature() to allow the main loop to keep processing while
# the conversion is in progress.
# Author: Louis Bertrand, based on original by Tony DiCola

import time

import board

from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

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

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

# Main loop to print the temperature every second.
while True:
    conversion_delay = ds18.start_temperature_read()
    conversion_ready_at = time.monotonic() + conversion_delay
    print("waiting", end="")
    while time.monotonic() < conversion_ready_at:
        print(".", end="")
        time.sleep(0.1)
    print('\nTemperature: {0:0.3f}C\n'.format(ds18.read_temperature()))
    time.sleep(1.0)
Exemplo n.º 2
0
# get parameters here
temp = bme280.temperature
humidity = bme280.humidity
pressure = bme280.pressure
probe1=-99.
probe2=-99.

try:
    # Scan for sensors and grab the first one found.
    ds18_bus=ow_bus.scan()
    print(ds18_bus)
    ds18=[]
    for probe in ds18_bus:
        print(probe)
        ds18.append(DS18X20(ow_bus, probe))
    time.sleep(1)
    probe1=ds18[0].temperature
    probe2=ds18[0].temperature

    #probe2=float(ds18[1].temperature)
except Exception as e:
    print("error: "+str(e))

# battery voltage
batt_voltage = 2*float(get_voltage(batt_pin))



trialcount= 0
got_fix = False
import time
import board
import simpleio
import neopixel

from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

heartbeat = simpleio.DigitalOut(board.D13)
heartbeat.value = True

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

# Scan for sensors and grab the first one found.
ds18_0 = DS18X20(ow_bus, ow_bus.scan()[0])
ds18_1 = DS18X20(ow_bus, ow_bus.scan()[1])
# devices = ow_bus.scan()
# for device in devices:
#     print("ROM = {} \tFamily = 0x{:02x}".format([hex(i) for i in device.rom], device.family_code))

# SetUp NeoPixels
tempLEDPin = board.A1
numLED = 16
ORDER = neopixel.GRB
tempLED = neopixel.NeoPixel(tempLEDPin, numLED, brightness=0.2, auto_write=False, pixel_order=ORDER)

# SetUp temp range and color range.  range for computer: 25 - 65 or 70?
minBTemp = 21
maxBTemp = 27
# import midi_testing_stuff

# 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 D5.
ow_bus = OneWireBus(board.GP2)
# Scan for sensors and grab them all
devices = ow_bus.scan()
print(devices)
ds18 = [DS18X20(ow_bus, found) for found in devices]

# Main loop to print the temperature every second.
while True:
    temperature = sum(ds.temperature for ds in ds18) / len(ds18)
    print("Temperature: {0:0.3f}C".format(temperature))
    print(tuple(ds.temperature for ds in ds18))
    time.sleep(.1)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
import time
import board
from adafruit_onewire.bus import OneWireBus, OneWireAddress
from adafruit_ds18x20 import DS18X20

# !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!!
ROM1 = b"(\xbb\xfcv\x08\x00\x00\xe2"
ROM2 = b"(\xb3t\xd3\x08\x00\x00\x9e"
ROM3 = b"(8`\xd4\x08\x00\x00i"
# !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!!

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

# Uncomment this to get a listing of currently attached ROMs
# for device in ow_bus.scan():
#     print(device.rom)

# Use pre-determined ROM codes for each sensors
temp1 = DS18X20(ow_bus, OneWireAddress(ROM1))
temp2 = DS18X20(ow_bus, OneWireAddress(ROM2))
temp3 = DS18X20(ow_bus, OneWireAddress(ROM3))

# Main loop to print the temperatures every second.
while True:
    print("Temperature 1 = {}".format(temp1.temperature))
    print("Temperature 2 = {}".format(temp2.temperature))
    print("Temperature 3 = {}".format(temp3.temperature))
    print("-" * 20)
    time.sleep(1)
Exemplo n.º 8
0
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

JSON_POST_URL = "https://udsensors.tk/api/Feather/"

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)