Thermal printer only prints halves of lines!
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Thermal printer only prints halves of lines!
Hello! I have a mini thermal printer from adafruit, and it prints the test page perfectly, runs the sketches for it, and seems to function correctly. That is, until I give it my own string made from concatinated chars read from an sd card. Then it only prints the top half of the first line of the string, like this:
Typed out strings ("what's going on!?" In the picture) print fine, then the half of mine, and any typed strings after mine are skipped and the program ends. I'm running this off an arduino uno, and I've had problems with brownouts running the arduino and sd card from the same 5v 2A supply, so I gave them their own supplies, and this happened. Please help! I have no idea what's wrong here.- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Thermal printer only prints halves of lines!
Could you post your code and a description or drawing of your connections between it all?
Please use the code button "</>"
Please use the code button "</>"
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
I have the printer and sd card hooked up as in both the adafruit libraries' example code. My code concatenates chars from the SD card into strings terminated by an @.
Code: Select all
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#include <SD.h>
const int chipSelect = 4;
const int ledPin = 3; // the number of the LED pin
int ledState = 0; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 10; // interval at which to blink (milliseconds)
int increment = 0;
int printer_RX_Pin = 5; // This is the green wire
int printer_TX_Pin = 6; // This is the yellow wire
Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(19200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(7, OUTPUT); digitalWrite(7, LOW); // To also work w/IoTP printer
printer.begin();
//Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
//Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
//Serial.println("card initialized.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("data.txt");
int count = 0;
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
char temp = char(dataFile.read());
if(temp == '@')
{
count++;
}
}
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
//Serial.println("error opening data.txt");
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
dataFile = SD.open("data.txt");
randomSeed(analogRead(A2));
int randomJoke = random(count-1) + 1;
String tempJoke;
String realJoke;
count = 0;
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
char temp = char(dataFile.read());
if(temp == '@')
{
count++;
if(count == randomJoke)
{
realJoke = tempJoke;
}
tempJoke = "";
}
else
{
tempJoke += temp;
}
}
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
//Serial.println("error opening data.txt");
}
realJoke = String(realJoke);
printer.setSize('S');
printer.println("What's going on!?");
printer.println(realJoke);
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
if(ledState == 255) increment = -1;
else if(ledState == 0) increment = 1;
ledState += increment;
// set the LED with the ledState of the variable:
analogWrite(ledPin, ledState);
previousMillis = currentMillis;
}
}
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
Well, after no response from here, I've discovered that the test lines I was printing were only half the width of the paper, and the custom String I was trying to print was the full width. The 2A power supply that comes with the kit isn't enough to power the printer. This is very BANNED because for a power supply that comes with the printer, you'd expect it to be able to support the product it comes with. I'll have to find a bigger supply that can support it, even by itself without powering the arduino too.
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Thermal printer only prints halves of lines!
I'll let the product group know.
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Thermal printer only prints halves of lines!
that's odd - we've had the 5V 2A power supply work really well for years printing plenty of text, logos, QR codes, barcodes, etc :)Thetinkerer wrote:Well, after no response from here, I've discovered that the test lines I was printing were only half the width of the paper, and the custom String I was trying to print was the full width. The 2A power supply that comes with the kit isn't enough to power the printer. This is very BANNED because for a power supply that comes with the printer, you'd expect it to be able to support the product it comes with. I'll have to find a bigger supply that can support it, even by itself without powering the arduino too.
can you post a clear photo or diagram how you have it wired up including the printer, arduino, and 5V supply?
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
I assure you, the 3 wires needed to connect this to an arduino are directly hooked up, there's no way it's that. It prints text fine to half the width of the paper, and for the full width, the voltage dips to 0, the arduino resets, and the voltage comes back to 5v and the code starts again. With the arduino on its own separate power supply and the printer on the 2A one, the voltage dips to 2.5 instead of zero and only prints slightly more of the line, but still less than half.
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Thermal printer only prints halves of lines!
Thanks for the note, it would still be really helpful to see a photo or diagram, we're always looking to improve our kits and since this is the first we've heard of this particular brownout, any information you can give helps, thank you!!! :)
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
Will do! I'll take some pictures.
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
It's an arduino pro mini wired up to the headers of a protoshield with a microsd card and ex link connected too. I'm using the adafruit printer.println method which prints text fine until it gets to most of the width of the paper, then the voltage dips. The pro mini's power is the vin of another arduino connected to USB.
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Thermal printer only prints halves of lines!
Thanks! OK can you try noodling with this code in the library, adjusting the printDensity to be lower?
Code: Select all
// Description of print settings from page 23 of the manual:
// ESC 7 n1 n2 n3 Setting Control Parameter Command
// Decimal: 27 55 n1 n2 n3
// Set "max heating dots", "heating time", "heating interval"
// n1 = 0-255 Max printing dots, Unit (8dots), Default: 7 (64 dots)
// n2 = 3-255 Heating time, Unit (10us), Default: 80 (800us)
// n3 = 0-255 Heating interval, Unit (10us), Default: 2 (20us)
// The more max heating dots, the more peak current will cost
// when printing, the faster printing speed. The max heating
// dots is 8*(n1+1). The more heating time, the more density,
// but the slower printing speed. If heating time is too short,
// blank page may occur. The more heating interval, the more
// clear, but the slower printing speed.
writeBytes(27, 55); // Esc 7 (print settings)
writeBytes(20); // Heating dots (20=balance of darkness vs no jams)
writeBytes(heatTime); // Library default = 255 (max)
writeBytes(250); // Heat interval (500 uS = slower, but darker)
// Description of print density from page 23 of the manual:
// DC2 # n Set printing density
// Decimal: 18 35 n
// D4..D0 of n is used to set the printing density. Density is
// 50% + 5% * n(D4-D0) printing density.
// D7..D5 of n is used to set the printing break time. Break time
// is n(D7-D5)*250us.
// (Unsure of the default value for either -- not documented)
#define printDensity 14 // 120% (? can go higher, text is darker but fuzzy)
#define printBreakTime 4 // 500 uS
writeBytes(18, 35); // DC2 # (print density)
writeBytes((printBreakTime << 5) | printDensity);
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
I'll try that when I get a chance. I've also ordered a 5v 3A supply that will hopefully fix everything without changing settings.
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Thermal printer only prints halves of lines!
Thx, it will help us debug the issue much faster if its just a 'darkness' setting issue, so just post up when you have a chance to noodle!
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
Don't worry, I'll noodle plenty in about an hour :)
- TheTinkerer
- Posts: 38
- Joined: Mon Jun 17, 2013 5:41 pm
Re: Thermal printer only prints halves of lines!
Nope, I noodled the density down to 1 and it still browns out. I closed the IDE, made the change, saved it, closed it, and reopened the IDE and flashed the code each time but it still browns out. This 3A supply will fix it. If there hasn't been a brownout problem before, I think the 2A supply from my kit isn't working right.
Please be positive and constructive with your questions and comments.