Пример #1
0
def main():
        with mcp3008.MCP3008() as adc:
                while True:
                        p1 = adc.read([mcp3008.CH2])[0]
                        print p1
                        for i in range(p1 / 100):
                                print ".",
                        time.sleep(0.1)
def main():
        with mcp3008.MCP3008() as adc:
                t1 = adc.read([mcp3008.CH0])[0]*bitcoeff
                l1 = adc.read([mcp3008.CH1])[0]*bitcoeff
                lr = (vref*r1)/(vref-l1)
                tr = (vref*r1)/(vref-t1)
                #print lr
                #print l1, t1
                invtmpk = (1/t0) + (1/b)*math.log1p(tr/r0)
                tempc = (1/invtmpk) - kelvin
                print tempc, lr
Пример #3
0
    def __init__(self):

        # Set the board.
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)

        # Setup outputs.
        for pin in self.__output_pins:
            GPIO.setup(pin, GPIO.OUT)
            GPIO.output(pin, False)

        # Setup inputs.
        for pin in self.__input_pins:
            GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

        # Initialize the timers.
        self.init_c1()
        self.init_c2()

        self.__adc = mcp3008.MCP3008(
        )  #Adafruit_MCP3008.MCP3008(clk=self.__CLK, cs=self.__CS, miso=self.__MISO, mosi=self.__MOSI)

        self.__output_len = len(self.__output_pins)
        self.__input_len = len(self.__input_pins)
Пример #4
0
# Importing modules
import mcp3008
import time

t0 = time.time()
with mcp3008.MCP3008(device=0) as adc:
    try:
        while True:
            c0, c1 = adc.read([mcp3008.CH0, mcp3008.CH1], norm=True)
            print("{:4} {:4}  {:.4f}       \r".format(c0, c1,
                                                      time.time() - t0),
                  end="")
            #            data = adc.read_all(norm=True)
            #            print(data, time.time() - t0)
            time.sleep(0.1)
    except KeyboardInterrupt:
        print()
        print("Closing...")
Пример #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
RPi_mcp3008 example file
'''
import mcp3008

if __name__ == '__main__':
    with mcp3008.MCP3008(speed=15000) as chip:
        print(chip.read_all(4.35))
        print(chip.read_all())
    with mcp3008.MCP3008.fixed([mcp3008.CH0]) as chip:
        print(chip())
        print(chip(4.35))
Пример #6
0
        nowDay = dt[2]
        nowHour = dt[3]
        nowMinute = dt[4]

        sensorHumdity, sensorTemperture = dht.read_retry(dht.DHT22, pinDHT22)
        if sensorHumdity is None:
            sensorHumdity = 0
        else:
            sensorHumdity = int(sensorHumdity)

        if sensorTemperture is None:
            sensorTemperture = 0
        else:
            sensorTemperture = int(sensorTemperture)

        adc = mcp3008.MCP3008()
        tmpValue = adc.read([mcp3008.CH0])
        sensorLight_r = tmpValue[0]
        tmpValue = adc.read([mcp3008.CH1])
        sensorLight_l = tmpValue[0]
        tmpValue = adc.read([mcp3008.CH2])
        sensorLight_c = tmpValue[0]
        tmpValue = adc.read([mcp3008.CH3])
        sensorSound = tmpValue[0]
        adc.close()

        secondsWait = time.time() - lastPIRdetect

        # 如果已經超過PIR delay時間
        if secondsWait > pirDelay:
            # 但是PIR偵測到有人
Пример #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
RPi_mcp3008 example file
'''
import mcp3008

if __name__ == '__main__':
    with mcp3008.MCP3008() as chip:
        print(chip.read_all(4.35))
        print(chip.read_all())
    with mcp3008.MCP3008.fixed([CH0]) as chip:
        print(chip())
        print(chip(4.35))
Пример #8
0
import mcp3008

with mcp3008.MCP3008() as adc:
    print adc.read([mcp3008.CH0])  # prints raw data [CH0]
def main():
    with mcp3008.MCP3008() as adc:
        while True:
            p1 = adc.read([mcp3008.CH2])[0]
            publish.single("humannode1/pulse", p1, hostname="192.168.2.83")
            time.sleep(0.2)