def shootAndPrint(): os.system( "sudo fswebcam -r 640x480 --no-banner /home/pi/photobooth/photo1.png") pt = Adafruit_Thermal("/dev/serial0", 19200, timeout=5) #pt.println("test") pic = im.open("/home/pi/photobooth/photo1.png") pic2 = pic.rotate(-90).resize((384, 512), im.ANTIALIAS).convert("1") pic2.save("photo2.bmp") data = list(pic2.getdata()) echauffement = [170] * 9600 print(len(data)) L = [] for x in data: if x == 0: L.append(1) else: L.append(0) print("done") M = [] i = 0 while i < 196608: oct = 0 for k in range(7, -1, -1): #print(i) #print(k) oct += L[i] * (2**k) i += 1 M.append(oct) print(len(M)) #pt.printBitmap(384,200, echauffement) #pt.feed(2) pt.printBitmap(384, 512, M, True)
printer.println("Small") printer.justify('C') printer.println("normal\nline\nspacing") printer.setLineHeight(50) printer.println("Taller\nline\nspacing") printer.setLineHeight() # Reset to default printer.justify('L') # Barcode examples printer.feed(1) # CODE39 is the most common alphanumeric barcode printer.printBarcode("ADAFRUT", printer.CODE39) printer.setBarcodeHeight(100) # Print UPC line on product barcodes printer.printBarcode("123456789123", printer.UPC_A) # Print the 75x75 pixel logo in adalogo.py import gfx.adalogo as adalogo printer.printBitmap(adalogo.width, adalogo.height, adalogo.data) # Print the 135x135 pixel QR code in adaqrcode.py import gfx.adaqrcode as adaqrcode printer.printBitmap(adaqrcode.width, adaqrcode.height, adaqrcode.data) printer.println("Adafruit!") printer.feed(2) printer.sleep() # Tell printer to sleep printer.wake() # Call wake() before printing again, even if reset printer.setDefault() # Restore printer to defaults
printer.justify('C') printer.println("normal\nline\nspacing") printer.setLineHeight(50) printer.println("Taller\nline\nspacing") printer.setLineHeight() # Reset to default printer.justify('L') # Barcode examples printer.feed(1) # CODE39 is the most common alphanumeric barcode printer.printBarcode("ADAFRUT", printer.CODE39) printer.setBarcodeHeight(100) # Print UPC line on product barcodes printer.printBarcode("123456789123", printer.UPC_A) # Print the 75x75 pixel logo in adalogo.py import gfx.adalogo as adalogo printer.printBitmap(adalogo.width, adalogo.height, adalogo.data) # Print the 135x135 pixel QR code in adaqrcode.py import gfx.adaqrcode as adaqrcode printer.printBitmap(adaqrcode.width, adaqrcode.height, adaqrcode.data) printer.println("Adafruit!") printer.feed(3) # Reset printer printer.setDefault() printer.flush() printer.sleep()
printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5) printer.justify('C') printer.inverseOn() printer.setSize('L') printer.println("SeeedStudio") printer.inverseOff() img = Image.open("qrcode.bmp") img = img.tobitmap() # print(type(img)) # img=img[78:-2] import gfx.adalogo as adalogo printer.printBitmap(204, 204, adalogo.data) # # Test inverse on & off # printer.inverseOn() # printer.println("Inverse ON") # printer.inverseOff() # # # Test character double-height on & off # printer.doubleHeightOn() # printer.println("Double Height ON") # printer.doubleHeightOff() # # # Set justification (right, center, left) -- accepts 'L', 'C', 'R' # printer.justify('R') # printer.println("Right justified") # printer.justify('C')
#!/usr/bin/python import subprocess, sys from Adafruit_Thermal import * size = 54 base_line = 90 spacing = 16 printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5) #printer.setTimes(120000, 8400) p = subprocess.Popen(["./FontPrinter", "-c", sys.argv[1], "-s", "%d" % (size), "-b", "%d" % (base_line), "-d", "%d" % (spacing), sys.argv[2]], stdout=subprocess.PIPE) out, err = p.communicate() data = out.split(",") width = int(data.pop(0)) height = int(data.pop(0)) data = map(ord,data[0].decode("hex")) print "font: ", sys.argv[2], " c: ", sys.argv[1], " width: ", width, " height: ", height printer.printBitmap(width, height, data)
#!/usr/bin/python from Adafruit_Thermal import * printer = Adafruit_Thermal("/dev/ttyUSB0", 19200, timeout=5) printer.wake() # Call wake() before printing again, even if reset printer.setDefault() # Restore printer to defaults ## centre all text - initially small size printer.justify('C') printer.setSize('S') ## print logo bitmap import gfx.logo as logo printer.printBitmap(logo.width, logo.height, logo.data) printer.feed(2) ## first_name, suburb - small bold printer.boldOn() printer.println("Steve from Sumner said: ") printer.boldOff() printer.feed(1) ## title - large printer.setSize('L') # Set type size, accepts 'S', 'M', 'L' printer.println("Climb or sit on the most lovely tree") printer.feed(1) ## what_makes_it_awesome - normal printer.setSize('S')
#!/usr/bin/python from Adafruit_Thermal import * printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5) # Print the 75x75 pixel logo in adalogo.py import gfx.wayfinding as wayfinding printer.printBitmap(wayfinding.width, wayfinding.height, wayfinding.data) printer.sleep() # Tell printer to sleep printer.wake() # Call wake() before printing again, even if reset printer.setDefault() # Restore printer to defaults
#!/usr/bin/python from Adafruit_Thermal import * printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5) # Test inverse on & off printer.inverseOn() printer.println("Inverse ON") printer.inverseOff() # Test character double-height on & off printer.doubleHeightOn() printer.boldOn() printer.justify('L') printer.println("STUDIO-X NEW YORK") # Print the 75x75 pixel logo in adalogo.py import img as img printer.printBitmap(img.width, img.height, img.data) printer.sleep() # Tell printer to sleep printer.wake() # Call wake() before printing again, even if reset printer.setDefault() # Restore printer to defaults
class ThermalPrinter: def __init__(self, photo_data=None, image_width=0, image_height=0): self.photo_data = photo_data self.photo_width = image_width self.photo_height = image_height def generateRandomNumber(self, digits): number = "" for x in range(0, digits): number += str(random.randint(1, 9)) return number def printLine(self, line, justify='L', fontSize='S', bold=False, underline=False, feed=0): if (bold): self.printer.boldOn() if (underline): self.printer.underlineOn() self.printer.justify(justify) self.printer.setSize(fontSize) self.printer.println(line) self.printer.boldOff() self.printer.underlineOff() if (feed > 0): self.printer.feed(feed) def printReceipt(self, fee): self.printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5) self.printData(fee.age, fee.makeup, fee.pyjama, fee.hipster, fee.youngster, fee.oldie, fee.badMood, fee.aggressive) self.printer.sleep() # Tell printer to sleep self.printer.wake() # Call wake() before printing again, even if reset self.printer.setDefault() # Restore printer to defaults def formattedCurrency(self, number): if (number < 10): return " " + str(number) if (number < 100): return " " + str(number) return str(number) def printData(self, age, makeupFee, pyjamaFee, hipsterFee, youngsterFee, oldieFee, badMoodFee, aggressiveFee): #Print logo import gfx.logo as logo self.printer.printBitmap(logo.width, logo.height, logo.data) self.printLine("BRUTUS", 'C', 'L', True, False, 1) #Print photo if self.photo_data is not None: self.printer.printBitmap(self.photo_width, self.photo_height, self.photo_data) self.printer.feed(1) self.printer.setLineHeight(36) baseFee = 8 totalFee = baseFee + makeupFee + pyjamaFee + hipsterFee + youngsterFee + oldieFee + badMoodFee + aggressiveFee #Print Content self.printLine("Estimated age " + str(age), 'L', 'S', True) self.printLine( "Base Fee EUR " + self.formattedCurrency(baseFee), 'L', 'S', False, False, 1) self.printLine("Appearance Cost", 'L', 'S', True) self.printLine("No-Make-Up Fee EUR " + self.formattedCurrency(makeupFee)) self.printLine("Underdressed Fee EUR " + self.formattedCurrency(pyjamaFee)) self.printLine("Hipster Fee EUR " + self.formattedCurrency(hipsterFee)) self.printer.feed(1) self.printLine("General Cost", 'L', 'S', True) self.printLine("Youngster Fee EUR " + self.formattedCurrency(youngsterFee)) self.printLine("Oldie Fee EUR " + self.formattedCurrency(oldieFee)) self.printLine("Bad Mood Fee EUR " + self.formattedCurrency(badMoodFee)) self.printLine("Aggressive Behavior Fee EUR " + self.formattedCurrency(aggressiveFee)) self.printer.feed(1) #Print Total self.printLine( "Total EUR " + self.formattedCurrency(totalFee), 'L', 'S', True, True, 1) #Print Barcode self.printer.setBarcodeHeight(100) number = self.generateRandomNumber(13) self.printer.printBarcode(number, self.printer.EAN13) self.printer.feed(2)
# CODE39 is the most common alphanumeric barcode printer.printBarcode("ADAFRUT", printer.CODE39) printer.setBarcodeHeight(100) # Print UPC line on product barcodes printer.printBarcode("123456789123", printer.UPC_A) time.sleep(2) # These settings allow for much cleaner output when printing images printer = Adafruit_Thermal(pins=(Pin.exp_board.G14, ), heatdots=1, heattime=155, heatinterval=1) # # Print the 75x75 pixel logo in adalogo.py import adalogo printer.printBitmap(adalogo.width, adalogo.height, adalogo.data, LaaT=True) printer.println("Adafruit!") try: # # Print the 135x135 pixel QR code stored in the file on disk printer.printBitmapFromFile(135, 135, '/flash/gfx/qrcode') # TODO: figure out what's wrong here time.sleep(2) # # Print some .bmp bitmap images printer.printBMPImage('/flash/gfx/aykm.bmp') printer.printBMPImage('/flash/gfx/notbad.bmp') except OSError as e: print(e.errno) pass