Printing through ATMega

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey there. I'm pretty new to this forum so take it easy on this first one :p

I have a recent project that would benefit alot if i could send characters via TX to a printer (zebra style) and therefore, print them on paper.

Have any of you guys saw something like that or think that it's possible and how?

Thanks!

This topic has a solution.
Last Edited: Fri. Mar 9, 2018 - 09:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You would need the printers command set. And then you write your code and implement the printers commands to facilitate printing via the usart. Although most printers these days use usb not serial

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum.

 

The real question, before answering your question, is what printer?

 

Most printers these days have a USB, (or wireless), interface.  So for a newbie printing to them is a non-trivial project by itself.

 

Many old printers had a Centronics (parallel) interface, and one can use a micro to print to them, but not by using the USART and the Tx data pin.

 

Some old printers had an RS-232 (serial) interface, and YES, one could hook the micro chip up to an RS-232 driver chip and send data to the printer.

 

But, it is rather unlikely that that is your actual setup.

 

The easier way to do this is to have your micro "print" to a PC running a Terminal Emulator program, (TeraTerm, RealTerm, HyperTerminal, etc.).  Then you can see the output on the PC display.  Most of these terminal emulator programs also have the ability to log the incoming data and to print out the log, (using the printer attached to the PC).

 

So, the question becomes how to attach the micro's TxData pin to the PC?

As most PCs have USB interfaces these days, and not an RS-232 serial interface, you have to convert the micro's USART (serial) data to a USB format.

 

You can do that with a Serial (TTL, logic level) to USB cable, (eBay), for a couple of bucks.

Plug one end into the PC and fire up the terminal emulator.

Plug the wires on the other end into Ground, TxData, and RxData.

 

You can also use a serial to USB converter chip, which can be purchased as an already wired breakout board.

 

Or you can use other approaches.

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Firstly, thanks for the awesome and fast reply!

 

But imagine that the printer has bluetooth or wi-fi, wouldn't I be able (with a bluetooth/wi-fi module attached to the micro) to send commands directly to the printer? Or that's not gonna work at all?

