Big problem with Mini Thermal Receipt Printer

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Wed May 23, 2012 10:14 am

Hi to everyone,
I've a big problem with Mini Thermal Receipt Printer.
I compiled this program:

Code: Select all
#include <LiquidCrystal.h>
#include "SoftwareSerial.h"
#include "Adafruit_Thermal.h"

int printer_RX_Pin = 8;  // this is the green wire
int printer_TX_Pin = 9;  // this is the yellow wire

Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  lcd.begin(20,4);
  Serial.begin(1200);
  printer.begin();
}

void loop() {
 
  if (Serial.available()) {
    char inByte = Serial.read();
    switch (inByte) {
    case '\n':
      lcd.setCursor(0,0);
      //printer.println();
      break;
    case 'L':
      lcd.setCursor(0,1);
      lcd.write("L");
      //printer.println();
      //printer.print("L");
      break;
    case 'H':
      lcd.setCursor(0,2);
      lcd.write("H");
      //printer.println();
      //printer.print("H");
      break;
    case '\r':
      break;
    default:
      Serial.write(inByte);
      lcd.write(inByte);
      printer.write(inByte);
      }
  }
}


It works for few seconds after that it starts to print (both on LCD and printer) strange things.
If I delet last row (printer.write(inByte);) everything works fine.
Without that row this is what I see on serial monitor:
kT1 23.5 Hi 24.6 Lo 22.6
kT1 23.5 Hi 24.6 Lo 22.6
kT1 23.4 Hi 24.6 Lo 22.6
kT1 23.5 Hi 24.6 Lo 22.6

When I use that row this is what I see on my serial monitor (see attached image) and this is what I see on LCD:
kT1 266C
Lo .266 ..
i 26. 5

I use Arduino UNO with 1.0 IDE.
How can I solve it? I've also tried to put printer.write(); in other points of the sketch, but no way. Thank to anyone who can help me,
Alberto
Attachments
Immagine.JPG
Immagine.JPG (51.79 KiB) Viewed 1460 times
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_bill » Wed May 23, 2012 11:28 am

Looks like you are overrunning the serial buffer and dropping characters.

Instead of printing each character to both devices as it is read, you should try reading in a whole line and printing the whole buffer at once.
User avatar
adafruit_support_bill
 
Posts: 16061
Joined: Sat Feb 07, 2009 9:11 am

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Wed May 23, 2012 11:48 am

I should read a 32 characters string and after that print it, right?
My problem is how to make the string before print it :D
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_bill » Wed May 23, 2012 1:16 pm

Create an array of characters (at least one character longer than the longest line you expect).
Read the characters as you do now, but instead of printing them out, just stick them in the array.
When you get to the end of the line ('\n'), add a null ('\0') to the end of the string, then print it out.
Reset all your indexes and start again.
User avatar
adafruit_support_bill
 
Posts: 16061
Joined: Sat Feb 07, 2009 9:11 am

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_rick » Wed May 23, 2012 1:56 pm

You can also use the String object:
Code: Select all
String line = "";

void loop() {
 
  if (Serial.available()) {
    char inByte = Serial.read();
    switch (inByte) {
    case '\n':
      lcd.setCursor(0,0);
      printer.println(line);     //print complete line
      line = "";                       //reset to empty string
      break;
    case 'L':
      lcd.setCursor(0,1);
      lcd.write("L");
      //printer.println();
      //printer.print("L");
      break;
    case 'H':
      lcd.setCursor(0,2);
      lcd.write("H");
      //printer.println();
      //printer.print("H");
      break;
    case '\r':
      break;
    default:
      Serial.write(inByte);
      line += inByte;                         //append inByte to the line String
      //lcd.write(inByte);
      //printer.write(inByte);
      }
  }
}
User avatar
adafruit_support_rick
 
Posts: 2905
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Wed May 23, 2012 3:53 pm

Thank you so much driverblock, I've modified and posted you on my other topic, tomorrow I will try to print developing this sketch. Now in Italy it's 11P.M. :)
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 24, 2012 2:45 am

