Garbage Characters with EM5820, esp32 and Adafruit_Thermal

Hello,

I am using a EB5820 Thermal Printer with the Adafruit_Thermal library. When running the example from Adafruit on an Arduino board, everything works fine. When I'm running it on doit esp32 devkit v1 board, the function call 'printer.begin()' causes the printer to print garbage characters. It prints '8' and then on a new line it prints 'x('. I have tried using HardwareSerial instead of SoftwareSerial, but it makes no difference. Has anyone dealt with this before? Thanks :slight_smile:

Edit: The printer works correctly. It's just that it prints the '8' and then 'x(' on a new line when 'printer.begin()' is executed. If I comment out that call, I don't see the garbage characters but I'm unable to use all printer functionalities such as inverse printing, temp setup etc.

/*------------------------------------------------------------------------
  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
}

what arduino board did it work with? upload a schematic of the wiring
upload a schematic of the ESP32 wiring
the ESP32 uses 3.3V logic which would be a problem if the device uses 5V logic - you would require a level shifter
upload the code using code tags </>, e.g.. click the </> and paste your code in the highlighted area

Help us help you.

1 Like

Hey stojanbacev, did you solve this issue? I have a EM5820 printer with the same issue.
Thanks

Hello,

I have changed the printer since but I think the problem was the order of initializing the printer. I would suggest using:

HardwareSerial mySerial(1);
Adafruit_Thermal printer(&mySerial);

void printerSetup(void){
  printer.begin();
  Serial.begin(BAUDRATE); 
  mySerial.begin(BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);  // must be 8N1 mode
}

Please let me know if this fixes it for you :slight_smile:

Thanks,
Stojan

Hi Stojanbacev,
I am new to arduino. I tried to use your code but it returns an error for HardwareSerial:

Compilation error: no matching function for call to 'HardwareSerial::HardwareSerial(int)'

I am using Arduino UNO with the printer EM5820

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.