Big problem with Mini Thermal Receipt Printer

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

Moderators: adafruit_support_bill, adafruit

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_rick » Fri May 25, 2012 7:30 am

OK. But what happens if you put in printer.println(line), but take out SD.open, datafile.println(line), and SD.close()?
User avatar
adafruit_support_rick
 
Posts: 2881
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Fri May 25, 2012 7:42 am

Nothing change. The problem is ONLY the printer.println(line) couse it goes crazy also with the printer not connected (no digital pins connected and no GND). If I connect the printer to digital pins 8 and 9, and also common GND but drop printer.print command it works fine.
I think the problem is just in this command. I've also tried with a while cycle or putting printer.print outside the main cycle with a void printing(); function, but no way.
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_rick » Fri May 25, 2012 7:57 am

The only thing that makes sense is that you are running out of RAM. The SD library will use a lot of RAM. Please remove EVERYTHING related to SD from your sketch - the header file and everything in setup() and loop(), and try it again with the printer.
User avatar
adafruit_support_rick
 
Posts: 2881
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Fri May 25, 2012 8:16 am

Ok, I used this code:
Code: Select all
#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);

void setup() {
  Serial.begin(1200);
  printer.begin();
}

String line = "";   

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


I've also disconnected the sd shield. No way! Same problem, but I think you can see it also in the serial monitor: when I have the printer.print command active it use another way to write lines on the scree:
0XE()
0XFE()
0X20()

If you drop the printer,print command you have a good printing on the serial monitor:

kT1 27.7C Lo 27.7 Hi 27.7

kT1 27.7C Lo 27.7 Hi 27.7

kT1 27.7C Lo 27.7 Hi 27.7

kT1 27.7C Lo 27.7 Hi 27.7

kT1 27.7C Lo 27.7 Hi 27.7

kT1 27.7C Lo 27.7 Hi 27.7

Why this? I think it's just a libraries problem, I think something in Adafruit_Thermal.h or SoftwareSerial.h take crazy my code. I have tried also with an Arduino Mega 2560... same problem!
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_rick » Fri May 25, 2012 10:35 am

I've been trying to duplicate your problem, but I cannot reproduce the issue.
what version of Arduino are you using?
What versions of the libraries are you using? Are they all Adafruit libraries?

Something odd - I copied and pasted your exact code into a new sketch, but it did not compile because it did not include Wire.h.
How is it that it compiles for you without including Wire.h?
User avatar
adafruit_support_rick
 
Posts: 2881
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Fri May 25, 2012 10:57 am

How is it that it compiles for you without including Wire.h?

Good question but I don't know. Now I try with.

what version of Arduino are you using?

Arduino UNO R3, Arduino Mega 2560. IDE 1.0

What versions of the libraries are you using? Are they all Adafruit libraries?


I followed adafruit instructions:
http://www.ladyada.net/make/logshield/download.html
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby adafruit_support_rick » Fri May 25, 2012 11:28 am

when I have the printer.print command active it use another way to write lines on the scree:
0XE()
0XFE()
0X20()
This is expected. Adafruit_Thermal does this normally.

edit: There is now a new version of the library in GitHub which does not output these lines to Serial
User avatar
adafruit_support_rick
 
Posts: 2881
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Fri May 25, 2012 3:06 pm

YEAHHHHHHHHHHHH!!! Now it seems to work!!! I downloaded new version of library from the link you gave me and I also added wire.h and now it seems to be ok.
I couldn't test the printings couse I left the thermal paper in my office, but before missed even without the printer connected.
On monday I'll do a full test. Thank you so much driverblock, I really appreciated your help!
Have a good weekend, and thank you again!
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm


Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 31, 2012 8:19 am

Hi everyone, I've hard-tested the printer and it seems to work fine. I've used a 12V 800mA and it had no problems.
Is it possible to update the file date when it's saved? My files display always 01/01/2000 date.
Thank you so much
Alberto
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm


Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 31, 2012 10:08 am

Thanks for your prompt reply. Take this opportunity to congratulate you for being inserted into the top 100 brilliant companies 2012.
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 31, 2012 12:23 pm

