Esempio n. 1
0
def read_tmp():
    tp = adc(pin('X2'))
    val = tp.read()
    print(val, ' div ')
    mv = (val * div * 1000)
    print(mv, 'mV ')
    tmp = ((val * div * 1000) - 500) / 10
    print(tmp, '°C\n')
Esempio n. 2
0
def print_tmp():
    tp = adc(pin('X22'))
    val = tp.read()
    print(val, ' div ')
    #mv = (val*div)
    print(mv, 'mV ')
    #tmp = (val/4095)*3.3*100#-50 #close but no cigar
    tmp = val * (3300 / 4096)
    print(tmp / 10, ' °C\n ')
import pyb
import machine, time
from machine import Pin

tp = pyb.pin('X6', pyb.Pin.OUT_PP) #trigger out
ep = pyb.Pin(pyb.Pin.board.X5, pyb.Pin.IN) #echo input

class HCSR04(object):
    def __init__(self, trigger_pin, echo_pin, echo_timeout_us=500*2*30):
        self.echo_timeout_us = echo_timeout_us
        self.trigger = Pin(trigger_pin, mode=Pin.OUT, pull=None)
        self.trigger.value(0)
        self.echo = Pin(echo_pin, mode=Pin.IN, pull=None)

    def _send_pulse_and_wait(self):
        self.trigger.value(0)
        time.sleep_us(5)
        self.trigger.value(1)
        time.sleep_us(10)
        self.trigger.value(0)
        try:
            pulse_time = machine.time_pulse_us(self.echo, 1, self.echo_timeout_us)
            return pulse_time
        except OSError as ex:
            if ex.args[0] == 110:
                raise OSError('Out of range')
            raise ex

    def distance_cm(self):
        pulse_time = self._send_pulse_and_wait()
        cms = (pulse_time / 2) / 29.1
Esempio n. 4
0
def read_tmp():
    tp = adc(pin('X22'))
    val = tp.read()
    tmp = (val / 4095) * 3.3 * 100  #-50 #close but no cigar
    return tmp
Esempio n. 5
0
def print_mv():
    tp = adc(pin('X22'))
    val = tp.read()