Also, the printer i was seeking is something similar to this one (https://www.logiscenter.pt/zt23042-t0e200fz?gclid=CjwKCAiA_ojVBRAlEiwAOLRxI4-sxjg57R-pX4YowKLEUmXEb9cljzKlBoLTRn6lZ2wIDSWBLxIV9RoCtrwQAvD_BwE)

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've done something like this a few years ago, where our sensor would print periodic values to a label printer as a hard copy log.

What do you want to print, text, graphics, or bar codes???

 

In our case it was a simple RS-232 interface, we used a transistor to invert the data and level shift it.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just want to print some text, like a serial number. Some graphics would be good for the future, but i'm sticking to the basics right now

The printer i'm keen to use does have RS-232, and it's also a label printer. (idk if you're familiar with the Zebra printers)

 

How did you printed the values? Is it a specific command to send through Tx just like AT commands?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to link standard C/C++ string functions to a USART varies with the toolchain used, state what compiler your using and an expert freak will pipe in with the details.

Note AVR's have limited ram, so graphics can be tricky, text is easy.

I'm familiar with zebra and other label printers, some can take serial TTL input which minimizes the hardware needed to interface.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The printer i'm keen to use does have RS-232

So, today is your lucky day! (Maybe...)

 

You didn't say the micro you are using, or whether your board already has an RS-232 output.

 

If you are using a micro, then it's USART will output serial data at logic voltage levels, (e.g. 0V and 5V).

 

The printer uses RS-232, which is typically +/- 12 V, and has an inverted phase, (i.e. +5 V logic level gives - 12V RS-232 level).

 

To connect the micro's 5V  serial to the RS-232 of the printer you use a Max232 chip, (or equivalent...).

 

That takes care of the hardware part of the project.

 

If you are lucky, you can just send ASCII text to the printer, and CR LF for a carriage return, line feed.

The printer will happily, dumbly, print out your alpha-numeric text in its default font.

 

If you are unlucky, you will have to send the printer a bunch of control codes to put it in dumb printer mode.

 

If you are really unlucky, the printer uses a complex interface that isn't trivial to implement on a small micro.

 

I'd hook up the hardware and output some sample text and see if the printer just prints it.

 

The printer's manual says there are front panel interface commands to set up the baud rate, etc.

 

The manual didn't say what the data format for the RS-232 input was.

 

Finally, know that some Max232 chips use 0.1 uF caps, some use 1.0 uF caps, and some use 0.33 uF caps.

So make sure you use the correct caps, placed with the correct polarity, for the specific chip you use.

 

You might also find a pre-built breakout board for TTL to RS-232 to make this easier, depending upon your hardware experience.

 

JC

 

Last Edited: Fri. Mar 9, 2018 - 07:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ThisIsJohny wrote:
(idk if you're familiar with the Zebra printers)

Zebras world headquarters is two towns over from me, and I have used their products quite extensively in a former life.  Thats why I suggested you get the printer codes.(hint hint)

 

What model Printer do you want to use?

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

The printer i'm keen to use does have RS-232

So, today is your lucky day! (Maybe...)

 

You didn't say the micro you are using, or whether your board already has an RS-232 output.

 

If you are using a micro, then it's USART will output serial data at logic voltage levels, (e.g. 0V and 5V).

 

The printer uses RS-232, which is typically +/- 12 V, and has an inverted phase, (i.e. +5 V logic level gives - 12V RS-232 level).

 

To connect the micro's 5V  serial to the RS-232 of the printer you use a Max232 chip, (or equivalent...).

 

That takes care of the hardware part of the project.

 

If you are lucky, you can just send ASCII text to the printer, and CR LF for a carriage return, line feed.

The printer will happily, dumbly, print out your alpha-numeric text in its default font.

 

If you are unlucky, you will have to send the printer a bunch of control codes to put it in dumb printer mode.

 

If you are really unlucky, the printer uses a complex interface that isn't trivial to implement on a small micro.

 

I'd hook up the hardware and output some sample text and see if the printer just prints it.

 

The printer's manual says there are front panel interface commands to set up the baud rate, etc.

 

The manual didn't say what the data format for the RS-232 input was.

 

Finally, know that some Max232 chips use 0.1 uF caps, some use 1.0 uF caps, and some use 0.33 uF caps.

So make sure you use the correct caps, placed with the correct polarity, for the specific chip you use.

 

You might also find a pre-built breakout board for TTL to RS-232 to make this easier, depending upon your hardware experience.

 

JC

 

 

I think you solved the question really. Fingers crossed that the printer just be as dumb as you expect laugh

jgmdesign wrote:

ThisIsJohny wrote:
(idk if you're familiar with the Zebra printers)

Zebras world headquarters is two towns over from me, and I have used their products quite extensively in a former life.  Thats why I suggested you get the printer codes.(hint hint)

 

What model Printer do you want to use?

 

JIm

 

That isn't defined yet, but it would be probably the one i posted the link above

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.adafruit.com/product...

 

Above is a simple printer that prints on adding machine paper strips.

You can use it to prototype what you need.  It will not print labels if that is the goal.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

https://www.adafruit.com/product...

 

Above is a simple printer that prints on adding machine paper strips.

You can use it to prototype what you need.  It will not print labels if that is the goal.

 

Jim

 

 

I have seen that tutorial and it quite helped, but that's quite different from label printers

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

ThisIsJohny wrote:
That isn't defined yet, but it would be probably the one i posted the link above

 

Ok, I guess I am going to have to spoon feed a little....

 

jgmdesign wrote:
Thats why I suggested you get the printer codes.(hint hint)

 

If you do a search of the printer you mention above you get to here:

 

https://www.zebra.com/us/en/supp...

 

At the bottom of the page there are PROGRAMMING manuals with the codes the printer uses to print.  THATS what I meant about writing your AVR code to spit those out the USART to the printer.

 

If you do a Google search for "Zebra printer command codes"  There is a list of many programmers reference guides to the Zebra printers.  THere are also example code example programs out there to show you how to do basic printing before you try and go exotic.

 

Since the model you want to use has a serial port, then you only need a MAX232 driver to interface between the AVR and the printer, and you are good to go.  Now all you have to do is get the programmers manual and write your AVR code and you are all set smiley

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Fri. Mar 9, 2018 - 10:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PROGRAMMING manuals

Well that's a little light reading, (only 1522 pages long surprise )

 

Luckily you only have to get to ~ P. 572 to get to the SGD Printer Commands Overview!

 

Weekend project!

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

PROGRAMMING manuals

Well that's a little light reading, (only 1522 pages long surprise )

 

Luckily you only have to get to ~ P. 572 to get to the SGD Printer Commands Overview!

 

Weekend project!

 

JC 

 

Yeah that printer is not as dumb as the OP hopes.  But in reality it actually is not that bad.  maybe a dozen or so commands and the rest is ascii print.

 

My HINT HINT was for the OP to simply RTM and see what they are getting into first.

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well that's a little light reading, (only 1522 pages long)

I hope he isn't doing all this to print the manual  laugh

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Having written a Zebra printer driver in the past: It's not hard at all, but you absolutely need the documentation for the printer. I suggest that you read up on it and do some coding on a desktop first to get code that produces the data you want.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Imagine if the printer I want to use doesn't have an RS-232 serial, but only have USB. Could i just place an rs232-to-usb converter and send serial commands anyway (still using the max232), or that's definitly not gonna work? laugh

 

My superiors just mailed me saying i have to use a Brother QL-560 instead of that Zebra one (sad face). Since it only has a usb cable, i was thinking in the solution above. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Probably will not work as the printer and the USB/232 adapter are not host devices and as such will not link to each other.  One needs to be a host, the other an end device.

 

If only it was that simple though...

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Sun. Mar 11, 2018 - 02:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ThisIsJohny wrote:

My superiors just mailed me saying i have to use a Brother QL-560 instead of that Zebra one (sad face). Since it only has a usb cable, i was thinking in the solution above. 

 

... then Jim said...

Probably will not work as the printer and the USB/232 adapter are not host devices and as such will not link to each other.  One needs to be a host, the other an end device.

 

... so maybe your "superiors" aren't. cheeky

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ThisIsJohny wrote:
i was thinking in the solution above. 

 

Heres a suggestion that might make your life, and ours easier....

 

Sit your superiors down and ask them to write out a detailed plan of what they want to do and with exactly what equipment.  You then determine the best course of action to make this happen.  They probably wont go for the logical approach to problem solving bet hey, it's worth a shot

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's actually a good advice tho.

 

The hardware Is at my choice (except for the printer, that's a Brother), so I may consider switching a micro-controller to a Raspberry Pi (or similar). For what I've researched, Pi's can communicate directly to a printer if I install the drivers. 

 

But I really feel that it takes the fun out of this project to be honest. But hey, if it works It ain't stupid i guess frown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The obvious question to ask is what is the printer being used for?

 

If it is on a network that is all Windows based, with multiple people using it for printing large, pre-existing data base files, (labels, or whatever), then it clearly makes sense to stick with a Windows based solution.

 

If the desired data set to print is Linux friendly, and the users understand the OS, then an RPi might be a reasonable choice.

 

I still recall my first laser printer, many years ago, was a Brother Printer that was astronomically expensive at the time.

I selected it because it also understood the HP Plotter Language, and I used that for many years to publish calendar schedules for the ER, as well as for some engineering work.

It made it easy to print nice boxes for the calendar, multiple fonts, flow charts, and exact sized PCB layouts, etc.

 

JC

 

Edit: Typo

Last Edited: Sun. Mar 11, 2018 - 11:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The printer is for the micro-controller ONLY.

 

Whenever i want to, the micro sends some data to be printed (letters only). The info will come from a PLC( S7-1200 ) plugged to the micro by an RJ45 (https://www.ebay.com/itm/ENC28J60-Ethernet-Board-Stand-Alone-Controller-LAN-SPI-serial-interface-Module-/281301658688)

 

So, after the answers you guys gave me, from what i've understood, It is only possible to send commands to the printer from a microcontroller only if it has a rs-232 .. That's a wrap, but i guess it kinda makes sense.

 

If it has USB, isn't not a way to make the microcontroller the "master" and the printer the "slave" ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some microcontrollers have usb host feature. Since you want ethernet as well, maybe something like an Atmel sam4 device is more suitable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just out of curiosity, what AVR were you planning on using for this task?

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm gonna check it out, thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ONLY avr i've worked so far are the ATmega family (i know i'm a complete newbie, but i'm still in college)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which Mega then....good grief :(

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ATmega 8 / 16 / 88 / 324 / 8535