Hello,
I have the following Omron encoder counter, which has its own communication frames and commands. I've done Serial communication before, but I'm not sure where to start on this one. I would like to just get a echo first. Then I just want to read the values displayed on the Omron encoder counter.
The link to the communications manual is the following.
I have a TTL to RS232 converter.
Is it just as simple as
Serial.Write(startframe/commandframe/etc)?
Let me know any other information that might be important to get started. I will start tomorrow, and wanted to see if anyone has had experience with this.
Yes, it is just that simple. BUT!!!!! Read the documentation you linked to. The default communication is 7 bit ASCII with even parity at 9600bps.
So, the easiest way to translate the ASCII text you write is to use a translation table to convert to even parity and make up a buffer using the even parity characters.
A good exercise for you to program.
Paul
And convert the reply to 8 bit ASCII using a similar table.
Yes, that would be easier, but will it actually ADD and REMOVE the high order bit from each byte? Don't know and can't try it. I doubt it will do that.
Paul
The document includes a echo test command, and I want to test this out to check connection between arduino and omron encoder counter.
The attached snippet shows the segment of the manual with the echo test function.
Now, from my arduino, do I simply do:
Serial.write("0801H'20");
Or do I have to split the frames up into bits and pieces.
Serial.write(08);
Serial.write(01);
Serial.write(H'20);
I feel like I am missing a crucial piece of knowledge here, since the 08 and 01 are supposed to be ASCII but H'20 is Hex?
On a slightly off topic note, I have a question about ground wiring.
Omron counter meter is powered off of 110VAC and provides a terminal for signal ground.
Arduino is powered off of USB via PC.
The RS232 level converter has a signal ground wire on the omron encoder side. Does this signal ground wire ground to the arduino, or the omron counter?
RS-232 is bipolar, + and - for the bits of each character sent/received. They are always referenced to signal ground. So both signal grounds MUST be connected together. Three wires, TX, RX, and signal ground.
Paul
So far, I have no luck finding a response from the omron counter.
The following is what I have wrote so far. Serial is hard for me because I have no clue how to debug, where the problem is.
//Serial communication between omron encoder counter and arduino unit.
//Used to compare the inputted value to the pulled value on the omron encoder counter, to reach desired position with accuracy.
//Compoway/F
void setup() {
// put your setup code here, to run once:
Serial.begin(9600,SERIAL_8E2);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.write(0x30);//0
Serial.write(0x38);//8
Serial.write(0x30);//0
Serial.write(0x31);//1 0801 is the starting bits, so I included those there, then the data, just a simple number 3 to echo back.
Serial.write(0x33);//3
while(!Serial.available()){//wait for data in serial
delay(1);
}
Serial.println(Serial.read(),DEC);//print out data in serial, I don't receive anything.
delay(100);
}
I don't get anything out, I don't think I have my Rx and Tx mixed up. Not too sure where to go from here. After tons of research online, I can't wrap my head around this problem.
Will hustle at it again tomorrow.
Thank you,
Kota Ozawa
You can't use Serial for both a terminal program and the counter. If you want to display data from the counter on e.g. Serial Monitor, you will need a board with an independent UART like a Leonardo, a Micro or a Mega and use Serial1 for communication with the counter.
// Edit
Alternative to this is the use of Software Serial for communication with the counter.
You must comply with the Compoway/F protocol which means every frame begins with STX,Node No.,Sub Address and Service ID the frame ends with ETX and checksum. In the middle is the FINS mini text which forms the body of the frame.
Your echo back test is not a complete frame it is the FINS mini text which should be enclosed within the start and end of a frame.
e.g.
STX - Node - Sub Address - SID - FINS mini txt - ETX - BCC
STX and ETX have the values of 2 and 3 respectively.
The data between STX and ETX are entered as ASCII values
BCC is derived by bcc xor value(x) where value(x) is the numeric value of each ASCII character and finally the value of ETX
I also came across a paper that may or may not be relevant to your instrument and it gave the menu structure which contained a page (Level 6 menu) with access to changing communication parameters. It may be possible to go from 7E2 to 8N1 if desired. here is the link. http://www.chlingkong.com/PDFManualEN/k3hb-v_inst-6431999-4h.pdf
Hello,
I've checked on the oscilloscope. From my knowledge, each bit should be 104us apart at 9600 baud rate.
Oscilloscope shows 104us between bit shifts across Tx and Signal ground of the counter side of the converter.
I've tried the following Serial3 communication on an arduino mega.
//Serial communication between omron encoder counter and arduino unit.
//Used to compare the inputted value to the pulled value on the omron encoder counter, to reach desired position with accuracy.
//Compoway/F
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial3.begin(9600,SERIAL_7E2);
}
void loop() {
// put your main code here, to run repeatedly:
while(!Serial3.available()){//wait for data in serial
Serial3.write(0);//0
Serial3.write(8);//8
Serial3.write(0);//0
Serial3.write(1);//1 0801 is the starting bits, so I included those there, then the data, just a simple number 3 to echo back.
Serial3.write(0);//
Serial3.write(0);
delay(1);
}
Serial.println(Serial3.read(),DEC);//print out data in serial, I don't receive anything.
delay(100);
}
Still get nothing back. I debugged, and know I'm stuck waiting for a signal from Serial3(counter).
I think my method of sending over the commands are not right. I will try to look at the receiving end on the arduino, and see if there is anything being sent over.
I am shocked that you have NOT been using your scope the entire time we have been wasting trying to see if your Arduino is sending or receiving.
Run the trace at a slower speed to actually see the entire transmission on the screen.
Paul