BCD through RS232

Hello I'm new here,

I am currently working on a project where I need to save the data I get from a Photometer using Arduino so we can graph this after.

The problem I have is that in my datasheet it states on page 5, that there is a BCD output interface using 5V TTL but the port used to connect it is of type RS232-DB9

I looked up some things about RS232 and found out that RS232 usually goes from -13v to 13v with -13V sending a 1 and 13V sending a 0.
This is where I'm a bit confused.
can I hook it up directly on my Arduino or will I still need some kind of shield?

Also I tried hooking it up using a cheap Arduino I didn't use much and ran the serial.read code.
The code is the same as the example code from Arduino.
I wired the ground and TX -> arduino RX and RX -> arduino TX.

The only data I get through is a number between 0-255 and not of BCD value?

I have a picture of the machine with the port in attachment and also the datasheet of the photometer

Thanks for the help in advance,

Kind regards.

bcdrs232.PNG

smart_systems_lmt_lichtmesstechnik_gmbh_photometers_s1000.pdf (141 KB)

bcdrs232.PNG

Then your device is working correctly. BCD means each byte that is sent consists of two 4 bit numbers, Each 4 bit pair is called a "nibble", or as the original IBM code written in England called it "nyble". Your program does not know about nibbles, so is using the entire byte as a single binary number.
Search the forum for examples of converting BCD bytes to regular 8-bit numbers so your code can use them.
Paul

Aah Thank you! nice so hooking up directly to Arduino was enough.

But The photometer sends in BCD and the Arduino converts to decimal.
1 byte is 2, 4 bit numbers and represents the 2 7-segment displays on the photometer.
What if there are 6 displays?

Can I assume the 1st byte it sends is the first 2 numbers in BCD, the 2nd byte it sends shows display 3 and 4 and the third byte represents display 5 and 6?
Im quite new at this.

This is the code I used and I only received 1 byte,
Am I right to assume the next byte I receive represents the next two digits? or do I have to use something else than a byte to read everything?

serialcode.PNG

serialcode.PNG

nubcake:
Aah Thank you! nice so hooking up directly to Arduino was enough.

But The photometer sends in BCD and the Arduino converts to decimal.
1 byte is 2, 4 bit numbers and represents the 2 7-segment displays on the photometer.
What if there are 6 displays?

Can I assume the 1st byte it sends is the first 2 numbers in BCD, the 2nd byte it sends shows display 3 and 4 and the third byte represents display 5 and 6?
Im quite new at this.

I suggest you get more information on the protocol used by the machine. Does it continuously send bytes, or are they combines into messages? How is a message identified and how do you know the end of a message? The BCD data may be imbedded in the message, but the message has special characters in the start of the message and some other special characters to tell you this is the end of the message. Look for documents relating to "protocol".
Paul

Paul_KD7HB:
I suggest you get more information on the protocol used by the machine. Does it continuously send bytes, or are they combines into messages? How is a message identified and how do you know the end of a message? The BCD data may be imbedded in the message, but the message has special characters in the start of the message and some other special characters to tell you this is the end of the message. Look for documents relating to “protocol”.
Paul

this is the only document I have been able to find from the machine itself, there was no other document explaining the BCD protocol of the machine :confused:

nubcake:
this is the only document I have been able to find from the machine itself, there was no other document explaining the BCD protocol of the machine :confused:

Comment out both of your Serial.print() and Serial.println().
Add this:

Serial.print(incomingByte, HEX);  // print as an ASCII-encoded hexadecimal

Then you can see what is really being sent and possible discover more about the messaging from the device.
Paul

Waiting for a reply.

Ah yes sorry for my absence.

For now I had a few problems with the connection because of limited tools/wires and thanks to covid it has been delayed.
Right now im awaiting some new cable/rs232 to TTL converter shield with MAX323.

But I’ve been thinking. If Arduino converts BCD values to Decimal on the serial monitor, then values like 255 should not be possible? 153 should be the maximum value representing a 9 on 1 segment and 9 on the other or 1001 1001.

On a sidenote, what should the peak voltage be when you measure it on a scope?
I sent the character “o” to the arduino serial monitor and got this

500mV seems awfully low but the signal form seems to be correct

nubcake:
Ah yes sorry for my absence.

For now I had a few problems with the connection because of limited tools/wires and thanks to covid it has been delayed.
Right now im awaiting some new cable/rs232 to TTL converter shield with MAX323.

But I've been thinking. If Arduino converts BCD values to Decimal on the serial monitor, then values like 255 should not be possible? 153 should be the maximum value representing a 9 on 1 segment and 9 on the other or 1001 1001.

On a sidenote, what should the peak voltage be when you measure it on a scope?
I sent the character "o" to the arduino serial monitor and got this

IMG-20210301-145257 — ImgBB

500mV seems awfully low but the signal form seems to be correct

The largest BCD in a single byte is 99. Anything larger than a 9 is not a BCD. So, you are correct in that. Anything you discover that is greater than 99 is likely to be some protocol indicator, like a message end or ?
Your scope shows a voltage going less than zero! What are you measuring and where?
Paul

Paul_KD7HB:
The largest BCD in a single byte is 99. Anything larger than a 9 is not a BCD. So, you are correct in that. Anything you discover that is greater than 99 is likely to be some protocol indicator, like a message end or ?
Your scope shows a voltage going less than zero! What are you measuring and where?
Paul

I made a simple sketch with
Serial.println("o"); to send a char to my serial monitor on arduino. It'll be read as ASCII and the signal output will be binary so i wanted a comparison.
I hooked it up to arduino ground and Tx pin.
It does look like a binary signal but the peak voltage is so tiny I think there's something wrong here.

