Serial thermal printer printing garbage

Hello there! Hope I can get some help with my printer as it prints garbage randomly (see pic below)

Thank you for the responses!

To be honest, there are a large number of sources of error.

Show the programme and the circuit diagram so that help can be provided.

3 Likes

Sorry for that paul! Here are the parts of my program that prints:

#include <Adafruit_Thermal.h>
#include <SoftwareSerial.h>
#include "NTPClient.h"
#include "ESP8266WiFi.h"
#include "WiFiUdp.h"
#include "vglogoII.h" //bitmap logo

const char *ssid = "My_Wifi";
const char *password = "********";
WiFiUDP ntpUDP;
const long utcOffsetInSeconds = 28800;
NTPClient timeClient(ntpUDP, "time.nist.gov", utcOffsetInSeconds);

void setup() {
    Serial.begin(9600);
    mySerial.begin(9600);
    WiFi.begin(ssid, password);
    while(WiFi.status() != WL_CONNECTED) {
         delay(500);
         Serial.print(".");
    }
    timeClient.begin();
    timeClient.update();
    time_t epochTime = timeClient.getEpochTime();
    struct tm *ptm = gmtime ((time_t *)&epochTime);
    int currentMonth = ptm->tm_mon+1;
    int monthDay = ptm->tm_mday;
    int currentYear = ptm->tm_year+1900;
    String date = String(currentMonth) +"-" +monthDay +"-" +currentYear +"  " + 
    String(timeClient.getFormattedTime());
    printVoucher("999569", "35.00", "7", "5", date)
}

void printVoucher(String code, String amount, String days, String change, String dateTime) {
    printer.begin();
    printer.sleep();
    delay(1000L);
    printer.wake();
    printer.println(F("\n"));
    printer.printBitmap(232, 82, VGWifi);
    printer.setSize('S');
    printer.println("");
    printer.justify('C');
    printer.setFont('C');
    printer.setSize('M');
    printer.println("Voucher Code:");
    printer.setSize('L');
    printer.println(code);
    printer.setSize('S');
    printer.println("");
    printer.setSize('M');
    printer.print("Valid for: ");
    printer.print(days);
    printer.print(" DAYS (P");
    printer.print(amount);
    printer.println(")");
    printer.boldOff();
    printer.setSize('S');
    printer.println("Thank you for purchasing!");
    printer.print(dateTime);
    printer.println("\n");
    printer.setSize('L');
    printer.println(F("\n"));
    printer.sleep();
    delay(3000L);
    printer.wake();
    printer.setDefault();
}

Thank you!

Hello

I´ve made a smal code review.

Move for a test this lines to the setup():

    printer.begin();
    printer.sleep();
    delay(1000L);
    printer.wake();

hth

Hello there again, paul. I moved this block to setup but the print out still has random characters:

Its only shows in the beginning of the print out

Hi there again paul, I removed this line:

printer.println(F("\n"));

at the beginning of the printVoucher() function, and lo and behold:

Thank you for your responses! Will get this thread updated once the garbage printout shows up again :blush:

1 Like

Have a nice day and enjoy coding in C++.

1 Like

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