Good morning,
I started from zero again and wrote a program making a string before print the data like driverblock's advice.
This is the sketch:

Code: Select all
#include <SoftwareSerial.h>

#include <Adafruit_Thermal.h>

//#include <LiquidCrystal.h>

//LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int printer_RX_Pin = 8;  // this is the green wire
int printer_TX_Pin = 9;  // this is the yellow wire

Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);

void setup() {
  Serial.begin(1200);
  //lcd.begin(20,4);
  printer.begin();
}

String line = "";   

void loop() {
  if (Serial.available()) {
    char inByte = Serial.read();
    switch (inByte) {
    case '\n':
      Serial.println(line);     //print complete line
      //lcd.setCursor(0,0);
      //lcd.print(line);
      printer.println(line);
      line = "";        //reset to empty string
      break;
    default:
      line += inByte;                         //append inByte to the line String
    }
  }
}


I've tried with both LCD and printer together but after few printings the data starts pointing wrong. I attach the printer receipt so you can see. As you can see it missed some data (you can check inside the circle), after that it wrong the pointing on the paper. Same thing on the LCD. As you can see I used to point the cursor at (0,0), but after the error it seems not to follow this instruction and it point wherever it wants. I've tried both solutions: LCD+printer and printer alone... same problem! If I use only the LCD it works fine!
How can I do, for me this is a big problem! :(
Attachments
DSC00060.JPG
DSC00060.JPG (210.48 KiB) Viewed 1412 times
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_rick » Thu May 24, 2012 9:20 am

How are you powering this system? Another user recently reported that he was having printer problems when he was running off of USB power alone. His problems went away when he switched to external power.
User avatar
adafruit_support_rick
 
Posts: 2905
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 24, 2012 9:42 am

I'm powering it with a 12V 800mA AC-DC adapter. I can try using a power supply if you want. I can give it 9V 2A like is written on the specs
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_bill » Thu May 24, 2012 10:09 am

The heater in the printhead needs a lot of current. Your 800mA supply is probably dropping out under the load. You should have better results with a 9v/ 2A supply.
User avatar
adafruit_support_bill
 
Posts: 16061
Joined: Sat Feb 07, 2009 9:11 am

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 24, 2012 10:30 am

I've tried with a stabilized power supply, 9V 2A... no way same problem. After a few readings it starts to became crazy.
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_rick » Thu May 24, 2012 11:06 am

From your picture, it looks like the the printer loses the last 2 or 3 characters on a line. That suggests a timing problem. How often is the serial data coming in? I'm just curious about what would happen if you put in a delay(xxx) right after you call printer.println(line);
Maybe try it with delay(200) and see what happens?
User avatar
adafruit_support_rick
 
Posts: 2905
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_bill » Thu May 24, 2012 11:12 am

To determine if it is a problem with the printer, or with dropping characters on the read, try the following:
Code: Select all
    String line = "kT1 23.5 Hi 24.6 Lo 22.6\n";   

    void loop()
    {
          printer.println(line);
    }


If it still misprints, then it is a printer problem. If not, then it is most likely a dropped character on the serial line.
User avatar
adafruit_support_bill
 
Posts: 16061
Joined: Sat Feb 07, 2009 9:11 am

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 24, 2012 12:10 pm

How often is the serial data coming in?


Once every second.

Now I'll try to do the tests you adviced me. I'll give you results asap.
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_bill » Thu May 24, 2012 12:30 pm

Actually, looking at the library, there is no flow-control so that test will likely overrun the printer buffer. If you add a "delay(500)" after each print line it should be able to handle it. That is about twice as fast as your 1-second updates, to it should be a good test.
User avatar
adafruit_support_bill
 
Posts: 16061
Joined: Sat Feb 07, 2009 9:11 am

Next

Return to Other Arduino products from Adafruit

Who is online

Users browsing this forum: No registered users and 3 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]