Пример #1
0
__email__ = "*****@*****.**"

Trigger_Ff=port.PE8
Echo_Ff=port.PE9
Trigger_Fr=port.PB4
Echo_Fr=port.PB3
Trigger_Fb=port.PC6
Echo_Fb=port.PC5
Trigger_Fl=port.PE10
Echo_Fl=port.PE11





gpio.init()
gpio.setcfg(Trigger_Ff,gpio.OUTPUT)
gpio.setcfg(Echo_Ff,gpio.INPUT)

gpio.setcfg(Trigger_Fr,gpio.OUTPUT)
gpio.setcfg(Echo_Fr,gpio.INPUT)

gpio.setcfg(Trigger_Fb,gpio.OUTPUT)
gpio.setcfg(Echo_Fb,gpio.INPUT)

gpio.setcfg(Trigger_Fl,gpio.OUTPUT)
gpio.setcfg(Echo_Fl,gpio.INPUT)


def front():
	gpio.output(Trigger_Ff,0) # Set Trigger LOW
Пример #2
0
from pyA13.gpio import port

__author__ = "David Cotterill-Drew"
__copyright__ = "Copyright 2014, RoboTonics"
__credits__ = ["David Cotterill-Drew"]
__license__ = "GPL"
__version__ = "2.0"
__maintainer__ = __author__
__email__ = "*****@*****.**"

LEDR = port.PE6
LEDL = port.PC11
LEDIRR = port.PE7
LEDIRL = port.PC10

gpio.init()
gpio.setcfg(LEDR, gpio.OUTPUT)
gpio.setcfg(LEDL, gpio.OUTPUT)
gpio.setcfg(LEDIRR, gpio.OUTPUT)
gpio.setcfg(LEDIRL, gpio.OUTPUT)


def ledr_on():
    gpio.output(LEDR, 1)


def ledl_on():
    gpio.output(LEDL, 1)


def ledr_off():
Пример #3
0
def DHT11Measures():
    # --------------------------------------
    # initialisation
    # refer to the tutorial for more information about the
    # GPIO pins in the A13-SOM-LTE

    sensor = port.PE11
    gpio.init()

    # --------------------------------------
    # trigger measure

    gpio.setcfg(sensor, gpio.OUTPUT)
    gpio.output(sensor, 1)
    time.sleep(0.025)
    gpio.output(sensor, 0)
    time.sleep(0.02)

    # ----------------------------------------
    # grab data

    gpio.setcfg(sensor, gpio.INPUT)


    data = []
    bit_count = 0
    tmp = 0
    count = 0
    HumidityBit = "0"
    TemperatureBit = ""
    crc = ""
    threshold = 9

    for i in range(0, 1500):
        data.append(gpio.input(sensor))
    # print(data)

    # --------------------------------------------
    # treat data to extract the values


    def bin2dec(string_num):
        return str(int(string_num, 2))

    try:

        # You may need to add this to your code, as normally the sensor
        # starts by sending a short sequence of 0s then another short
        # sequence of 1s to show it is available before sending the
        # metrics data, as I could not see this in my data I just did not
        # use this code

        # Code

        # if data[count] == 0:
        #     while data[count] == 0:
        #         count += 1
        # while data[count] == 1:
        #     tmp = 1
        #     count += 1

        # End of code

        # The first bit of data being normally truncated and as it is a zero for sure
        # (humidity is always under 100%) then we directly put a 0 in HumidityBit and we read
        # the next 31 bits which are structured as follows :
        # Humidity (7bits) - 0 byte - Temperature (8bits) - 0
        for i in range(0, 31):
            bit_count = 0

            while data[count] == 0:
                tmp = 1
                count += 1

            while data[count] == 1:
                bit_count += 1
                count += 1

            if bit_count > threshold:
                if 0 <= i < 7:
                    HumidityBit += "1"
                if 15 <= i < 23:
                    TemperatureBit += "1"
            else:
                if 0 <= i < 7:
                    HumidityBit += "0"
                if 15 <= i < 23:
                    TemperatureBit += "0"

    except Exception as e:
        print(e)
        print("A problem occurred during data gathering")
        exit(0)

    # the next 8 bits encode CRC which is equal to the sum of
    # the temperature value and the humidity value

    try:
        for i in range(0, 8):
            bit_count = 0

            while data[count] == 0:
                tmp = 1
                count += 1

            while data[count] == 1:
                bit_count += 1
                count += 1

            if bit_count > threshold:
                crc += "1"
            else:
                crc += "0"

    except Exception as e:
        print(e)
        print("A problem occurred during CRC calculation")
        exit(0)

    Humidity = bin2dec(HumidityBit)
    Temperature = bin2dec(TemperatureBit)

    # --------------------------------------
    # Check CRC is correct then print results

    if int(Humidity) + int(Temperature) - int(bin2dec(crc)) == 0:
        return ("Humidity = " + Humidity + "%"), ("Temperature = " + Temperature + "C")
    else:
        print("Wrong data, incorrect CRC")
        return None