Hello,
I use the code from Adafruit_Thermal library to communicate with the EM5820 thermal printer. When I use my code on an Arduino board, everything works fine. But when I use the code on DOIT Esp32 DevKit v1 board, the function call 'printer.begin();' causes the printer to print garbage characters. It prints an '8' and then 'x(' on a new line. I am using the SoftwareSerial library but even with HardwareSerial, I get the same issue. Again, this does not happen on an Arduino board. Has anyone seen this and knows how to fix it? Thanks!
/*------------------------------------------------------------------------
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.
------------------------------------------------------------------------*/
#include "EEPROMHandler.h"
#include "Adafruit_Thermal.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 16 // Arduino transmit YELLOW WIRE labeled RX on printer
#define RX_PIN 17 // 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(&Serial1); // Or Serial2, Serial3, etc.
// -----------------------------------------------------------------------
void printSomething(String webSender, String webMessage) {
// 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(9600); // Initialize SoftwareSerial
//Serial1.begin(19200); // Use this instead if using hardware serial
printer.begin(); // Init printer (same regardless of serial type)
delay(1L); // Sleep for 1 seconds
printer.wake(); // MUST wake() before printing again, even if reset
printer.setDefault(); // Restore printer to defaults
//printer.println("");
// 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.
// Font options
printer.setFont('A');
printer.boldOn();
//printer.setHeatConfig(11, 200, 40);
printer.flush();
//printer.setSize('M');
// Test inverse on & off
//printer.println ("");
printer.println("New Message From: " + webSender);
printer.println("--------------------------------");
printer.println(webMessage);
printer.println("--------------------------------");
printer.feed(4);
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
}
Garbage Characters with Thermal Printer EM5820
-
- Posts: 1
- Joined: Sun Jan 15, 2023 12:02 am
Who is online
Users browsing this forum: No registered users and 61 guests