modifying Serial Port "Invert Logic"

I just aquired a Mega 2560 board with multi serial ports. Great right? Just one little problem for me at least. I need to be able to invert the logic of a byte sent by a LS2208 bar code scanner.

In the past I used a SoftwareSerial port assigned (10, 11, 1); it was that little "1" that was inverting the logic bits. Without it I would get nothing or trash.

Is there something like this for say Serial1 that I can add to it to make it invert the logic bits?

Thanks

Paul

Worse case I will have to go back to using a SoftwareSeril port again.

You might make a simple level shifter to convert rs232 into TTL like in the attached pix.

ezservo.jpg

I don't know the answer - and I have looked at the Atmel datasheeet which does not seem to mention it.

As it is a rather specialized question I suggest you change your title to include "invert logic". You can change the title by modifying your Original Post.

Post a link to the datasheet for your barcode scanner

...R

Shouldn't be hard to do in code.

invertedSerialWrite(byte b){
   Serial.write(~b);
}

@ Delta_G

First answer that seems to be addressing my problem. But concerned cause I dont know poo about some of this code still. I am needing to read in from the buffer the Bar Code serial data. If I am reading your code right. Your talking about transmitting or writing out data from the Mega. Am I correct?

Thanks Paul

zoomkat and Robin,

Thanks for taking a look at my thread and suggesting somethings.

Please note it works fine with the Pro Mini! It works cause of the declaration in the

SoftwareSerial scanner(8, 9, 1); //please note the number “1”. This inverts the logic levels not the voltage.

The scanner already outputs TTL not RS-232c voltage levels.

Robin thanks for the suggestion of thread title. Maybe it will catch more fish for me.

SoftwareSerial scanner(8, 9, 1); //please note the number "1". This inverts the logic levels not the voltage.

The scanner already outputs TTL not RS-232c voltage levels.

If the scanner actually outputs TTL logic at 5v, then no conversion is needed. Just insure the baud rates between the arduino and scanner are matched.

I don't think simply inverting the data byte will work. The start/stop bits are always expected to be low/high by the UART. SoftwareSerial can invert those too but I don't believe that's an option in the Atmega328 UART hardware. In a long string of continuous bytes you might be able to get away with swapping start/stop bits and inverting the data in software but this approach would fail for the first and last bytes, or if the stop bit is longer than one bit width.

Can you add a chip to invert the signal?

I don't think the suggestion in Reply #3 will solve the problem. And I had assumed you need to be able to read data with inverted logic.

I find it hard to believe that a product communicates using a "strange" system - but you have not posted the link to the datasheet that I requested.

A simple hardware solution would probably be to feed the Rx and Tx signals through an inverting chip such as a NOT or NAND gate.

...R

@Robin2

Hi Robin, As stated before the last Arduino (Pro Mini) this was working just fine after much reading and I swear I cant find the thread again. I came across this one reply showing how to set up a SoftwareSerial port with the one at the end of the pin parameters. Took off flying and reading everything just fine.

2 Days ago I wired up a Mega 2560 board and its been hell sence. The 4D Display not talking to the Mega nor is the scanner. I have double check and found a few wiring errors, but they have been corrected. I can put in code and make the #13 DIO LED blink so it is not a bricked board.

Well if worse comes to worse. I will just put back in SoftwareSerial and set up a few of those comm ports. Seems that the display and bar code scanner worked just fine on those types of ports. Heck the Mega has more than enough Digital pins that are not being used.

As for the spec sheet. Not sure what your looking for. They really dont get into what the signal is like. They sell these to go on cashregisters and inventory devices, not makers projects. When I called, ended up talking to a level 2 tech and he was of no help either.

I just remembered from that post that was so helpful. The Author said something about how the Arduino had some kind of inversion on its Digital pins. I would love to hear from more people who have the Mega 2560 boards.

Thanks for the help Paul

Are you using the hardware serial ports on the Mega? If so, did you follow the suggestion of adding a hardware inverter?

@aarg

No I have not aarg. I live out in the country (abt 60 miles to local electronics store). Will make the trip in when I go to work Tuesday.

Here is the thread I have been talking about. Note 1st paragraph from #1 replay. I say again if you read the whole post. I have a TTL cord on the LS2208.

And replay #2 is the fix.

Note that professor chaos states how the Arduino UARTs are inverted. That makes me wonder if my 4D display is inverted to match. Wondering what is going on between the SoftwareSerial and the Hardware serial ports? What kind of inputs are the two expecting?

Oh what wicket webs are woven when playing with these microprocessors.

Might take a few days but will get this working again on the Mega 2560

Sorry forgot the link. http://forum.arduino.cc/index.php?topic=21168.0 ::)

Since when are Arduino UARTs inverted? That is news to me. RS-232 is sometimes though of as inverted since -V is a 1. TTL to TTL shouldn't be a problem, just a direct connection.

aarg is correct.

I don't see a TTL serial cable available for that scanner, only RS232. Please post a link to the cable you are using.

If you are connecting a RS232 device to a TTL serial device, the inverted signal is only one of your problems. You are putting a negative voltage into the Arduino serial rx line. That may eventually cause you some problems, either on the Arduino or the scanner.

Reference guide: https://atgsupportcentral.motorolasolutions.com/content/emb/docs/manuals/MN000754A02a.pdf

NOTE This scanner uses TTL RS-232 signal levels, which interface with most system architectures. For system architectures requiring RS-232C signal levels, we offer different cables providing the TTL to RS-232C conversion. Contact support for more information.

Robin2: A simple hardware solution would probably be to feed the Rx and Tx signals through an inverting chip such as a NOT or NAND gate.

No ICs Required. An NPN and a couple of resistors [CE] - that's simple.

aarg,

I really dont know. All I do know is that the display worked just fine when on a software serial port. But now it is on a hardware port it does not work. What changed between the two ports? And I do know that the scanner did not work on software port till I added the "1" to the parameters. Can you explain that? What does the number one do?

If you dont know, thats ok, but please do not muddy the waters with wild guesses.

The same goes for all of the others who just jumping in without understanding what is going on. PLEASE NOTE I SAID IT WAS WORKING BEFORE. only change is from software serial to hardware serial. And I might have screwed up and gotten the scanner RX and TX swapped on the board. Thats something else I might have to check on the scanner. Cause it is hard wired I was going with the possibility that there was something I missed on the software side such as inverting the logic bits.

Thanks if nothing else, its been a sounding board to help me think and one good hardware fix.

Paul

The hardware UART on the Arduino is configurable for word length, parity and stop bits, but not for inverted data. I don't know if that holds for a "Mega".

Paul1958: As for the spec sheet. Not sure what your looking for. They really dont get into what the signal is like. They sell these to go on cashregisters and inventory devices, not makers projects. When I called, ended up talking to a level 2 tech and he was of no help either.

Yes, they do get into what the signal is like. TTL is not listed in the interface specs for the scanner:

"Interfaces Supported: USB, RS232, Keyboard Wedge, IBM 468x/9x"

So it probably worked for you before because you had the RS232 connected to the logic levels on the board. The "1" in softserial was necessary because RS232 levels are inverted. But it won't always work, as you have discovered, and yet you seem to be uninterested in this, even as a possibility.

Others have hinted strongly that this is your problem. Then later you accuse me of "muddying the waters". Some people just can't be helped.