def pinUpdate(self, pinName, value): """ main function to update a pin: the passed name has to be a valid name. It has to be among the keys read from ablib and stored in ValidPins or it has to be into the available MCU names (also read from ablib) """ pinName = pinName.upper() if pinName not in self.ValidPins.keys(): logger.error("unknown pin %s", pinName) return if self.ValidPins[pinName].value == value: logger.debug("pin %s value %s not changed: do nothing", pinName, value) return else: logger.debug("update pin:%s value:%s use:%s to value:%s", pinName, self.ValidPins[pinName].value, self.ValidPins[pinName].mode, value) #if not self.isNumeric(value): #logger.error("Value %s not admitted: pin %s unchanged", value, pinName) #return try: logger.debug("pin %s commanded to be %s", pinName, value) if self.ValidPins[ pinName].invert: # is True: Invert data value (useful for 7 segment common anode displays) value = 1 - abs(value) if self.ValidPins[pinName].mode == POUTPUT: # if already in output self.ValidPins[pinName].value = value self.ValidPins[pinName].instance.set_value( value) # set output to 1 or 0 logger.debug("pin %s set to %s", pinName, value) elif self.ValidPins[pinName].mode in [ PUNUSED, PINPUT ]: # if pin is in input or not used old_mode = self.ValidPins[pinName].mode self.ValidPins[pinName].mode = POUTPUT # switch it to output self.ValidPins[pinName].instance = AB.Pin(pinName, POUTPUT) self.ValidPins[pinName].value = value self.ValidPins[pinName].instance.set_value( value) # set output to 1 to 0 logger.debug("pin %s was %s - now output to value %s", pinName, old_mode, value) except ValueError: logger.error("Error trying to update pin %s to value %s", pinName, value) pass except IOError, e: logger.error("Unable to access pin %s: %s", pinName, e) pass
def setPinMode(self, pinName, mode): """ set pin mode for a single pin """ pinName = pinName.upper() if pinName not in self.ValidPins.keys(): logger.error("setPinMode: unknown pin %s", pinName) return if self.ValidPins[pinName].mode == mode: logger.debug("pin mode not changed: do nothing") return self.ValidPins[pinName].mode = mode AB.Pin(pinName, mode) logger.debug("pin %s set to %s mode", pinName, mode)
def resetPin(self, pinName): """ reset all pins """ pinName = pinName.upper() if pinName not in self.ValidPins.keys(): logger.error("unknown pin %s", pinName) return if self.ValidPins[pinName].mode != PUNUSED: # set the default mode to OUTPUT: INPUT mode with trigger # should start one thread for each pin self.ValidPins[pinName].instance = None AB.Pin(pinName, POUTPUT) self.ValidPins[pinName].mode = PUNUSED self.ValidPins[pinName].value = PNONE self.ValidPins[pinName].invert = False logger.debug("reset pin %s", pinName)
import time import ablib Power_USB_A = ablib.Pin('N', '7', 'high') Power_USB_B = ablib.Pin('N', '8', 'high') Power_USB_C = ablib.Pin('N', '9', 'high') while True: Power_USB_B.off() Power_USB_C.off() print "USB A ON" Power_USB_A.on() time.sleep(15)
#!/usr/bin/python import time import ablib print "Telit ON/OFF" telitRESET = ablib.Pin('J6', '38', 'low') telitON = ablib.Pin('J6', '37', 'low') telitON.on() time.sleep(1) telitON.off()
#!/usr/bin/python #Factory test for Daisy-9 boards import ablib import time import os TXD3 = ablib.Pin("D10","2","high") RXD3 = ablib.Pin("D10","3","in") RTS3 = ablib.Pin("D10","4","high") CTS3 = ablib.Pin("D10","5","in") TXD1 = ablib.Pin("D13","2","high") RXD1 = ablib.Pin("D13","3","in") RTS1 = ablib.Pin("D13","4","high") CTS1 = ablib.Pin("D13","5","in") TXD3.on() if RXD1.get_value()==0: print "Error TXD3->RXD1" TXD3.off() if RXD1.get_value()==1: print "Error TXD3->RXD1" TXD1.on() if RXD3.get_value()==0: print "Error TXD1->RXD3" TXD1.off() if RXD3.get_value()==1: print "Error TXD1->RXD3"
ablib.set_value(kid_dictionary[key], 0) time.sleep(0.01) def modem_terminal(serial, string, timeout): serial.flushInput() serial.write(string) while timeout > 0: if serial.inWaiting() > 0: sys.stdout.write(serial.read(serial.inWaiting())) time.sleep(0.001) timeout = timeout - 1 print "" quectel_power = ablib.Pin('W', '10', 'high') quectel_power_key = ablib.Pin('E', '10', 'low') usb_a_power = ablib.Pin('N', '7', 'high') usb_b_power = ablib.Pin('N', '8', 'high') usb_c_power = ablib.Pin('N', '9', 'high') kid_dictionary = ablib.D10_kernel_ids thread.start_new_thread(slide, (kid_dictionary, 1)) kid_dictionary = ablib.D11_kernel_ids thread.start_new_thread(slide, (kid_dictionary, 1)) kid_dictionary = ablib.D12_kernel_ids thread.start_new_thread(slide, (kid_dictionary, 1)) kid_dictionary = ablib.D13_kernel_ids thread.start_new_thread(slide, (kid_dictionary, 1)) kid_dictionary = ablib.D14_kernel_ids
import ablib import time print "Blinking led" print "Type ctrl-C to exit" led = ablib.Pin('J7','3','low') while True: time.sleep(0.2) led.on() time.sleep(0.2) led.off()
out_file.write(number + "\n") out_file.close() ser = serial.Serial(port='/dev/ttyS1', baudrate=115200, timeout=1, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) gate = ablib.Daisy8('D11', 'first', 'RL1') while True: #Check if the modem is on quectel_STATUS = ablib.Pin('N6', 'INPUT') if quectel_STATUS.get_value() == 1: print "Modem is ON" break else: print "Turn ON the modem" quectel_power = ablib.Pin('W10', 'HIGH') quectel_power_key = ablib.Pin('E10', 'LOW') quectel_power_key.on() sleep(1) quectel_power_key.off() ser.flushInput() ser.flushOutput()
from time import sleep import ablib print "Modem ON" quectel_power = ablib.Pin('W10', 'HIGH') quectel_power_key = ablib.Pin('E10', 'LOW') quectel_power_key.on() sleep(1) quectel_power_key.off()
rtc = quectel.readlines() print rtc def fatal_error(message): print "Error: ", message lcd.clear() lcd.setcurpos(0, 0) lcd.putstring("Error:") lcd.setcurpos(0, 1) lcd.putstring(message) sys.exit(1) #Modem ON quectel_power = ablib.Pin('W', '10', 'low') time.sleep(0.5) quectel_power_key = ablib.Pin('E', '10', 'low') quectel_power.on() time.sleep(0.5) quectel_power_key.on() time.sleep(1) quectel_power_key.off() #Serial link with Modem configuration quectel = serial.Serial(port="/dev/ttyS1", baudrate=115200, timeout=1, parity=serial.PARITY_NONE,
import ablib import time print "Pressing button" print "Type ctrl-C to exit" led = ablib.Pin('J7','3','low') button = ablib.Pin('J7','5','in') while True: if button.get_value()==0: led.on() else: led.off()
import ablib import time power_overrun = ablib.Pin('W', '9', 'in') while True: if power_overrun.get_value() == False: print "Power overrun" time.sleep(1)