I tried to read the AnalogLogger but I can't understand that kind of code. I think the right procedure is this:

Code: Select all
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
    DateTime now = RTC.now();

  // return date using FAT_DATE macro to format fields
  *date = FAT_DATE(now.year(), now.month(), now.day());

  // return time using FAT_TIME macro to format fields
  *time = FAT_TIME(now.hour(), now.minute(), now.second());
}


and this:

Code: Select all
SdFile::dateTimeCallback(dateTime);
  DateTime now = RTC.now();
  cout  << now << endl;


But I don't know how to integrate them on my code:

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


#define SYNC_INTERVAL 10000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
//#define redLEDpin 2
//#define greenLEDpin 3

RTC_DS1307 RTC; // define the Real Time Clock object

const int chipSelect = 10;

File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  while(1);
}

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(void)
{
  Serial.begin(1200);
  Serial.println();
  lcd.begin(20,4);
  printer.begin();
 
  //use debugging LEDs
  //pinMode(redLEDpin, OUTPUT);
  //pinMode(greenLEDpin, OUTPUT);
 
  // initialize the SD card
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
    //digitalWrite(redLEDpin, HIGH);
  }
  Serial.println("card initialized.");
 
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }
  }
 
  if (! logfile) {
    error("couldnt create file");
    //digitalWrite(redLEDpin, HIGH);
  }
 
  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin(); 
  if (!RTC.begin()) {
    logfile.println("RTC failed");
    //digitalWrite(redLEDpin, HIGH);
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
 
  logfile.println("millis,stamp,datetime,data");   
  }    //end SETUP

String line = "";

void loop(void)
{
  if (Serial.available()) {
    char inByte = Serial.read();
    switch (inByte) {
      case '\n':
        //digitalWrite(greenLEDpin, HIGH);
        lcd.setCursor(0,0);
        lcd.print(line);
        printer.println(line);
        // if the file is available, write to it:
        if (logfile){
          DateTime now;

          // log milliseconds since starting
          uint32_t m = millis();
          logfile.print(m);           // milliseconds since start
          logfile.print(", ");   

          // fetch the time
          now = RTC.now();
          // log time
          logfile.print(now.unixtime()); // seconds since 1/1/1970
          logfile.print(", ");
          logfile.print('"');
          logfile.print(now.year(), DEC);
          logfile.print("/");
          logfile.print(now.month(), DEC);
          logfile.print("/");
          logfile.print(now.day(), DEC);
          logfile.print(" ");
          logfile.print(now.hour(), DEC);
          logfile.print(":");
          logfile.print(now.minute(), DEC);
          logfile.print(":");
          logfile.print(now.second(), DEC);
          logfile.print('"');
#if ECHO_TO_SERIAL
          Serial.print(now.unixtime()); // seconds since 1/1/1970
          Serial.print(", ");
          Serial.print('"');
          Serial.print(now.year(), DEC);
          Serial.print("/");
          Serial.print(now.month(), DEC);
          Serial.print("/");
          Serial.print(now.day(), DEC);
          Serial.print(" ");
          Serial.print(now.hour(), DEC);
          Serial.print(":");
          Serial.print(now.minute(), DEC);
          Serial.print(":");
          Serial.print(now.second(), DEC);
          Serial.print('"');
#endif //ECHO_TO_SERIAL
          logfile.print(", ");   
          logfile.println(line);
        }
        Serial.println(line);      //print complete line
        line = "";                 //reset to empty string
        //digitalWrite(greeLEDpin, LOW);
        break;
      default:
        line += inByte;            //append inByte to the line String
    }
  }
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
  //digitalWrite(redLEDpin, HIGH);
  logfile.flush();
  //digitalWrite(redLEDpin, LOW);
}
9six4
 
Posts: 33
Joined: Tue May 22, 2012 12:11 pm

Re: Big problem with Mini Thermal Receipt Printer

Postby 9six4 » Thu May 31, 2012 12:27 pm

I've tried doing this:

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


#define SYNC_INTERVAL 10000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
//#define redLEDpin 2
//#define greenLEDpin 3

