I’m trying to get the Adafruit thermal printer working, I’ve had success with printing text, but want the ability to print images.
This is the printer
I found some arduino code online, and was trying to migrate some of that code, but without any luck.
I’m stuck on the part of the code that actually writes the pixels to the printer. The line that starts “PRINTER_PRINT” is the arduino line I’m trying to convert, and the line below is my version of it, but instead of outputting a byte, it outputs ALL my data, with a incrementally increasing byte added to the end.
I know this part is wrong, but I don’t know how to solve it.
`
// Mini Printer
server.log(“Printer Started”);
// Hardware Configuration
local serial = hardware.uart57;
serial.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS);
local imageArray = “0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F,0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F,0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F,0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F,0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F,0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F,0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F,0x1F, 0x3D, 0xA8, 0x7E, 0x7E, 0xA8, 0x3D, 0x1F”;
local function writeImage(w,h,imageArray){
local rowStart;
local i;
local chunkHeight;
if (w > 384) {return;} // maximum width of the printer
for (rowStart=0; rowStart < h; rowStart += 256) {
chunkHeight = ((h - rowStart) > 255) ? 255 : (h - rowStart);
serial.write(18); //used to tell the printer what to expect (I think)
serial.write(42); //same here
serial.write(chunkHeight); //passing height
serial.write(w/8); // passing width
for (i=0; i<((w/8)chunkHeight); i++) {
//PRINTER_PRINT(pgm_read_byte(bitmap + (rowStart(w/8)) + i)); // <-- taken from the arduino code
//serial.write(imageArray + (rowStart*(w/8)) + i); // <-- this isn’t right
}
}
}
writeImage(16,16,imageArray);
imp.configure(“Printer”, [], []);
`
I can print a 16 x 16 block of pixels by sequentially writing the bytes in my “image”, but they are random, and have no resemblance to what I’m trying to print.
Thanks for the help!