ATTINY driving a small Thermal Printer via Serial Comms using only one pin.
THREE Code examples below. BARCODE. LARGE TEXT and Regular text. CHANGE the "LT" below to LESS THAN SYMBOL!
PDF Manual: crazytom.com/p/thermal/printe...
#ATTINY85
#Printer
======== BARCODE
/*
Barcode example
*/
#include "SoftwareSerial.h"
SoftwareSerial Thermal(-1, 4);
char Barcode[] = { '9', '2', '3', '0', '5', '6', '4', '8', '9', '8', '4', '1'}; // a barcode
void setup()
{
Thermal.begin(19200); // to write to our new printer
}
void loop()
{
Thermal.write(29); // The GS code cc
Thermal.write(107);
Thermal.write((byte)0x00); // you have to cast 0 in GCC/SoftwareSerial as it isn't
for (int i = 0; i LT 12; i++)
{
Thermal.write(Barcode[i]);
}
Thermal.write((byte)0x00); // terminate Barcode
delay(1000);
Thermal.write(10); // line feed
Thermal.write(10);
while(1) { };
}
======== REGULAR TEXT
/*
Minimum printer code regular text
*/
#include "SoftwareSerial.h"
SoftwareSerial Thermal(-1, 4); // only need tx
void setup() {
Thermal.begin(19200); // to write to our new printer
}
void loop(){
Thermal.println("KZitem demo");
Thermal.write(10);
Thermal.write(10);
Thermal.write(10);
while(1) { };
}
======== GIANT TEXT
/*
Big text example
*/
#include "SoftwareSerial.h"
SoftwareSerial Thermal(-1, 4);
void setup()
{
Thermal.begin(19200); // to write to our new printer
}
void loop()
{
Thermal.write(29);
Thermal.write(33);
Thermal.write(255);
Thermal.println("BIG");
Thermal.println("TEXT");
delay(1000);
Thermal.write(29);
Thermal.write(33);
Thermal.write((byte)0x00); // Don't forget to set printer back to normal
Thermal.write(10);
Thermal.write(10); // line feed
while(1) { };
}
Негізгі бет Ғылым және технология ATtiny-85 Printer - Thermal Printing
Пікірлер: 4