RTC_DS1307 RTC; // define the Real Time Clock object

const int chipSelect = 10;

File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  while(1);
}

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);

// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
    DateTime now = RTC.now();

  // return date using FAT_DATE macro to format fields
  *date = FAT_DATE(now.year(), now.month(), now.day());

  // return time using FAT_TIME macro to format fields
  *time = FAT_TIME(now.hour(), now.minute(), now.second());
}

void setup(void)
{
  Serial.begin(1200);
  Serial.println();
  lcd.begin(20,4);
  printer.begin();
 
  //use debugging LEDs
  //pinMode(redLEDpin, OUTPUT);
  //pinMode(greenLEDpin, OUTPUT);
 
  // initialize the SD card
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
    //digitalWrite(redLEDpin, HIGH);
  }
  Serial.println("card initialized.");
 
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
      SdFile::dateTimeCallback(dateTime);
      DateTime now = RTC.now();
      cout  << now << endl;
      break;  // leave the loop!
    }
  }
 
  if (! logfile) {
    error("couldnt create file");
    //digitalWrite(redLEDpin, HIGH);
  }
 
  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin(); 
  if (!RTC.begin()) {
    logfile.println("RTC failed");
    //digitalWrite(redLEDpin, HIGH);
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
 
  logfile.println("millis,stamp,datetime,data");   
  }    //end SETUP

String line = "";

void loop(void)
{
  if (Serial.available()) {
    char inByte = Serial.read();
    switch (inByte) {
      case '\n':
        //digitalWrite(greenLEDpin, HIGH);
        lcd.setCursor(0,0);
        lcd.print(line);
        printer.println(line);
        // if the file is available, write to it:
        if (logfile){
          DateTime now;

          // log milliseconds since starting
          uint32_t m = millis();
          logfile.print(m);           // milliseconds since start
          logfile.print(", ");   

          // fetch the time
          now = RTC.now();
          // log time
          logfile.print(now.unixtime()); // seconds since 1/1/1970
          logfile.print(", ");
          logfile.print('"');
          logfile.print(now.year(), DEC);
          logfile.print("/");
          logfile.print(now.month(), DEC);
          logfile.print("/");
          logfile.print(now.day(), DEC);
          logfile.print(" ");
          logfile.print(now.hour(), DEC);
          logfile.print(":");
          logfile.print(now.minute(), DEC);
          logfile.print(":");
          logfile.print(now.second(), DEC);
          logfile.print('"');
#if ECHO_TO_SERIAL
          Serial.print(now.unixtime()); // seconds since 1/1/1970
          Serial.print(", ");
          Serial.print('"');
          Serial.print(now.year(), DEC);
          Serial.print("/");
          Serial.print(now.month(), DEC);
          Serial.print("/");
          Serial.print(now.day(), DEC);
          Serial.print(" ");
          Serial.print(now.hour(), DEC);
          Serial.print(":");
          Serial.print(now.minute(), DEC);
          Serial.print(":");
          Serial.print(now.second(), DEC);
          Serial.print('"');
#endif //ECHO_TO_SERIAL
          logfile.print(", ");   
          logfile.println(line);
        }
        Serial.println(line);      //print complete line
        line = "";                 //reset to empty string
        //digitalWrite(greeLEDpin, LOW);
        break;
      default:
        line += inByte;            //append inByte to the line String
    }
  }
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
  //digitalWrite(redLEDpin, HIGH);
  logfile.flush();
  //digitalWrite(redLEDpin, LOW);
}


But it can't compile:

RS232_man_ok1.cpp: In function 'void setup()':
RS232_man_ok1:77: error: 'cout' was not declared in this scope
RS232_man_ok1:77: error: 'endl' was not declared in this scope
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 31, 2012 1:15 pm

"cout" is declared in the original code:

// Serial print stream
ArduinoOutStream cout(Serial);
User avatar
adafruit_support_bill
 
Posts: 15962
Joined: Sat Feb 07, 2009 9:11 am

PreviousNext

Return to Other Arduino products from Adafruit

Who is online

Users browsing this forum: No registered users and 2 guests

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


New Products [102]

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[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
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]