Page 1 of 1

UART output

PostPosted: 02 Jun 2013, 13:02
by sblanz
Hello everybody
I'm trying to access the UART data that Output pin 7 can produce with my arduino but the reading on the serial gives strange strings under various settings.
This is low it looks like:
p����p~���p�c�p����p~���p�c�p����p~���p�c�p����p~���p�c�p����p~���p�c�p���


Looking deeper I found out that Mk2/4 UART output may need a DMA controller be read. Is this correct?
Arduino Due has a DMA controller and I'm curious to know if you think it can be useful to access to DRO output on pin7.

I've read the uart / dro displays regarding posts in the forum and at the moment I am not interested in hardware solutions different from arduinos.

can you give me a hint?
Thank you very much in advance!

Re: UART output

PostPosted: 02 Jun 2013, 23:31
by Andrej
Output is not in ascii. It is binary data.
Signal is also inverted.

Re: UART output

PostPosted: 03 Jun 2013, 08:42
by sblanz
Thanks for the quick answer.

Does this mean I need a DMA controller to extract coordinates data? I'm now oriented on getting a Teensy3 to do the job.
Can you provide any datasheet I can refer to get the coordinates out of the binary data?

thank you very much

Re: UART output

PostPosted: 04 Jun 2013, 07:17
by Andrej
You don't need DMA.

Mk2 sends this message to DRO.
6 bytes total
1: Message identifier (value 31)
2: Axis number (values 1-9). Value 0 is for RPM data.
3, 4, 5, 6: Value to be displayed on DRO

This is same for I2C and UART.
UART is prefered way. It is nonblocking and much faster. I use baud rate 460800.

For configuration:
1: Message identifier (value 21)
2: Number of axes (values 1-9). If 0x10 is added then RPM should also be displayed.
3 - 38: (9*4bytes): Steps per mm for all 9 axes
39: Units (mm or inches)
40-48: Character for axis name

Here is extract from test code:
U8 tmp[1 +4*9 +10];
tmp[0] = Settings.AxesCount;
memcpy((U8*)&tmp[1], (U8*)&Settings.AxisStepsPerMM, 4*9);
tmp[37+0] = Settings.Units;
tmp[37+1] = Settings.AxisAName;
tmp[37+2] = Settings.AxisBName;
tmp[37+3] = Settings.AxisCName;
tmp[37+4] = Settings.AxisDName;
tmp[37+5] = Settings.AxisEName;
tmp[37+6] = Settings.AxisFName;
tmp[37+7] = Settings.AxisGName;
tmp[37+8] = Settings.AxisHName;
tmp[37+9] = Settings.AxisIName;



Also take a look at "external display" project from this site:
http://blog.fxdteam.com/?page_id=53

Re: UART output

PostPosted: 05 Jun 2013, 07:08
by sblanz
this is great!
I'll be working on this

thank you very much!

Re: UART output

PostPosted: 24 May 2014, 07:34
by Math1010
Hello,
You say:
Mk2 Sends Message to this DRO.
6 total bytes
1: Message Log (value 31)
2: Axis number (values ​​1-9). Value 0 is for RPM data.
3, 4, 5, 6: Value to be displayed on DRO
I managed to read the axis positions correctly, but can not read the speed of the spindle, it still shows 0.00.
I'm sure I enabled "RPM" in the settings.
Do you have any idea ?
Thank you

Re: UART output

PostPosted: 26 May 2014, 06:50
by Andrej
Do you have encoder for measuring spindle speed connected to controller?

Re: UART output

PostPosted: 26 May 2014, 20:16
by Math1010
No, I do not have encoder to measure the speed of the spindle, but I thought the value would be the set sent by the software.
If I put an encoder on which connector should I connect to the MK2 ?

Re: UART output

PostPosted: 27 May 2014, 10:22
by Support
DRO is meant to use the Spindle speed data which is measured with encoder and not the values that are set in software. Since you don't use an encoder, spindle speed is 0.00 on DRO.

Encoder is connected at CTRL connector like MPG.

For pin description and better understanding of CTRL connector please follow this link:

http://www.planet-cnc.com/faq/mpg/

Re: UART output

PostPosted: 13 Nov 2014, 15:47
by jemzik
Hello there
I don't get how to encode last 4 byte position sent via UART
Could some one point me to the right direction . What type of magic I have to do with this 4 bytes to get right value of axis position
Thank you

Re: UART output

PostPosted: 14 Nov 2014, 08:09
by Support
UART can send three messages
first byte can be: 21, 30 or 31

1 byte = value 21 means steps per mm
2 byte = axis count,
9 integers (4*9 bytes) = SPU for all 9 axes,
1 byte = units,
9*1 byte = axis name (X, Y, ...)

1 byte = value 30 means position
2 byte = axis count (use 0x0f mask)
axis count integers(4* axis count bytes= position )
Integer = RPM

1 byte= value 31 means send position
1 byte = means Axis number
1 integer = means Axis position or RPM if axis number is 0

Re: UART output

