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 time.sleep(0.5)
__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(): gpio.output(LEDR, 0)
__copyright__ = "Copyright 2014, RoboTonics" __credits__ = ["David Cotterill-Drew"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "*****@*****.**" ENA = port.PC0 IN1 = port.PC1 IN2 = port.PC2 IN3 = port.PC3 IN4 = port.PC4 ENB = port.PC5 gpio.init() gpio.setcfg(ENA, gpio.OUTPUT) gpio.setcfg(IN1, gpio.OUTPUT) gpio.setcfg(IN2, gpio.OUTPUT) gpio.setcfg(IN3, gpio.OUTPUT) gpio.setcfg(IN4, gpio.OUTPUT) gpio.setcfg(ENB, gpio.OUTPUT) def left(): gpio.output(ENA, 1) gpio.output(ENB, 1) gpio.output(IN1, 1) gpio.output(IN2, 0) gpio.output(IN3, 0) gpio.output(IN4, 1)
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
readInput |= 0x1 # disable the mcp3008 module gpio.output(chipSelectPin, gpio.HIGH) return readInput # do not forget to change these to meet your own wiring SPICLK = port.PE9 SPIMISO = port.PE8 SPIMOSI = port.PE7 SPICS = port.PE6 # Initialization of the used gpios gpio.setcfg(SPIMOSI, gpio.OUTPUT) gpio.setcfg(SPIMISO, gpio.INPUT) gpio.setcfg(SPICLK, gpio.OUTPUT) gpio.setcfg(SPICS, gpio.OUTPUT) # the analog device is placed on channel 0 here, you can change it if you # need to do so chosenChannel = 0 while gpio.HIGH: # read analog value (0 to 1023) trim_pot = readadc(chosenChannel, SPICLK, SPIMOSI, SPIMISO, SPICS) print("Value: " + str(trim_pot)) # convert the read value to a voltage
__license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __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 time.sleep(0.5)
from pyA13.gpio import gpio from pyA13.gpio import port __author__ = "Stefan Mavrodiev" __copyright__ = "Copyright 2014, Olimex LTD" __credits__ = ["Stefan Mavrodiev"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "*****@*****.**" led = port.PG9 gpio.init() gpio.setcfg(led, gpio.OUTPUT) try: print ("Press CTRL+C to exit") while True: gpio.output(led, 1) sleep(0.1) gpio.output(led, 0) sleep(0.1) gpio.output(led, 1) sleep(0.1) gpio.output(led, 0) sleep(0.1) sleep(0.6)
from pyA13.gpio import port __author__ = "Stefan Mavrodiev" __copyright__ = "Copyright 2014, Olimex LTD" __credits__ = ["Stefan Mavrodiev"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "*****@*****.**" led = connector.gpio0p0 # This is the same as port.PH2 button = connector.gpio3p40 """Init gpio module""" gpio.init() """Set directions""" gpio.setcfg(led, gpio.OUTPUT) gpio.setcfg(button, gpio.INPUT) """Enable pullup resistor""" gpio.pullup(button, gpio.PULLUP) #gpio.pullup(button, gpio.PULLDOWN) # Optionally you can use pull-down resistor try: print("Press CTRL+C to exit") while True: state = gpio.input(button) # Read button state """Since we use pull-up the logic will be inverted""" gpio.output(led, not state) except KeyboardInterrupt: print("Goodbye.")
__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(): gpio.output(LEDR,0) def ledl_off():
__author__ = "Stefan Mavrodiev" __copyright__ = "Copyright 2014, Olimex LTD" __credits__ = ["Stefan Mavrodiev"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "*****@*****.**" led = connector.gpio0p0 # This is the same as port.PH2 button = connector.gpio3p40 """Init gpio module""" gpio.init() """Set directions""" gpio.setcfg(led, gpio.OUTPUT) gpio.setcfg(button, gpio.INPUT) """Enable pullup resistor""" gpio.pullup(button, gpio.PULLUP) #gpio.pullup(button, gpio.PULLDOWN) # Optionally you can use pull-down resistor try: print ("Press CTRL+C to exit") while True: state = gpio.input(button) # Read button state """Since we use pull-up the logic will be inverted""" gpio.output(led, not state) except KeyboardInterrupt:
__credits__ = ["David Cotterill-Drew"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "*****@*****.**" ENA=port.PC0 IN1=port.PC1 IN2=port.PC2 IN3=port.PC3 IN4=port.PC4 ENB=port.PC5 gpio.init() gpio.setcfg(ENA,gpio.OUTPUT) gpio.setcfg(IN1,gpio.OUTPUT) gpio.setcfg(IN2,gpio.OUTPUT) gpio.setcfg(IN3,gpio.OUTPUT) gpio.setcfg(IN4,gpio.OUTPUT) gpio.setcfg(ENB,gpio.OUTPUT) def left(): gpio.output(ENA, 1) gpio.output(ENB, 1) gpio.output(IN1, 1) gpio.output(IN2, 0) gpio.output(IN3, 0) gpio.output(IN4, 1)