Thermal printer: print bitmap from SD card

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
peek
 
Posts: 23
Joined: Sat Jan 14, 2012 6:17 am

Re: Thermal printer: print bitmap from SD card

Post by peek »

try without the while loop.

like:

Code: Select all

File dataFile = FileSystem.open(chemin, FILE_READ);    
printer.printBitmap(384, 240, dynamic_cast<Stream*>(&dataFile));
good luck!

franck_7L
 
Posts: 4
Joined: Thu Jan 16, 2014 12:00 pm

Re: Thermal printer: print bitmap from SD card

Post by franck_7L »

TY Peek,

I tried but it didn't resolve the problem, which seems to be with the file read or format ...
I've converted my file with LCD Assistant and I got this :

//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------

const unsigned char tapie [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
........................................... etc
........................................... etc
};

If I print to the console instead of the printer, this is what I get :

Image

And I don't understand if I've to use a .h file or .bin file by readind your exchanges ...

User avatar
technerdchris
 
Posts: 46
Joined: Sun Nov 25, 2012 4:08 am

Re: Thermal printer: print bitmap from SD card

Post by technerdchris »

1) A header .h file has the ascii characters to tell the C program what each byte's value is.
2) A binary .bin file has the byte vales recorded in binary in each byte's position, which could be said is like how the same numbers are stored in a program's memory.
3) Printing to the console will not behave correctly, as the console is looking for ascii values so as to display readable characters to the humans watching.
4) Printing monochrome bitmaps is where the mostly 0x00 values come in to play. That represents 8 different pixels which are not darkened.

Listed above are 4 different concepts in which 2 different communication methods are used 3, 4, or 5 different ways depending on how you split up what's going on.

I will try to explain this in the most basic way, so please do not see this as "talking down", it is my attempt to help you see each step. When I was a lab assistant for a C programming class, the biggest problem is when we as people merge these above concepts in our mind.

Let's put things in order... (easier for me to think it in reverse order)

» Thermal printer prints a monochrome bitmap.
» A bitmap is setup via the ordering of binary data (this are the 0x00 values) but with a special header in front of the image data.
» The binary data has to be output serially from the controller (Arduino, ChipKIT, computer).
» The controller's program has to buffer that data out the serial port.
» The output buffer has to get that data from somewhere.
(here are options)
----» Controller's program can READ the data from SD Card.
----» Controller's program can have the image data declared within its program.

Description of options:
» Controller's program can READ the data from SD Card:
----» Data on SD card would probably be a binary file.
----» If the binary file has the bitmap header, it could be called a bitmap file and have extension .bmp.
----» If the binary file only has the image data within, it is a binary file and by convention has extension .bin or .dat and then the controller's program needs to add a proper header before the image data before sending it to the serial port.

» Controller's program can have the image data declared within its program:
----» Our controller's programs are written in C/C++ and C likes to receive it's information from ascii characters people input via keyboards.
----» C programs in this situation get binary data via static declarations of byte arrays having values expressed in the hex format 0x00.
----» People like to put giant array declarations in header files so they don't have to page down 80 times to get to the C code they're writing.

A further complication is the limitation of Ardunio's memory. Even a Mega with its 16k of SRAM can at most store all of a 192x192 bitmap's pixels in the program's memory.

Hoping this helps,
Chris

PS - footnote about 2) at the top: this is not always exactly true when endian-ness or the byte order of how data is stored in memory is considered. Most PCs are little endian and I believe I observed the Arduino platform is big endian.

franck_7L
 
Posts: 4
Joined: Thu Jan 16, 2014 12:00 pm

Re: Thermal printer: print bitmap from SD card

Post by franck_7L »

Thank you so much for the time you've taken to write something clear.
I've red it and I'll again.
I don't have found the time to try a little bit more but this could be usefull.

franck_7L
 
Posts: 4
Joined: Thu Jan 16, 2014 12:00 pm

Re: Thermal printer: print bitmap from SD card

Post by franck_7L »

I never succeed pinting an image from sd card with stream.

Image

All details, results and bitmaps are there, dispatched in my two posts : https://groups.google.com/forum/#!topic ... ikxLxKcQeo
Is someone able to provide any help ?

User avatar
technerdchris
 
Posts: 46
Joined: Sun Nov 25, 2012 4:08 am

Re: Thermal printer: print bitmap from SD card

Post by technerdchris »

I see in the final picture that you're getting pretty close...

Now, it appears upside down, so you'll need to change the direction you send the bytes to the printer. Which probably means on your PC before you save the image to SD card, you'll need to flip it upside down. I forget which board you are using (sorry, didn't re-read), but I doubt the Arduino AVR processor has enough SRAM to do much...

And seeing how the printout looks correct but then just stops: that tells me you ran out of RAM and crashed your program. I'm not sure HOW the code reads from the SD Card, but if it is actually streaming small numbers of bytes at a time, this should be possible; which then makes me think that memory use is not well handled. Perhaps there is a problem like a buffer variable is being declared in a function and then not specifically freed from memory.

Ensure all buffers for reading from SD Card, storing image info, and sending to the printer are GLOBAL variables.

Next, there is a lot of "pointer arithmetic" happening in the code to handle things like this. If a pointer that's supposed to be pointing to one of those data buffers instead goes astray, that will cause your program to crash.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”