Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The EM5820 Thermal Printer with a serial interface can be easily connected to an Arduino using the SoftwareSerial library. Here's an example code to print text and a simple horizontal line using the EM5820 Thermal Printer:
- This code initializes the printer, configures the print settings, and then prints text followed by a horizontal line.
- Connect the EM5820 Thermal Printer to the Arduino as follows:
- VCC pin to 5V (or the appropriate voltage for your printer)
- GND pin to GND
- RX pin to digital pin 3 on the Arduino
- TX pin to digital pin 2 on the Arduino
- Please note that you may need to adjust the pin numbers in the code depending on the specific pins you choose to use for connecting the printer to your Arduino. Additionally, make sure that the EM5820 printer is powered by a power supply with enough current to operate properly, as the Arduino's onboard 5V regulator might not provide sufficient power.
- */
- #include <Arduino.h>
- #include <SoftwareSerial.h>
- const int printerRxPin = 2; // Connect this pin to the TX pin of the printer
- const int printerTxPin = 3; // Connect this pin to the RX pin of the printer
- SoftwareSerial printerSerial(printerRxPin, printerTxPin);
- void setup() {
- Serial.begin(9600);
- printerSerial.begin(9600);
- delay(500); // Allow time for the printer to initialize
- // Configure printer
- printerSerial.write(27); // ESC
- printerSerial.write(64); // @ - Initialize printer
- printerSerial.write(27); // ESC
- printerSerial.write(55); // 7 - Print settings
- printerSerial.write(7); // Heating dots (7 - max heat)
- printerSerial.write(100); // Print and feed time (100 * 10 microseconds)
- printerSerial.write(20); // Heating time (20 * 10 microseconds)
- // Print text
- printerSerial.print("Hello, EM5820 Thermal Printer!\n");
- // Print a horizontal line
- for (int i = 0; i < 32; i++) {
- printerSerial.write(0xFF);
- }
- printerSerial.write('\n');
- }
- void loop() {
- // Nothing to do in the loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement