def _main_loop(self): while True: try: self.led_usb = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) led_usb = self.led_usb print("Found: 0x%04x 0x%04x %s %s" % (led_usb.idVendor, led_usb.idProduct, led_usb.productName, led_usb.manufacturer)) while True: if not self.blink: self._set_color(self.color) time.sleep(1) else: self._set_color(self.color) time.sleep(self.on_time) self._set_color((0, 0, 0)) time.sleep(self.off_time) except USBFailed: print("USB communication problem, retrying later") time.sleep(2) except USBDeviceNotFound: print("No USB device found, retrying later") time.sleep(2)
def write(): user_input = raw_input("DigiUSB#") user_input = user_input+"\n" theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) for c in user_input: theDevice.write(ord(c)) time.sleep(0.1)
def send_to_digi(m_str): m_str += '\n' try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: #sys.exit("No DigiUSB Device Found") return "ERROR: No DigiUSB Device Found" for c in m_str: theDevice.write(ord(c))
def __init__(self): try: self.device = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: raise rospy.ROSException("No DigiUSB Device Found") rospy.init_node('temperature_sensor_publisher') self.pub = rospy.Publisher('temp', Temperature, queue_size=50) self.rate = 1.0
class LED(object): def __init__(self): self._digispark = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) self.off() def on(self, color_name): rgb_values = webcolors.name_to_rgb(color_name) self._digispark.write(ord("s")) for v in rgb_values: self._digispark.write(v) def off(self): rgb_values = [0, 0, 0] self._digispark.write(ord("s")) for v in rgb_values: self._digispark.write(v) def blink(self, color_name, blink_count): self.off() for _ in xrange(blink_count): self.on(color_name) time.sleep(.75) self.off() time.sleep(.75)
def connect(self): if self.DEBUG: print "Connecting Device" deviceBound = False while (not deviceBound): try: self.device = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) deviceBound = True except Exception as e: print "Problem connecting:", e time.sleep(1) print 'retrying...'
class DigisparkTemperature(): def __init__(self): try: self.device = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: raise rospy.ROSException("No DigiUSB Device Found") rospy.init_node('temperature_sensor_publisher') self.pub = rospy.Publisher('temp', Temperature, queue_size=50) self.rate = 1.0 def handle(self): self.device.write(ord('\n')) temp = Temperature() temp.header.stamp = self.current_time temp.header.frame_id = 'temp_frame' buf = StringIO() while True: try: c = chr(self.device.read()) if c == '\n': break buf.write(c) except Exception: continue try: rospy.loginfo(buf.getvalue()) v = json.loads(buf.getvalue()) temp.temperature = v['temp'] except ValueError as e: rospy.loginfo(e) return except Exception as e: rospy.logerror(e) return self.pub.publish(temp) def spin(self): r = rospy.Rate(self.rate) while not rospy.is_shutdown(): self.current_time = rospy.Time.now() self.handle() r.sleep()
def init_function(): if len(sys.argv) == 1: print("Usage [<Mode>] [<param>..]") return mode = int(sys.argv[1]) theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) if theDevice is None: print("Cannot found the devie") return print("Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer)) # mode send_param(theDevice, mode) # params for x in range(2, len(sys.argv)): send_param(theDevice, int(sys.argv[x])) pass return
def blink(): theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) red = request.query.get('red') green = request.query.get('green') blue = request.query.get('blue') print("red:{}, green:{}, blue:{}".format(red, green, blue)) red = int(mapping(red)) green = int(mapping(green)) blue = int(mapping(blue)) theDevice.write(ord("s")) theDevice.write(red) theDevice.write(green) theDevice.write(blue) print("mred:{}, mgreen:{}, mblue:{}".format(red, green, blue))
def connect(self): if self.DEBUG: print "Connecting Device" deviceBound = False while not deviceBound: try: self.device = ArduinoUsbDevice(idVendor=0x16C0, idProduct=0x05DF) deviceBound = True except Exception as e: print "Problem connecting:", e time.sleep(1) print "retrying..."
def read(): try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) except: pass while True: try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) try: sys.stdout.write(chr(theDevice.read())) sys.stdout.flush() except: # TODO: Check for exception properly time.sleep(0.5) except: # TODO: Check for exception properly time.sleep(1)
def write(): try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % ( theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) except: pass while True: user_input = raw_input("DigiUSB#") user_input = user_input + "\n" theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) for c in user_input: theDevice.write(ord(c)) time.sleep(0.1)
""" """ theDevice.write(byte1) theDevice.write(byte2) return chr(theDevice.read()) if __name__ == "__main__": if len(sys.argv) > 1: source = sys.argv[1] else: source = "13e971c3bd7ef968ac92174cbd63ca1ddb849f1e3161beb0a926b8e4af1c1338cecb02f34622a89e137c468f9e7060c33402ac3f8e044216bd96aca4062702f89cc7216ccfc9afb6" theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) bytes = [int(i + j, 16) for i,j in zip(source[::2], source[1::2])] un = "".join([decrypty_(byte1, byte2) for byte1, byte2 in zip(bytes[::2], bytes[1::2])]) print eval(un) raise SystemExit
# Written for PyUSB 1.0 (w/libusb 1.0.3) # import usb # 1.0 not 0.4 import sys sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: sys.exit("No DigiUSB Device Found") import sys import time while 1 == 1: try: lastChar = chr(theDevice.read()) if(lastChar == "\n"): break sys.stdout.write(lastChar)
class USBLedController(object): def __init__(self): self.blink = False self.on_time = 0 self.off_time = 0 self.color = (0, 0, 0) self.work_thread = threading.Thread(target=self._main_loop) self.work_thread.setDaemon(True) self.work_thread.start() def set_constant(self, color): self.blink = False self.color = color def set_blink(self, color, on_time, off_time): self.on_time = on_time self.off_time = off_time self.color = color self.blink = True def _main_loop(self): while True: try: self.led_usb = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) led_usb = self.led_usb print("Found: 0x%04x 0x%04x %s %s" % (led_usb.idVendor, led_usb.idProduct, led_usb.productName, led_usb.manufacturer)) while True: if not self.blink: self._set_color(self.color) time.sleep(1) else: self._set_color(self.color) time.sleep(self.on_time) self._set_color((0, 0, 0)) time.sleep(self.off_time) except USBFailed: print("USB communication problem, retrying later") time.sleep(2) except USBDeviceNotFound: print("No USB device found, retrying later") time.sleep(2) def _set_color(self, color): r, g, b = color for retry in range(5): try: if retry > 0: # If retrying, flush any previous transfer for _ in range(3): self.led_usb.write(0) self.led_usb.write(ord("s")) self.led_usb.write(r) self.led_usb.write(g) self.led_usb.write(b) return except usb.core.USBError as exp: print(f"USB error retrying({retry})...") print(exp) raise USBFailed("USB communication failed")
# # Assumes 'UsbStreamDemo1.pde' is loaded on Arduino and # LEDs are present on pins 11, 12 and 13. # import usb # 1.0 not 0.4 import sys sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % ( theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) except: pass import sys import time while 1 == 1: try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) try: sys.stdout.write(chr(theDevice.read()))
try: tty.setraw(fd) ch = sys.stdin.read(1) except KeyboardInterrupt: sys.exit(0) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % ( theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) except: print("Couldn't find device.") sys.exit(0) # Switch mode (PlayPingPong). theDevice.write(ord('p')) time.sleep(0.1) while True: key = getch()
class OpenWestKit: def __init__(self, debug=False): self.DEBUG = debug self.connect() self.brightness(255) time.sleep(1) self.brightness(64) self.clear() def connect(self): if self.DEBUG: print "Connecting Device" deviceBound = False while (not deviceBound): try: self.device = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) deviceBound = True except Exception as e: print "Problem connecting:", e time.sleep(1) print 'retrying...' # Sends a byte to the device def sendByteToDevice(self, data): try: self.device.write(data) except Exception as e: print "Unable to write to device:", e self.connect() # Try to rebind the device return 0 return 1 # Read all data off the bus. Multiple codes may be waiting so we keep # reading until there is no more data. We then return it all in an array. # Codes: # z - Acknowledgement of LED set command # a - Button 1 pressed # b - Button 2 pressed def readData(self): result = [] while (True): # keep reading while we have data try: result.append(str(unichr(self.device.read()))) except: break return result # Sets the master brightness on the device (0-255) def brightness(self, bright): if self.DEBUG: print "Setting master brightness to: ", bright while (True): if (self.sendByteToDevice(42)): # LED control code if (self.sendByteToDevice(255)): # Brightness control code if (self.sendByteToDevice(bright)): # brightness amount break # Sets a Pixel to RGB value (0-3, 0-255, 0-255, 0-255) def setPixel(self, pixelNum, redByte, greenByte, blueByte): if self.DEBUG: print "Setting pixel [ %s ] to values: %s, %s, %s" % ( pixelNum, redByte, greenByte, blueByte) while (True): if (self.sendByteToDevice(42)): # LED control code if (self.sendByteToDevice(pixelNum) ): # LED position control code if (self.sendByteToDevice(redByte)): if (self.sendByteToDevice(greenByte)): if (self.sendByteToDevice(blueByte)): break # Reset board to starting state with Red, Green, Blue, White LED def reset(self): self.brightness(10) self.setPixel(0, 255, 0, 0) self.setPixel(1, 0, 255, 0) self.setPixel(2, 0, 0, 255) self.setPixel(3, 255, 255, 255) # Helper method to turn all LEDs off def clear(self): self.setPixel(0, 0, 0, 0) self.setPixel(1, 0, 0, 0) self.setPixel(2, 0, 0, 0) self.setPixel(3, 0, 0, 0)
def __init__(self): self._digispark = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) self.off()
# Assumes 'UsbStreamDemo1.pde' is loaded on Arduino and # LEDs are present on pins 11, 12 and 13. # import usb # 1.0 not 0.4 import sys sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) except: pass import sys import time while 1 == 1:
class OpenWestKit: def __init__(self, debug=False): self.DEBUG = debug self.connect() self.brightness(255) time.sleep(1) self.brightness(64) self.clear() def connect(self): if self.DEBUG: print "Connecting Device" deviceBound = False while not deviceBound: try: self.device = ArduinoUsbDevice(idVendor=0x16C0, idProduct=0x05DF) deviceBound = True except Exception as e: print "Problem connecting:", e time.sleep(1) print "retrying..." # Sends a byte to the device def sendByteToDevice(self, data): try: self.device.write(data) except Exception as e: print "Unable to write to device:", e self.connect() # Try to rebind the device return 0 return 1 # Read all data off the bus. Multiple codes may be waiting so we keep # reading until there is no more data. We then return it all in an array. # Codes: # z - Acknowledgement of LED set command # a - Button 1 pressed # b - Button 2 pressed def readData(self): result = [] while True: # keep reading while we have data try: result.append(str(unichr(self.device.read()))) except: break return result # Sets the master brightness on the device (0-255) def brightness(self, bright): if self.DEBUG: print "Setting master brightness to: ", bright while True: if self.sendByteToDevice(42): # LED control code if self.sendByteToDevice(255): # Brightness control code if self.sendByteToDevice(bright): # brightness amount break # Sets a Pixel to RGB value (0-3, 0-255, 0-255, 0-255) def setPixel(self, pixelNum, redByte, greenByte, blueByte): if self.DEBUG: print "Setting pixel [ %s ] to values: %s, %s, %s" % (pixelNum, redByte, greenByte, blueByte) while True: if self.sendByteToDevice(42): # LED control code if self.sendByteToDevice(pixelNum): # LED position control code if self.sendByteToDevice(redByte): if self.sendByteToDevice(greenByte): if self.sendByteToDevice(blueByte): break # Reset board to starting state with Red, Green, Blue, White LED def reset(self): self.brightness(10) self.setPixel(0, 255, 0, 0) self.setPixel(1, 0, 255, 0) self.setPixel(2, 0, 0, 255) self.setPixel(3, 255, 255, 255) # Helper method to turn all LEDs off def clear(self): self.setPixel(0, 0, 0, 0) self.setPixel(1, 0, 0, 0) self.setPixel(2, 0, 0, 0) self.setPixel(3, 0, 0, 0)
# Assumes 'UsbStreamDemo1.pde' is loaded on Arduino and # LEDs are present on pins 11, 12 and 13. # import usb # 1.0 not 0.4 import sys sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % (theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) import sys import time import webcolors #sequence = [11,12,13]* 20
def updateColor(setColor): global color if color != setColor: color = setColor global taskbar_icon try: theDevice = ArduinoUsbDevice(idVendor=0x16C0, idProduct=0x05DF) icon = color if icon == "black": icon = "white" taskbar_icon.set_icon("icons/" + icon + ".png") # print "Color:" + color global red, green, blue, cyan, white, warmwhite, purple, magenta, yellow, orange, black if color == "red": color_list = red elif color == "green": color_list = green elif color == "blue": color_list = blue elif color == "cyan": color_list = cyan elif color == "white": color_list = white elif color == "warmwhite": color_list = warmwhite elif color == "purple": color_list = purple elif color == "magenta": color_list = magenta elif color == "yellow": color_list = yellow elif color == "orange": color_list = orange elif color == "black": color_list = black # while 1: # pin = int(pin) # if output == "\r": # print line # line ="" # else: # line += output # else: # print "Pin response didn't match." # byte val = sys.argv[1] print color_list theDevice.write(ord("s")) if color_list[0] == 0: theDevice.write(0) else: theDevice.write(int(color_list[0])) if color_list[1] == 0: theDevice.write(0) else: theDevice.write(int(color_list[1])) if color_list[2] == 0: theDevice.write(0) else: theDevice.write(int(color_list[2])) except: print "No device found"
def logicloop(loopy): try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: gui.alert( u'?? ???? ?? ???? ?????? ????? ??? ????? ????? \n ??? ?? ????? ????? ?? ????? ????' ) try: f = open('data.txt', 'r') a = pickle.load(f) #print a, "Bombs So Far At:", time.ctime() except: a = 0 b = 0 f = open('pase.txt', 'w') pickle.dump(b, f) f.close() startime = time.time() f = open('startime.txt', 'w') pickle.dump(startime, f) f.close() c = 0 f = open('shiftpase.txt', 'w') pickle.dump(c, f) f.close() shifttime = time.time() f = open('shifttime.txt', 'w') pickle.dump(shifttime, f) f.close() while True: lastChar = chr(theDevice.read()) sys.stdout.flush() while (lastChar == "0"): lastChar = chr(theDevice.read()) if (lastChar == "1"): winsound.PlaySound('bomb.wav', winsound.SND_FILENAME) f = open('data.txt', 'r') a = pickle.load(f) a = a + 1 #print a, "Bombs So Far At:", time.ctime() ddelay = 0 bombnum = a mywin['count'].left = '860' if (9 < a < 100): mywin['count'].left = '790' if (99 < a < 1000): mywin['count'].left = '720' if (999 < a): mywin['count'].left = '660' mywin['count'].size = (0, 0) mywin['count'].text = u'%s' % (bombnum) mywin['count'].transparent = False mywin['count'].transparent = True mywin['count'].bgcolor = 'transparent' f = open('data.txt', 'w') pickle.dump(a, f) f.close() lastChar = chr(theDevice.read()) mywin['statusbar'].text = u"???? ?????? ?????? ????: %s" % ( time.ctime()) f = open('pase.txt', 'r') b = pickle.load(f) b = b + 1 f = open('startime.txt', 'r') startime = pickle.load(f) pase = time.time() avg = (pase - startime) #print "time passed: ", avg avgpase = (b / avg) * 3600 #print b #print "bomb pase: ", avgpase avgpase = int(avgpase) bombpase = avgpase print bombpase if (bombpase < 1): mywin['bombpase'].fgcolor = u'#FFFFFF' mywin['bombpase'].left = '800' mywin['bombpase'].top = '500' mywin['bombpase'].size = (0, 0) mywin['bombpase'].text = u'--' mywin['bombpase'].transparent = False mywin['bombpase'].transparent = True mywin['bombpase'].bgcolor = 'transparent' if (1 <= bombpase < 10): mywin['bombpase'].fgcolor = u'#FFFFFF' mywin['bombpase'].left = '800' mywin['bombpase'].size = (0, 0) mywin['bombpase'].text = u'%s' % (bombpase) mywin['bombpase'].transparent = False mywin['bombpase'].transparent = True mywin['bombpase'].bgcolor = 'transparent' if (10 <= bombpase <= 33): mywin['bombpase'].fgcolor = u'#FFFFFF' mywin['bombpase'].left = '775' mywin['bombpase'].top = '480' mywin['bombpase'].size = (0, 0) mywin['bombpase'].text = u'%s' % (bombpase) mywin['bombpase'].transparent = False mywin['bombpase'].transparent = True mywin['bombpase'].bgcolor = 'transparent' if (34 <= bombpase <= 99): mywin['bombpase'].fgcolor = u'#FFFFFF' mywin['bombpase'].left = '775' mywin['bombpase'].top = '480' mywin['bombpase'].size = (0, 0) mywin['bombpase'].text = u'%s' % (bombpase) mywin['bombpase'].transparent = False mywin['bombpase'].transparent = True mywin['bombpase'].bgcolor = 'transparent' if (99 < bombpase): mywin['bombpase'].fgcolor = u'#FFFFFF' mywin['bombpase'].left = '780' mywin['bombpase'].top = '500' mywin['bombpase'].size = (0, 0) mywin['bombpase'].text = u'--' mywin['bombpase'].transparent = False mywin['bombpase'].transparent = True mywin['bombpase'].bgcolor = 'transparent' f = open('pase.txt', 'w') pickle.dump(b, f) f.close() f = open('shiftpase.txt', 'r') c = pickle.load(f) c = c + 1 f = open('shifttime.txt', 'r') shifttime = pickle.load(f) shiftpase = time.time() shiftavg = (shiftpase - shifttime) #print "time passed: ", shiftavg shiftavgpase = (c / shiftavg) * 3600 #print c #print "bomb pase: ", shiftavgpase shiftavgpase = int(shiftavgpase) shiftbombpase = shiftavgpase print shiftbombpase if (shiftbombpase < 1): mywin['shiftbombpase'].fgcolor = u'#FFFFFF' mywin['shiftbombpase'].left = '800' mywin['shiftbombpase'].top = '700' mywin['shiftbombpase'].size = (0, 0) mywin['shiftbombpase'].text = u'--' mywin['shiftbombpase'].transparent = False mywin['shiftbombpase'].transparent = True mywin['shiftbombpase'].bgcolor = 'transparent' if (1 <= shiftbombpase < 10): mywin['shiftbombpase'].fgcolor = u'#FFFFFF' mywin['shiftbombpase'].left = '800' mywin['shiftbombpase'].size = (0, 0) mywin['shiftbombpase'].text = u'%s' % (shiftbombpase) mywin['shiftbombpase'].transparent = False mywin['shiftbombpase'].transparent = True mywin['shiftbombpase'].bgcolor = 'transparent' if (10 <= shiftbombpase <= 33): mywin['shiftbombpase'].fgcolor = u'#FFFFFF' mywin['shiftbombpase'].left = '775' mywin['shiftbombpase'].top = '680' mywin['shiftbombpase'].size = (0, 0) mywin['shiftbombpase'].text = u'%s' % (shiftbombpase) mywin['shiftbombpase'].transparent = False mywin['shiftbombpase'].transparent = True mywin['shiftbombpase'].bgcolor = 'transparent' if (34 <= shiftbombpase <= 99): mywin['shiftbombpase'].fgcolor = u'#FFFFFF' mywin['shiftbombpase'].left = '775' mywin['shiftbombpase'].top = '680' mywin['shiftbombpase'].size = (0, 0) mywin['shiftbombpase'].text = u'%s' % (shiftbombpase) mywin['shiftbombpase'].transparent = False mywin['shiftbombpase'].transparent = True mywin['shiftbombpase'].bgcolor = 'transparent' if (99 < shiftbombpase): mywin['shiftbombpase'].fgcolor = u'#FFFFFF' mywin['shiftbombpase'].left = '780' mywin['shiftbombpase'].top = '700' mywin['shiftbombpase'].size = (0, 0) mywin['shiftbombpase'].text = u'--' mywin['shiftbombpase'].transparent = False mywin['shiftbombpase'].transparent = True mywin['shiftbombpase'].bgcolor = 'transparent' f = open('shiftpase.txt', 'w') pickle.dump(c, f) f.close() while (ddelay < 50000000): ddelay = ddelay + 1 break
sys.path.append(".") from arduino.usbdevice import ArduinoUsbDevice def codeToBytes(code): return struct.unpack("4B", struct.pack("I", code)) def sendCode(code): print "Sending %s" % str(code) for byte in codeToBytes(code): print " Sending byte %s" % hex(byte) theDevice.write(byte) if __name__ == "__main__": if len(sys.argv) != 2: print "Usage: %s CODE" print "CODE must be a 32 bit int." else: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % ( theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer ) code=int(sys.argv[1]) sendCode(code)
# The Blindinator v1.0 by Ivan Cooper & Meena Shah # created for San Francisco Science Hack Day 2014 from SimpleCV import * import usb, sys from arduino.usbdevice import ArduinoUsbDevice from collections import deque try: USBlindinator = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: sys.exit("Blindinator Not Found") # "calibration" given in servo values pleft = 66 pright = 141 ptop = 59 pbottom = 111 class point(object): def __init__(self, x, y): self.x = x self.y = y def aim_and_fire(): if lit: s = "*" else: s = "."
# /usr/bin/python # # Written for PyUSB 1.0 (w/libusb 1.0.3) # import usb, sys # 1.0 not 0.4 sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": try: theDevice = ArduinoUsbDevice(idVendor=0x16C0, idProduct=0x05DF) except: sys.exit("No DigiUSB Device Found") try: user_input = sys.argv[1] + "\n" except: exit("No data to send") for c in user_input: theDevice.write(ord(c))
#/usr/bin/python # # Written for PyUSB 1.0 (w/libusb 1.0.3) # import usb # 1.0 not 0.4 import sys sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) except: sys.exit("No DigiUSB Device Found") import sys import time while 1 == 1: try: lastChar = chr(theDevice.read()) if (lastChar == "\n"): break sys.stdout.write(lastChar) sys.stdout.flush() except:
def updateColor(setColor): global color if (color != setColor): color = setColor global taskbar_icon try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) icon = color if (icon == "black"): icon = "white" taskbar_icon.set_icon("icons/"+icon+".png") # print "Color:"+color global red,green,blue,cyan,white,warmwhite,purple,magenta,yellow,orange,black if color == 'red': color_list = red elif color == 'green': color_list = green elif color == 'blue': color_list = blue elif color == 'cyan': color_list = cyan elif color == 'white': color_list = white elif color == 'warmwhite': color_list = warmwhite elif color == 'purple': color_list = purple elif color == 'magenta': color_list = magenta elif color == 'yellow': color_list = yellow elif color == 'orange': color_list = orange elif color == 'black': color_list = black # while 1: #pin = int(pin) #if output == "\r": # print line # line ="" #else: # line += output #else: # print "Pin response didn't match." #byte val = sys.argv[1] print color_list theDevice.write(ord("s")) if color_list[0] == 0: theDevice.write(0) else: theDevice.write(int(color_list[0])) if color_list[1] == 0: theDevice.write(0) else: theDevice.write(int(color_list[1])) if color_list[2] == 0: theDevice.write(0) else: theDevice.write(int(color_list[2])) except: print "No device found"
def decrypty_(byte1, byte2): """ """ theDevice.write(byte1) theDevice.write(byte2) return chr(theDevice.read()) if __name__ == "__main__": if len(sys.argv) > 1: source = sys.argv[1] else: source = "13e971c3bd7ef968ac92174cbd63ca1ddb849f1e3161beb0a926b8e4af1c1338cecb02f34622a89e137c468f9e7060c33402ac3f8e044216bd96aca4062702f89cc7216ccfc9afb6" theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % ( theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) bytes = [int(i + j, 16) for i, j in zip(source[::2], source[1::2])] un = "".join([ decrypty_(byte1, byte2) for byte1, byte2 in zip(bytes[::2], bytes[1::2]) ]) print eval(un) raise SystemExit
# # Assumes 'UsbStreamDemo1.pde' is loaded on Arduino and # LEDs are present on pins 11, 12 and 13. # import usb # 1.0 not 0.4 import sys, time sys.path.append("..") from arduino.usbdevice import ArduinoUsbDevice if __name__ == "__main__": try: theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) print "Found: 0x%04x 0x%04x %s %s" % ( theDevice.idVendor, theDevice.idProduct, theDevice.productName, theDevice.manufacturer) except: pass while 1 == 1: user_input = raw_input("DigiUSB#") user_input = user_input + "\n" theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df) for c in user_input: theDevice.write(ord(c)) time.sleep(0.1)