Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_Thermal.h>
- /*------------------------------------------------------------------------
- Example sketch for Adafruit Thermal Printer library for Arduino.
- Demonstrates a few text styles & layouts, bitmap printing, etc.
- IMPORTANT: DECLARATIONS DIFFER FROM PRIOR VERSIONS OF THIS LIBRARY.
- This is to support newer & more board types, especially ones that don't
- support SoftwareSerial (e.g. Arduino Due). You can pass any Stream
- (e.g. Serial1) to the printer constructor. See notes below.
- You may need to edit the PRINTER_FIRMWARE value in Adafruit_Thermal.h
- to match your printer (hold feed button on powerup for test page).
- ------------------------------------------------------------------------*/
- #include "Adafruit_Thermal.h"
- #include "adalogo.h"
- #include "adaqrcode.h"
- // Here's the new syntax when using SoftwareSerial (e.g. Arduino Uno) ----
- // If using hardware serial instead, comment out or remove these lines:
- #include "SoftwareSerial.h"
- #define TX_PIN 6 // Arduino transmit YELLOW WIRE labeled RX on printer
- #define RX_PIN 5 // Arduino receive GREEN WIRE labeled TX on printer
- SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
- Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
- // Then see setup() function regarding serial & printer begin() calls.
- // Here's the syntax for hardware serial (e.g. Arduino Due) --------------
- // Un-comment the following line if using hardware serial:
- //Adafruit_Thermal printer(&mySerial); // Or Serial2, Serial3, etc.
- // -----------------------------------------------------------------------
- String inputString = ""; // a String to hold incoming data
- bool stringComplete = false; // whether the string is complete
- void setup() {
- // This line is for compatibility with the Adafruit IotP project pack,
- // which uses pin 7 as a spare grounding point. You only need this if
- // wired up the same way (w/3-pin header into pins 5/6/7):
- //pinMode(7, OUTPUT); digitalWrite(7, LOW);
- // NOTE: SOME PRINTERS NEED 9600 BAUD instead of 19200, check test page.
- mySerial.begin(19200); // Initialize SoftwareSerial
- //mySerial.begin(19200); // Use this instead if using hardware serial
- printer.begin(); // Init printer (same regardless of serial type)
- inputString.reserve(200);
- // The following calls are in setup(), but don't *need* to be. Use them
- // anywhere! They're just here so they run one time and are not printed
- // over and over (which would happen if they were in loop() instead).
- // Some functions will feed a line when called, this is normal.
- // Test inverse on & off
- //printer.inverseOn();
- //printer.println(F("Inverse ON"));
- //printer.inverseOff();
- // Test character double-height on & off
- //printer.doubleHeightOn();
- //printer.println(F("Double Height ON"));
- //printer.doubleHeightOff();
- // Set text justification (right, center, left) -- accepts 'L', 'C', 'R'
- // Test more styles
- //printer.boldOn();
- //printer.println(F("Bold text"));
- //printer.boldOff();
- //printer.underlineOn();
- //printer.println(F("Underlined text"));
- //printer.underlineOff();
- printer.setSize('L'); // Set type size, accepts 'S', 'M', 'L'
- printer.println(F("Large"));
- printer.setSize('M');
- printer.println(F("Medium"));
- printer.setSize('S');
- printer.println(F("Small"));
- // printer.justify('C');
- // printer.println(F("normal\nline\nspacing"));
- // printer.setLineHeight(50);
- // printer.println(F("Taller\nline\nspacing"));
- // printer.setLineHeight(); // Reset to default
- // printer.justify('L');
- // Barcode examples:
- // CODE39 is the most common alphanumeric barcode:
- //printer.printBarcode("ADAFRUT", CODE39);
- // printer.setBarcodeHeight(100);
- // Print UPC line on product barcodes:
- //printer.printBarcode("123456789123", UPC_A);
- // Print the 75x75 pixel logo in adalogo.h:
- //printer.printBitmap(adalogo_width, adalogo_height, adalogo_data);
- // Print the 135x135 pixel QR code in adaqrcode.h:
- //printer.printBitmap(adaqrcode_width, adaqrcode_height, adaqrcode_data);
- //printer.println(F("Adafruit!"));
- //printer.feed(2);
- //printer.sleep(); // Tell printer to sleep
- //delay(3000L); // Sleep for 3 seconds
- //printer.wake(); // MUST wake() before printing again, even if reset
- //printer.setDefault(); // Restore printer to defaults
- }
- void loop() {
- while (mySerial.available()) {
- // get the new byte:
- char inChar = (char)mySerial.read();
- // add it to the inputString:
- inputString += inChar;
- // if the incoming character is a newline, set a flag so the main loop can
- // do something about it:
- if (inChar == '\n') {
- stringComplete = true;
- printer.justify('C');
- printer.setSize('M');
- printer.println(F("Max"));
- // printer.sleep(); // Tell printer to sleep
- // delay(1000L); // Sleep for 3 seconds
- // printer.wake(); // MUST wake() before printing again, even if reset
- // printer.setDefault(); // Restore printer to defaults
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement