Arduino Mb2hal question (solved)

More
26 May 2020 05:02 #168938 by Henk
Arduino Mb2hal question was created by Henk
Hi

I am working on a Wire EDM machine and i need Linuxcnc to control the water conductivity by switching a solenoid valve to divert water through a de-ionising resin filter.

I am measuring the water conductivity (EC) using this setup with an Arduino Uno.

Arduino EC meter

I want Arduino to report the EC to LCNC so that i can control the pumps and valve from one platform

I loaded Mb2hal using this info: Mb2Hal

Now my problem:

I cant find a decent source of information on how to setup the Arduino code to report a float or u32 value to LCNC. The Arduino code seems to write the input registers to the output registers but i have no idea what these registers contain or how to use them.

On the LCNC side it seems to load without issues and i can see the pins in hal. I am aware of how to change the variable types in Mb2hal, but the default code linked sets up float values so that is ok.

Any tips would be appreciated.

P.S my fallback is to use the remaining arduino pins as paralell bits and link that to inputs on my 7i76E and decode the paralell binary data to S32 in LCNC but this seems a bit stupid...:P

Please Log in or Create an account to join the conversation.

More
26 May 2020 08:10 - 26 May 2020 15:16 #168943 by tommylight
Replied by tommylight on topic Arduino Mb2hal question
Two ways you can do that:
Set arduino to output frequency depending on EC and use the 7i76 encoder to count that frequency, set encoder counter mode to 1 so it outputs just the velocity and use a comp (comparator) component in LinuxCNC to output to a pin at a preset threshold,
Use LinuxCNC components to convert u32 to float or vice versa:
linuxcnc.org/docs/2.4/html/man/man9/conv_u32_float.9.html
linuxcnc.org/docs/2.5/html/man/man9/conv_float_u32.9.html
Last edit: 26 May 2020 15:16 by tommylight. Reason: typo

Please Log in or Create an account to join the conversation.

More
26 May 2020 08:11 #168944 by bbsr_5a
Replied by bbsr_5a on topic Arduino Mb2hal question
you can use the USB and your own HAL comp to report whatever you like to the HAL

see the XHC Handheld component it reports back and forth 1000times a second

Please Log in or Create an account to join the conversation.

More
26 May 2020 14:00 #168983 by Henk
Replied by Henk on topic Arduino Mb2hal question
Thanks.
I also thought of the encoder counting option as a possibility. Will be low frequency though because I will have to use a software encoder. The 7i76e encoder is occupied already.

Would be nice to get MB2hal working though because I can then simplify a lot of wiring from the water level sensors and so on.

Please Log in or Create an account to join the conversation.

More
26 May 2020 15:09 #168988 by HeronG
Replied by HeronG on topic Arduino Mb2hal question
I just uploaded my code to github, It is what I use to send data both ways from an arduino to linuxcnc.

github.com/herongcachoeira/ComLinuxcncArduino

Hope this helps a bit.
The code was not intended to be shared so i did not bothered with comments, sorry!
The following user(s) said Thank You: Henk

Please Log in or Create an account to join the conversation.

More
27 May 2020 05:49 #169032 by Henk
Ok. I managed to solve this issue.
The serial port was incorrect.
I checked dmesg before and set the serial port in the mb2hal config correctly the first time but somehow this changed. I don't know how these are assigned and if they can change.....maybe it was just a mistake.

Anyway. It works now. Thanks for all the valued suggestions.

Henk

Please Log in or Create an account to join the conversation.

More
16 Jun 2020 17:34 #171865 by Henk
Hi.
I seem to be losing Comms between the Arduino and Linuxcnc.

The Arduino simply reports a value (float) to Linuxcnc every 5 seconds, but this fails to update after a while. Sometimes it will be ok for over an hour but other times it stops after minutes.

I can see the error count (in hal...mb2hal pins) going up rapidly when it doesn't work anymore, but other than that no error messages show up.

Quitting LCNC and disconnecting the usb cable for a second or so and starting back up again fixes the issue only to fail again.

I also noticed that the serial port changes sometimes. ACMtt0 (I think) to ACMtt1 without rebooting the pc. LCNC fails to open because of this but the Arduino was never disconnected.

Is there a way to reserve a certain usb port for the Arduino?

Any advice would be appreciated

Thanks
Henk

Please Log in or Create an account to join the conversation.

Time to create page: 0.125 seconds
Powered by Kunena Forum