nubcake:
It does look like a binary signal but the peak voltage is so tiny I think there's something wrong here.

If applicable to your scope: check that the probe attenuation on the probe matches that in the scope settings.

arduarn:
If applicable to your scope: check that the probe attenuation on the probe matches that in the scope settings.

Hello, I checked and it was indeed the probe attenuation.
The probe itself had by default x10 but the scope settings had x1
Thank you.

Hello,

I wanted to update on my progress regarding this topic.
Going back to the starting point, I hooked up everything on an oscilloscope and got the following results of a RS232 port.

RxD -> -10.4V
DSR -> 9.2V
CTS -> 8.6V
RI -> -10.4V
(all other voltage levels are 0V)

I concluded that my photometer is a DCE (Data Communications Equipment) because my RxD reads a value lower than -3V.
I also concluded that it is in an "idle-state" because the idle state of RS232 is a logic 1 or a constant negative voltage of between -3V and -12V.

The problem is, how do I get this out of the idle-state?
Do I have to perform hardware handshaking?

Kind regards.

nubcake:
Hello,

I wanted to update on my progress regarding this topic.
Going back to the starting point, I hooked up everything on an oscilloscope and got the following results of a RS232 port.

RxD -> -10.4V
DSR -> 9.2V
CTS -> 8.6V
RI -> -10.4V
(all other voltage levels are 0V)

I concluded that my photometer is a DCE (Data Communications Equipment) because my RxD reads a value lower than -3V.
I also concluded that it is in an "idle-state" because the idle state of RS232 is a logic 1 or a constant negative voltage of between -3V and -12V.

The problem is, how do I get this out of the idle-state?
Do I have to perform hardware handshaking?

Kind regards.

You don't and you don't care! The UART will do the watching and it's code will tell you when it places a byte in the buffer for you to handle. You will know this by a return value from reading the UART or Serial that is greater than 0. That number will the a count of bytes in the buffer.
In the mean time, you code can do anything else you want it to do, or just loop.
Paul
Paul

Paul_KD7HB:
You don’t and you don’t care! The UART will do the watching and it’s code will tell you when it places a byte in the buffer for you to handle. You will know this by a return value from reading the UART or Serial that is greater than 0. That number will the a count of bytes in the buffer.
In the mean time, you code can do anything else you want it to do, or just loop.
Paul
Paul

So basically, I can’t measure anything on that port until my code says so?
Im using a Seeed RS232 arduino shield to have the signal convert to 5V TTL.
since my RxD is -10.4V and my TxD is 0V, it converts to 5V to my RxD and TxD of my arduino.

 #include <SoftwareSerial.h>
 SoftwareSerial mySerial(10, 1); //232_TX,232_RX 
void setup()
{    
    // Open serial communications and wait for port to open:    
      Serial.begin(9600);    
      while (!Serial) {        ; // wait for serial port to connect. Needed for Leonardo only    }
      Serial.println("Goodnight moon!");     // set the data rate for the SoftwareSerial port    
      mySerial.begin(9600);    } 
void loop() // run over and over
{    
      if (mySerial.available())
      Serial.write(mySerial.read());}

This code should work right? but it doesn’t.
It is an example code which I modified a bit.
I can send a character using

mySerial.write("o")

This sends a 5V TTL signal from my Arduino to the board and the board converted it to RS232-signals.
But yeah, the problem still persists, I can’t read anything because my machine is in an “idle-state” and isn’t sending data at all.

Seems to me the problem is not an Arduino problem, but is a problem with your machine NOT sending data. Can you explain that a bit more. Do you have to send an inquiry to you machine before it sends data? Your Arduino can't read serial data if it's not being sent.
Paul

yeah, this seems to be the case. It is an old machine in which im trying to read data from.
Sadly I have only a datasheet explaining the machine itself but not the communication process.

This is a block diagram from the datasheet.
As you can see the analog/digital converter sends the information to the display and to the BCD interface, the port uses a RS232-protocol.
ignore the IEEE, apparently you could choose between those 2 protocols, it is not very clear tbh.
I have a download link to the datasheet on my 1st post

I've had the 'pleasure' of getting printers working with RS232 long back. At that time, they seemed to be all different, but there was often a hardware handshake required, which in the case of the printer was a way to tell the sending computer to stop transmitting for now.

You may find that you need to wire your machine so it thinks it always has permission to send. DSR to CTS perhaps, but as I recall, it was a case of experimenting to find out which pin this particular device was dependent upon. Somewhat risky behavior, but I didn't realize that at the time :slight_smile:

nubcake:
yeah, this seems to be the case. It is an old machine in which im trying to read data from.
Sadly I have only a datasheet explaining the machine itself but not the communication process.

Imgur: The magic of the Internet

This is a block diagram from the datasheet.
As you can see the analog/digital converter sends the information to the display and to the BCD interface, the port uses a RS232-protocol.
ignore the IEEE, apparently you could choose between those 2 protocols, it is not very clear tbh.
I have a download link to the datasheet on my 1st post

There is noting in the manual/document that says the machine uses RS-232 protocol.
Does you machine give proper readouts on the front panel display and is it otherwise functioning as it should?
Paul

Paul_KD7HB:
There is noting in the manual/document that says the machine uses RS-232 protocol.
Does you machine give proper readouts on the front panel display and is it otherwise functioning as it should?
Paul

yes the readings at the front is good and it works perfectly.
I know there is no information about RS232 in the datasheet but it is the same machine, I also added a picture to show the connection is of type RS232.
There are other things that doesn't add up, like how it's a BCD interface with 5V TTL, so in essence, the datasheet doesn't help me much and I need to figure this out.