Friday, April 6, 2012

The Problem and The Solution

Having some serious serial trouble here... While trying to find a solution I stumbled onto following. It's pretty informative and funny when at the end when the guy gets the solution!


Schu1212
07-08-2009, 01:46
I am trying to communicate to a serial thermal printer and I can't seem to get it to work. I can work with a serial LCD and my code works fine for that, but I'm not sure with the printer if it's my code or my circuit that is messing me up. Can I just run a ground and serial output to the printer direct wired? Or are there other components I'm missing? I'm new to serial programming and interfacing. I understand the concept of the programming, but I am not familiar with the actual connections.
I am using a 40x2 and
hsersetup b9600_8,%010
hserout 0,($1b,$40)
$1b,$40 is what the printer company told me was initialize the printer.

If anyone can help I would really appreciate it.

Thanks,
Jim
papaof2
07-08-2009, 03:17
Which printer are you using (serial thermal is a broad definition)?

Are you running the 40X2 at 8MHz? The baud setting you have puts out 9600 baud IF the chip is running at 8 MHz.

1. What serial voltages does the printer need? Standard RS232 would have signal levels of +/- 12 volts. but the PICAXE serial signal levels are 0 volts and 5 volts. If the printer needs +/- 12 volts, you must add a MAX232 chip to convert the +5/0 from the PICAXE to the +/- 12 the printer needs.

2. What serial protocol does the printer need? 7/8 data bits? 1/2 stop bits? Baud rate options?

John
Schu1212
07-08-2009, 03:43
I am using an ICT GP-58
Yes I am running the picaxe at 8MHz.
I match up on the protocols, 9600,n,8,1

I am not sure about the serial voltage though, I didn't realize that part. I will have to find out and see if that could be the problem. Thanks for the info, it at least gives me a direction to go. I was spinning my wheels on this one. I'll let you know how it goes.
lanternfish
07-08-2009, 04:45
I am using an ICT GP-58
Yes I am running the picaxe at 8MHz.
I match up on the protocols, 9600,n,8,1

I am not sure about the serial voltage though, I didn't realize that part. I will have to find out and see if that could be the problem. Thanks for the info, it at least gives me a direction to go. I was spinning my wheels on this one. I'll let you know how it goes.

You are all good to use standard PICAXE serial voltages (pg 7 of the manual for the printer).

If you do not have the manual download it from this link: www.ict-america.com/pdffiles/GP58CR.DOC

A bit of othe info in th emanual that mat help
westaust55
07-08-2009, 06:02
The manual indicates RS232C (page 13) and that the signal is TTL level (page 7) so it could be +5/-5V not +5V/0V that the PICAXE delivers.


cannot see anything specifically wrong with your few lines of code from what you mention

You might also need to invert the signal.

If the PICAXE is running at 8MHz you can also use:
SEROUT pinX, N9600_8, ($1b,$40)

change the N to a T for non inverted (True) logic level (See PICAXE manual 2 page 173)


Also, the hardware DIP switch 2 seemingly must be OFF for GR-58CR-Mode. The RS-232 is used by GP-58CR mode.
Schu1212
07-08-2009, 19:56
I still am not having any luck. I talked with the manufacturer and the tech support is new to the serial capabilities of the printer so they aren't able to give me much info. For some reason I can't help but think I have the circuit hooked up wrong. I even tried hooking it up using one of the cables supplied with the printer which has an HIN232 chip in it. I am trying inverted and true levels of communicating and neither seems to be doing anything for me. I am not sure if there are start and end of line commands I need to include in my string of serial data or not. I'm pretty much taking stabs in the dark right now. I even tried switching the way I am communicating with the printer by trying different pins on my picaxe. I tried sertxd, serout, and hserout all with no luck. I am sending a command to initialize the printer, and then I am just trying to do a simple line feed. If anyone has any suggestions I am not sure what direction to go in next. Here is the exact program I am downloading and after that are the command codes I got from the printer manufacturer, in case that will help anyone with suggestions.

With this code I believe I am initializing the printer and doing a pause just to make sure the printer has time to initialize and then do a line feed.

main:
SEROUT b.7,n9600_8,($1b,$40)
pause 2000
SEROUT b.7, n9600_8, (lf,lf)
goto main