PostPosted: 14 Nov 2014, 18:33
by jemzik
My question was how to encode position bits.
It makes no sense for me at all ( fresh noob here ;) ) . And thats why I attached the picture .
Comparing one of the packets (31:3:7:57:1:0) and value sown on DRO of the program(when all axises are still) are not the same as long as I read encodig right
With message starts with 31 value I was able to distinguish between positive and negativevalue (5th and 6th bit) but third and 4th bit which shold mean position just not what written on DRO
Thank you and sorry ( I'm definetly doing some thing wrong)

Re: UART output

PostPosted: 17 Nov 2014, 12:47
by Support
31:3 -> this means position of third axis. If 31:1 -> position of first axis...

7:57:1:0 -> these are four byte-s that you receive in HEX format. If you sum and convert these values in decimal, you get your position in form of motor steps(95). So divide this number with your SPU value and you will get your position in mm(95/SPU=...).

Re: UART output

PostPosted: 14 Dec 2014, 13:58
by Math1010
hello,
I do not understand what this means:

1 byte = value 30 means position
2 byte = axis count (use 0x0f mask)
axis count integers(4* axis count bytes= position )
Integer = RPM


I understood the structure for bytes 31 and 21, but not 30.
PS:
I am doing a DRO screen with Arduino, I would share the source when I have finished if anyone interested.

Re: UART output

PostPosted: 27 Mar 2015, 00:46
by jemzik
I'm doing the same !
Right now I'm thinking how to filter out "30" and "21" messages out from being read by arduino . Can not see any use for this two . and it seems like the "21" ( pushed every 10 seconds from MK2 ) message overflows arduinos buffer and I get crap info right after that
Any ideas?
May be I2c will be more appropriate for this task ?

Re: UART output

PostPosted: 27 Mar 2015, 14:24
by Support
You must do this by yourself when you read your data with Arduino. Discard "30" and "21" messages.

Re: UART output

PostPosted: 10 Dec 2015, 00:13
by cnc_dragon
Support wrote:If you sum and convert these values in decimal, you get your position in form of motor steps(95). So divide this number with your SPU value and you will get your position in mm(95/SPU=...).


Hi Guys,
I'm currently doing the same but I must be missing something mathematically fundamental.
I have sucessfully used my logic analyser to read the UART data on my MK2 controller.
First byte - Message identifier (0x1f) - Decimal 31
Second byte - (0x01) - Decimal 1
This indicates that I am being given the position of axis 1 (31:1) All fine so far.
However the next 4 bytes should give me the actual position of my axis when I add them up and divide by my SPU. I believe this is where I am going wrong.
In my case the numbers are (0x8A)138: (0x53)83: (0xFF)255: (0xFF)255
Therefore the decimal numbers I need to work with are,
138+83+255+255 / 500 (my steps per unit)
I presume that this mathematical equation is incorrect as it does not in any way reflect my actual software reading for any axis.
I must admit I have not been able to work out where the 95 comes in, in the above example.
Any help is appreciated ! Thanks.

Re: UART output

PostPosted: 28 Nov 2017, 03:16
by Ivan Kalpakchiev
Hi there, It is long after last post about that LCD DRO for MK2 controller, but I would like to find out if someone managed to decode the UART output using ARDUINO?

Please share the sketch because I am totally stuck with it.

Best regards and many thanks in advance for your kind cooperation, Ivan Kalpakchiev

Re: UART output

PostPosted: 28 Nov 2017, 19:30
by Ivan Kalpakchiev
Hi Guys,

I've just managed to get it done using an AARDUINO NANO.
The sketch is at the end of the post.

Here is the output:
"Axes= 4 X= 111.46875 Y= 53.28750 Z= -1.22500 A= -25.95007"

Here I have a question to the support:
@Support - The values I am receiving are machine coordinates.
Is there a way to get the OFFSET COORDINATES?

Best regards, Ivan
//------------------------------------------------------------------------
byte aRaw;
float SPU = 320.0;
byte x[4]; byte y[4]; byte z[4]; byte a[4];
long X, Y, Z, A;

void setup() {
Serial.begin(115200);
}

void loop() {
if (Serial.available() ) {
aRaw = Serial.read();
if (aRaw == 30) {
aRaw = Serial.read(); delay(5); Serial.read(); delay(5);Serial.println();
aRaw = Serial.read(); delay(5);Serial.print("Axes= "); Serial.print(aRaw);

Serial.print(" X= "); X = 0;
x[0] = Serial.read(); X = (long)x[3] << 24; delay(5);
x[1] = Serial.read(); X += (long)x[2] << 16; delay(5);
x[2] = Serial.read(); X += (long)x[1] << 8; delay(5);
x[3] = Serial.read(); X += (long)x[0]; float XX = X / SPU;
Serial.print(XX, 5); delay(5);

Serial.print(" Y= "); Y = 0;
y[0] = Serial.read(); Y = (long)y[3] << 24; delay(5);
y[1] = Serial.read(); Y += (long)y[2] << 16; delay(5);
y[2] = Serial.read(); Y += (long)y[1] << 8; delay(5);
y[3] = Serial.read(); Y += (long)y[0]; float YY = Y / SPU;
Serial.print(YY, 5); delay(5);

Serial.print(" Z= "); Z = 0;
z[0] = Serial.read(); Z = (long)z[3] << 24; delay(5);
z[1] = Serial.read(); Z += (long)z[2] << 16; delay(5);
z[2] = Serial.read(); Z += (long)z[1] << 8; delay(5);
z[3] = Serial.read(); Z += (long)z[0]; float ZZ = Z / SPU;
Serial.print(ZZ, 5); delay(5);

if (aRaw == 4) {
Serial.print(" A= "); A = 0;
a[0] = Serial.read(); A = (long)a[3] << 24; delay(5);
a[1] = Serial.read(); A += (long)a[2] << 16; delay(5);
a[2] = Serial.read(); A += (long)a[1] << 8; delay(5);
a[3] = Serial.read(); A += (long)a[0];float AA = A / 13.3333;
Serial.print(AA, 5); delay(5);
}
}
}
}
//------------------------------------------------------------------------