Read the analog input from Arduino

More
02 Apr 2021 13:35 - 02 Apr 2021 13:39 #204499 by elisa
Hello to all,

I have a 5 DOF robotic arm with a photoresistance on the end effector. The photoresistance is connected to an Arduino analog pin, eg. A0, while the robotic arm is controlled with Mesa cards. My aim is to send the analog value read from the Arduino A0 analog pin to LinuxCNC and save the current junction angles in case this value drops below 100.

Searching the internet, I discovered that I can read the analog value in LinuxCNC from the Arduino serial port with a python code, which I have attached here. Then, I wrote a .hal file where the value read in the python code is connected to an analog pin, motion.analog-in-00.

Then, I wrote a gcode where with the command M66 E0 L0 the value stored in the analog pin should be read and saved in the parameter #5399.

So if it works, when the subroutine is called, the M66 command reads the value stored in motion.analog-in-00 and saves it repeatedly in parameter # 5399, until this value drops below 100. In that case, the current joint angles are stored with the command "(LOG, ...)".

I have attached all the files here: the python code (my_arduino.py), the arduino sketch (arduino_sketch.txt), the hal file (my_costum.hal) and an example of gcode (my_gcode.ngc)

I would like to know if what I have done until now is correct or, in case of errors, I would like to have some suggestions.


Please write soon!
Attachments:
Last edit: 02 Apr 2021 13:39 by elisa.

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

More
02 Apr 2021 23:33 #204576 by andypugh
What you are doing sounds a lot like probing. Perhaps G38 would work better, as that is a way for LinuxCNC to continually sample an input while moving, and automatically stop and save the position.

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

More
03 Apr 2021 06:46 #204593 by elisa
Yes I agree. However, I would not like to use a probe to avoid contact with the object. Consequently, I thought about using this sensor.

Do you think what I've done so far can work?

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

More
03 Apr 2021 10:21 #204607 by andypugh

Yes I agree. However, I would not like to use a probe to avoid contact with the object. Consequently, I thought about using this sensor.


You can use the sensor as a probe. My suggestion was to connect the sensor output to motion.probe-in and then use a G38.x cycle to find the object.

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

Time to create page: 0.117 seconds
Powered by Kunena Forum