here is the command set from ICT
Command table
HEX ASCII Description
$00 NUL Prints in small characters
$01 SOH Prints in double width
$02 STX Prints in double height
$03 ETX Expanded printing
$0A LF Forward feeds one line
(n)$0B VT Forward feeds (n) line
$0D CR Prints line buffer
$0E SO Prints in double width
$0F SI Set CRLF mode
$14 DC4 Cancel 0xE command.
$18 CAN Cancel print data
$1B $40 ESC @ Initialize the printer
$1B $49 ESC I Selects Font A
(dd)$1B $4D (dd) ESC M Writes value(dd) in print mode
$1B $4E ESC N Sets normal mode printing
$1B $51 ESC Q Enable underline.
$1B $68 ESC h Select Font B
$1B $6D ESC m Transmits print mode in serial
$1B $71 ESC q Disable underline.
$1B $F0 ESC {} Transmission of printer real time clock
$1B $F1 ESC {} Setting of printer real time clock
Technical
07-08-2009, 20:42
Some printers do not actual output anything until a form feed ($0C) is sent - ie all the data is internally buffered until formfeed is received, at that point the page is printed.
Schu1212
08-08-2009, 00:07
I have tried several different variations of commands and still nothing. I know the picaxe is sending the data because I can reprogram the same outputs and hook up my LCD and it works fine. The printer is also good, I can hook it up to the programming software and print test pages from my computer. The download cable, WEL-R079 is used to plug in to the computer and the software can configure it this way. I tried hooking my picaxe up as if it were the computer, I hooked my serial output pin B.7 to pin 2 of the DB 9 connector. If you take the cable apart, inside the DB9 shell is the HIN232 chip and circuitry. So the DB9 pins are the input to the HIN232 circuit, shouldn't this work? I am having fun trying to figure this out. I haven't worked on things like this in years. It's frustrating but I know I can do it. I appreciate everyone's comments. Since I posted I have tried a few new things based on replies and still no luck. I'm not sure where to look next for the problem.
hippy
08-08-2009, 00:40
If the HIN232 ( I'm assuming a variant of MAX232 ) can handle 5V signals you should be able to just connect your B.7 output to the 9-way D. Are you sure it goes to Pin 2 and not to Pin 3 ? Be careful not to connect printer output ( if there is any ) to the PICAXE output. PICAXE 0V should go to Pin 5.

You could take a line off pin 2 ( plus 0V ) and take that to a PC serial input port ( Pn 2 / 3 - you'll have to check ) and use a terminal emulator to see exactly what is being sent.

Also note what Technical said in post #7. If this is a 'pen plotter' ( maybe a different printer ) it could well be buffering data until it decides to print.
Schu1212
08-08-2009, 02:37
Thanks for the info Hippy, when you asked about pin 2 or 3 that made me wonder. I thought I used pin 2, but now I'm not sure. I will have to check tomorrow. I had to be torn away from my project, haha, until tomorrow anyway. By the way Hippy, you are correct, the HIN232 is a variation of the MAX232. I am also going to try using hyperterminal or something similar to see if I can troubleshoot it that way also.
But why with some serial circuitry there is reference to using a resistor inline with the serial line and sometimes the use of a transistor. I haven't seen much reference to those components but I have seen some. I tried search for alot of different things to see if I could find my answer before I posted but I wasn't having any luck finding the answers I needed. Thanks again and I'm back at it tomorrow, have a good night.
westaust55
08-08-2009, 02:55
At the printer CN2 connector (without the HI232 based cable),
pin 1 is ground (0V), and pin 3 is the RXD2 – Input, TTL Level.

Using the WEL-079 cable there will be a signal inversion with the RS232 chipset.
Should be standard DB9 RS232 connections at the WEL-079 cable. But the WEL-079 cable may required +/-12V signal levels.

Have you tried with PICAXE direct to CN2?
0V from picaxe supply to CN2 pin 1
serial out pin (b.7) to CN2 pin 3. Could put a 1kOhm resistor in series as a safeguard until proven.
hippy
08-08-2009, 09:35
But why with some serial circuitry there is reference to using a resistor inline with the serial line and sometimes the use of a transistor.

Transistors may be used to invert the active polarity of a signal but that can be done in software with the PICAXE by using Nxxxx or Txxxx baud rates.

Inline resistors are suggested to prevent one damage when output accidentally gets connected to another output. It limits the current so the output pin drivers don't melt and destroy the chip. Because of null modem cables and the like, it is possible to accidentally connect two serial outputs together rather than an output into an input.
Schu1212
11-08-2009, 21:36
I am still stuck. I got more information from the manufacturer, they told me I should be able to direct connect my circuit gnd to pin 5 of the DB9 connector and my output b.7 to the receive line of the printer, pin 3. The manufacturer told me pin 2 is the host Rx and printer Tx and pin 3 is the host Tx and printer Rx. I've tried different variations of the command set I was sent and I still am not having any luck and I am confused. I know it is probably something simple I am missing or doing wrong. Here is what I believe the code should look like. All I would like to do is get this thing to acknowledge I am communicating with it and I can play with the rest of it later. With the following code I was simply trying to get the word 'hello' to print.

pause 1000 'pause on power up to let printer initialize
main:
serout b.7,t9600_8,($1b,$40) 'initialize printer
serout b.7,t9600_8,($1b,$6d) 'transmits print mode in serial
serout b.7,t9600_8,($0f) 'CRLF mode (I assume this means ending each line with CRLF)
pause 1000
SEROUT b.7, t9600_8, ($1b,$4e,"hello",$1b,$4d,cr,lf) 'set normal print mode,print hello?
goto main

anyone have any idea's what I may be doing wrong? I tried contacting the manufacturer about what order to send ascII commands to the printer and they haven't gotten back to me yet. The manufacturer said it shouldn't be a problem making this work, unless the problem is me, hahaha. Anyway, I could use some help if anyone has any ideas. Thanks.
Technical
11-08-2009, 23:00
Have you actually tried connecting

picaxe - max232 - pin 3 of DB9

yet?

As others have already suggested if it is an RS232C system the 0/5V signal from a PICAXE may not be sufficient to drive the chip (inside the cable) and so nothing will ever work with your DB9 hardware setup - you will need a max232/max202 style chip to amplify the voltages.

An AXE091 experimenter board has this type of circuit on the board.
Technical
11-08-2009, 23:18
Looking at here:
http://www.slotsdirect.com/manuals/ictprinter.pdf

You need to make these 4 connections direct (forget about the DB9 cable as it just complicates things):

PICAXE serout output pin - CN2-3
PICAXE 0V - CN2-1
+12V - CN1-1
0V - CN1-2

Then use a N9600_8 baud rate.

You could use the 5V output, CN2-6, to power the PICAXE if you wanted to.
Schu1212
12-08-2009, 02:21
I am almost right back where I started. I'm not sure what is throwing me a loop but what technical just explained about the 4 connections is exactly how I started. But at that time there may have been other factors messing me up. I'm going to start there because I was told by the manufacturer that this will work with the 5V level so I don't need the max232 chip. I will try wiring it back up and tinker a little more. I even double checked again today to make sure the printer is working. The printer comes with a programming cable and software that is serial and I can go in there and print a test page still. I will get back to everyone after I get a chance to work on this again. I hope I'm not being a pest, but i really appreciate how much input I am getting. I will keep my eyes open for times when I can return the favor. thanks again!
Technical
12-08-2009, 10:58
You don't need the max232 if you connect direct to the board. You will need the max232 if you connect via the DB9 cable. It depends on how you connect to the board!
vttom
12-08-2009, 15:05
According to this documentation...

http://www.ict-america.com/pdffiles/GP58CR.DOC

You're best bet is to connect the PICAXE directly to the RJ45 connector named "CN2".

The document above gives the following pinout for CN2:

1. GND
2. TXD2 – Output, TTL Level.
3. RXD2 – Input, TTL Level.
4. PROGRAM
5. /RESET
6. VCC – +5V DC
7. RXD1–Input, TTL Level.
8. TXD1 – Output, TTL Level

So, you would connect pin 1 of CN2 to the same GND that the PICAXE is connected to. You would also connect your PICAXE output pin to pin 3 (or pin 7?) of CN2. If you use pin 3, then ground pin 7 or vice-versa.

The documentation doesn't say anything about what to do with pins 4 or 5. From the names, it sounds like you want to tie pin 4 to GND and pin 5 to VDD.

The remaining pins can probably be left unconnected.
Technical
12-08-2009, 15:13
The documentation doesn't say anything about what to do with pins 4 or 5. From the names, it sounds like you want to tie pin 4 to GND and pin 5 to VDD.

Not required - have a look at the pinout of the serial cable - it leaves these two pins unconnected (only 4 wires connected).
vttom
12-08-2009, 15:25
Here's another thought...

You may need to do some reverse-engineering. Basically, take the DB9 cable they give you, tap into the RX pin that goes to the printer, and connect that to the RX pin of a second serial port on your computer.

After that, run a terminal emulator on the PC and set it to listen to the 2nd serial port while you "drive" the printer from the commercial software.

You may need to get special terminal software to let you see the non-printable character codes (you can probably find something for free with a little Googling).
Schu1212
18-08-2009, 20:06
I had to go out of town for a little while for work so I wasn't able to work on my little project with the printer until last night. I got more information from the manufacturer and they informed me of the connections I need to make to communicate with the printer. On the CN2 connection on the printer pin 1 is my circuit ground, and pin 3 is printer Rx. So I hooked my serial output to pin 3 and connected the ground to my picaxe circuit and I used the following program to experiment.

hsersetup b9600_8,%010
pause 3000
main:
pause 500
hserout 0,("hello",cr)
pause 2000
goto main

I got some response from the printer with this wiring and program, but it still isn't right. The response I get from the printer is sometimes a continuous roll feed where I have to actually disconnect the power to make the paper stop feeding out of it. Sometimes a few characters will print, then it will line feed a little bit and print a few characters, then line feed, then continuous line feed where I have to shut the power off again. I have tried several variations of the code. I tried inverted and non-inverted, I tried a couple different baud rates, I also tried different timing with the pauses. This exact code is all that would get any reaction from the printer. In fact, if I change the word hello to anything else or reduce the word to less than 3 characters I get nothing. Any time I changed the code or baud rate I got nothing from the printer and a few times sent it in to an error state. The characters that would print when I did get it to print were not even close to what I was trying to print either. For the above code the only characters I would get to print were random n,j,T,@,>,5,/,u/q,% and never in any repeatable pattern that I could see. It wouldn't even print every time I tried using the same code. turn the power on one time and get one thing, turn it on and off and get something else. At least I know I'm communicating with the printer now. But does anyone have any idea why it still isn't recognizing my commands? Is there something I can ask the manufacturer for that I am missing?
Andrew Cowan
18-08-2009, 20:27
Maybe it needs some sort of code to say 'print this'?

Has the manufacturer told you what baud rate to use?

A
Schu1212
19-08-2009, 07:36
I am new to the commands for printers and the distributor in the U.S. isn't very knowledgeable about the programming side of serial communications for their printer. So I am still waiting on an answer on whether or not I need a certain string of commands to start or stop a line or whatever.
The manufacturer did tell me their printers are 9600 baud, but after talking to someone who has used these printers before, he said he has come across some that had lower default baud rates. So every time I try something I try it at 4800 and 2400 baud also but nothing ever gets any type of response from the printer unless it's at 9600. But the problem I have when I'm at 9600 sounds like a baud rate problem according to a few people I have consulted.
hippy
19-08-2009, 09:04
In post #16 you say, "The printer comes with a programming cable and software that is serial and I can go in there and print a test page still"; does that still work ?

If it does, you can feed the serial output which should go to the printer into another serial port and run a terminal emulator to capture the serial and analyse the data to see exactly what is being sent ( as suggested in post #9 ).

If it is a baud rate issue, you can connect an external resonator and add an appropriate SETFREQ comand which will make the baud rates spot-on.

In Post#1, you say, "$1b,$40 is what the printer company told me was initialize the printer" - You aren't sending that.

Have you read the manual which lanternfish identified in post #4 ?
Schu1212
19-08-2009, 19:55
Yes I can still hook up the programming software and print a test page. I guess I will look in to hooking it up and seeing if I can capture what is being sent to the printer.

I did read the manual, and I have been in contact with the company in california a few times a week. They informed me that this printer has not always had serial functionality and it is only a few months old on this product. So the tech support is not very familiar with how it works or how to program it. The manufacturer is over in Taiwan and unfortunately they have been having weather issue's so they are working with me slowly but they are helping a little. Taiwan is who sent over the exact hook ups and how to convert the programming cable to a cable I can use directly if I wanted. But instead of modifying the cable I just snipped the ends off and used the wires directly.

The initialize printer command I found out is more of a printer 'reset' it brings the printer to an initial power up state and is generally used to clear printer errors. That is what I was told anyway, so i have not been sending that. I was sending that in my first attempts, but after I was told it was a reset I stopped sending it. When I have a chance today I am going to try a few more things and I will keep everyone posted.
Schu1212
09-09-2009, 06:56
well, it took me a while, but I finally got this printer working with a picaxe controller!! I ended up finding out that the baud rate is 2400, not 9600 like I was told by the manufacturer. Once I got that part figured out the rest was smooth sailing. Thanks again everyone for all the help and tips while I was working on this thing. Now I can get this project finished up and move on to another one.

No comments:

Post a Comment