Collecting data with Arduino and Python
- VNR
- Offline
- Senior Member
-
- Posts: 61
- Thank you received: 7
Is the protocol between the Mesa card and the Arduino handled by firmware in the Mesa card ? If it so, could be implemented a modbus/etercath/devicenet or other protocol in the firmware ? (may be using a 7i44 not a 7i77)The Mesa 7i87 might have worked for you, plugged into the 7i77 smart-serial port.
........
I set up a UART on my Mesa card and have the Arduino talking 1Mb serial to a realtime HAL component. That was quite involved (custom Mesa firmware and changes to the Hostmot2 driver), but might also be an option.
Thanks you in advance,
VNR
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
- Posts: 23328
- Thank you received: 4949
The Mesa firmware only sends/receives 8-bit data packets. All the protocol is handled at the Arduino and HAL ends.Is the protocol between the Mesa card and the Arduino handled by firmware in the Mesa card ? If it so, could be implemented a modbus/etercath/devicenet or other protocol in the firmware
I wrote a HAL comp for the job.
So, what you propose would be possible, but might be more easily done with the userspace serial driver.
Please Log in or Create an account to join the conversation.
- PCW
-
- Away
- Moderator
-
- Posts: 18606
- Thank you received: 5120
Please Log in or Create an account to join the conversation.
- mcenter
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
Sometimes, I will use a screwdriver for a pry-bar. I always keep a Crescent wrench handy, although I have SAE and metric wrenches from very small to quite large with extra copies. The trick is realizing when you really should use a pry-bar, a box end wrench, or a gas hatchet and sledge hammer.
This is the HAL I used:
loadusr -Wn datarecord data_recorder.py
net record-flag datarecord.record <= motion.digital-out-00
net spindle-speed datarecord.sp <= motion.spindle-speed-out
net x-rel-position datarecord.xpos <= halui.axis.0.pos-relative
net y-rel-position datarecord.ypos <= halui.axis.1.pos-relative
A waitusr command would be superfluous.
Using M62 P00 followed by G1 X1 Y1 MDI commands (M62 doesn't take action until motion command), the signals change in the watch window, but datarecord pin values do not. (As seen in the attached watch window.
My Python script only writes the .csv header for the file, apparently h is never set to TRUE.
Thanks for all the input. I am still very much in the learning phase regarding linuxCNC, HAL, Python and C. I do plan to implement this as a comp later for a learning exercise. But, my summer is almost over, and I am behind schedule on my research. If I can't resolve these issues, I'll be out there with a clipboard and a stopwatch (think gas hatchet and sledge hammer).
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
- Posts: 23328
- Thank you received: 4949
Your Python code needs to set itself up, issue a hal_ready then enter a busy-loop which polls the data. Unlike realtime components userspace components are not polled by the threads.
(Or, all this could be wrong, I am not very good at reading Python)
Please Log in or Create an account to join the conversation.
- mcenter
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
I think you are pointing me in the right direction. However, the code does not complete until LinuxCNC shuts down. In other words, the file opens when LinuxCNC begins, however it is not called again until shut down.
Mark
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
-
- Posts: 24
- Thank you received: 758
What happens if you write it like this?
try:
basetime = time.time()
while 1:
delT = time.time() - basetime
if h.record == 1:
ain = pollArduino()
f.write(str( h.xpos) +","+ str(h.ypos)+','+str(ain)+','+str(h.sp)+','+str(delT)+'n')
time.sleep(1)
except (KeyboardInterrupt,):
raise SystemExit, 0
regards
Please Log in or Create an account to join the conversation.
- mcenter
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
Yes, I think l the indents were stripped. And that is terribly important in Python.
The references are similar to how Jeff Epler did it in his arduino.py script.
My Python script works when executed outside LinuxCNC in conjunction with halrun.
But, I will try it the way you suggest. I think it is less confusing.
I will try to post my script again.
Mark
Please Log in or Create an account to join the conversation.
- mcenter
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
I am having problems posting my file. Maybe it will work this time.
Mark
Please Log in or Create an account to join the conversation.
- mcenter
- Offline
- New Member
-
- Posts: 14
- Thank you received: 0
www.linuxcnc.org/index.php/english/compo...&id=342&catid=29#342
Please Log in or Create an account to join the conversation.