Communicating with printer


#1

So we’ve got a Factory BlinkUp Box (https://electricimp.com/docs/manufacturing/factoryblinkupbox/) and a Brother label printer (http://www.amazon.co.uk/dp/B008RXS4P0/ref=pe_385721_126915741_TE_item).

I’ve never worked with UART so I imagine the error is my end. I’ve read the manual (http://download.brother.com/welcome/docp000706/cv_ql720_eng_escp_100.pdf) and have come up with the follow squirrel code, however the printer always just prints out a blank label.

Any ideas where I have gone wrong.

`
// Hardware Configuration
serial <- hardware.uart1289;
serial.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS);

// Select ESC/P mode
serial.write(0x1B);
serial.write(0x69);
serial.write(0x61);
serial.write(0x00);

// Initialise ESC/P mode
serial.write(0x1B);
serial.write(0x40);

// Format Settings

// Landscape
serial.write(0x1B);
serial.write(0x69);
serial.write(0x4C);
serial.write(0x01);

// Page Length 2inches
serial.write(0x1B);
serial.write(0x28);
serial.write(0x43);
serial.write(0x02);
serial.write(0x00);
serial.write(0x10);
serial.write(0x02);

// Horizontal Space
serial.write(0x1B);
serial.write(0x24);
serial.write(0x96);
serial.write(0x00);

// Vertical Space
serial.write(0x1B);
serial.write(0x28);
serial.write(0x56);
serial.write(0x02);
serial.write(0x00);
serial.write(0xFC);
serial.write(0x00);

// Font Type
serial.write(0x1B);
serial.write(0x6B);
serial.write(0x0B);

// Character Size
serial.write(0x1B);
serial.write(0x58);
serial.write(0x00);
serial.write(0x32);
serial.write(0x00);

// Text

serial.write(0x41);
serial.write(0x74);

// Print
serial.write(0x0C);

`


#2

We have some example code internally, I’ll see if we can get it posted.

One note though, you don’t need to write each byte individually, you can write as strings eg:

`// Select ESC/P mode
serial.write("\\x1B\\x69\\x61\\x00");
`

…which is a bit more readable.

It’s possible that you need a short delay after configuring the UART so the printer clears any break errors. I’ve not looked at the codes you’re sending, but try adding an imp.sleep(0.1); after the uart.configure.


#3

You can now find the code we have been developing on electric imp’s github -


#4

Yes spot on it was because I wasn’t sleeping after config.

Great thanks for the code. I’ll work on 2D Barcode support and submit a pull request.


#5

Not formally live yet, but here’s an article I’ve just finished on QR code printing. Won’t help @jdelaune - different codes, different printer - but other may find it useful: https://electricimp.com/docs/resources/qrcodeprinter/