DNC Module for older cnc equipment

I'll start by making you all aware that I have a very rudimentary understanding of the language by which we program these modules and I ask that you bear this in mind when responding to this query.

I run a small machine shop and what I am trying to achieve with this project is to create a more convenient method of uploading programs to some of our older equipment. Currently we have serial cables running great distances and the procedure for uploading a program is to initiate a machine, walk into the office, start the transfer, then walk back to the machine and verify that everything made it. This is an incredibly cumbersome and time consuming process especially if any editing is in order.

My idea is to use an Arduino with a SD shield, XBee shield, and a LCD readout on which I will load a program and at the machine side I will use a Xbee explorer with a RS232 jack to receive the program. Ideally I will be able to save multiple programs, select a program from a list, then execute a send command to initiate an upload. To get started, however, my goal is to load a single program on the SD card and have the Arduino send said program at the push of a button. Having read multiple examples regarding the SD library that is pre-loaded with the Arduino IDE I have devised the sketch which you will find attached to this post. I am awaiting the SD shield so I haven't yet been able to test this code but I figured I'd present it to the masses in an effort to expose any obvious red flags. The code compiles though!

P.S. The programs I am uploading to the machines are .txt files

DNC_Module.ino (899 Bytes)

Post a link to the datasheet or user manual that describe the programming interface for the CNC machine.

Are you trying to upload a GCode file to the machine?

What software is currently being used to upload the program over the inconvenient wires? I ask because if that it a proprietary program it may have hand-shaking arrangements with the machine that have to be replicated.

Have you considered putting the existing PC software on a laptop and bringing the laptop to the machine that needs to be updated?

...R

A laptop would be an easy fix but I'm dealing with a shop owner who has a staunch opposition to bringing company computers onto the production floor. And... to be completely honest, the tinkerer in me is eager to do this just for $hits and giggles.

I've worked out the logistics of inserting code into the machine in that I've done enough research to find handshaking is only applied while trying to stream a program to the machine and run the program simultaneously (tape mode). For a direct upload into the machines' memory one must only match the baud rate, parity, etc... The two controls I am working with are the Fanuc 0M and Fanuc 0T.

Is the interface just straight 0/5V serial lines?
You could adapt your sketch to run on my standalone programmer. Go to the machine, connect up, select a file and press the start button.
The header for a USB/Serial adapter is there, it has Gnd/Rx/TX connection, you could use that vs the ICSP header as pictured here.
http://www.crossroadsfencing.com/BobuinoRev17/

rvaindustrial:
A laptop would be an easy fix but I'm dealing with a shop owner who has a staunch opposition to bringing company computers onto the production floor. And... to be completely honest, the tinkerer in me is eager to do this just for $hits and giggles.

If you are the only employee who knows how your "tinkering" device works, how is the shop owner going to manage when you are not there? And don't say they can revert to using the wired solution because they will quickly forget how to do that if you introduce a more convenient system.

I strongly suggest that you get the guy to agree to using a laptop or else you drop the project. Used laptops are cheap so you could easily have one dedicated to this task and if somebody stands on it or welds it to something then just get another.

...R

Don't know how well XBee works in an industrial environment but if it was me I would just bring the SD card to the machine and plop it into a reader/loader permanent to the machine.

I would start off with just making sure that you can communicate with the controls both hardware and software wise. Pretty sure you will need a converter for the rs232 signals.

This device will do no harm to any machine nor will it make any irreversible changes. I'm not doing it for the good of the shop it's simply a project I found interesting and would make my day just a tad more convenient. I wasn't posting here to ask your opinions on whether or not this is the best way to get this done, I simply wanted some insight on programming since I am a novice. So far I have been offered a sales pitch and dissuasion from the project all together, I am new to this community but these posts seem somewhat contrary to what I imagined was the purpose of the forum.

I wasn't posting here to ask your opinions on whether or not this is the best way to get this done

Step one in writing any program is to understand what the program should do. Part of that is understanding whether there are better ways to accomplish the same goal. If you are not interested in learning whether or not there is a better way, you can build the program yourself.

To do that, you still need to define exactly what the program should do, with what hardware, connected to what pins.

To get started, however, my goal is to load a single program on the SD card and have the Arduino send said program at the push of a button.

I suggested a way to do that. I'm sorry you saw it as a mere sales pitch.

I have been communicating with the machines via the xbee and the terminal on xctu. Now that I know the port settings are compatible I have more confidence that the Arduino will have no trouble talking to the equipment.

I'm sorry you saw it as a mere sales pitch.

I'm not trying to be offensive. From a hobbyists perspective I prefer to trudge through this on my own (with a little advice when necessary).

rvaindustrial:
So far I have been offered a sales pitch and dissuasion from the project all together

If you understand all the issues I don't mind helping. But there have been many ideas here for projects that really should be left in the hands of the professionals - even though a DIY version might be perfectly practicable.

Another thought (with a view to being constructive) is that if the only purpose of your system is to upload a file to a machine then a RaspberryPI might make a lot more sense than an Arduino.

...R

If i thought for a minute that I was dealing with an inherent liability I wouldn't risk my job for a measly project such as this. I'm not new to this equipment by any stretch of the imagination and at the end of the day this is just another tool in my toolbox. The worst that could possibly happen here is that this doesn't work and I'm out $20. I appreciate all of the concern but you'll have to take my word that I am a very thorough and cautious individual. To be honest I find it a bit asinine that I have to explain this to a group of random strangers on the internet but nevertheless here I am promoting my work ethic and typing entirely too much rhetoric for your 2 cents.

So... getting back to my original question. Have I made any glaring mistakes in the program I attached to the original post?

rvaindustrial:
Have I made any glaring mistakes in the program I attached to the original post?

Have you tested any of it?

The only way I know that my own programs work is by testing - often after I add a single extra line of code.

  • Can you read data from the SD Card and display it on the Serial Monitor? (or on the LCD?)
  • Then you will have to do some tests with the real machines.
  • You probably should have some code to gather and display any responses from the machines.
  • I would be very cautious about the code in loop() that uploads multiple files. Start testing with one file and no repetition.

...R

The only way I know that my own programs work is by testing - often after I add a single extra line of code.

I'd have put the dash in a different place, and added a comma:

The only way I know that my own programs work is by testing often, - sometimes after I add a single extra line of code.

PaulS:
I'd have put the dash in a different place, and added a comma:

The only way I know that my own programs work is by testing often, - sometimes after I add a single extra line of code.

Pedant :slight_smile:

But I do agree with you about the "testing often". I had supposed that would have been inferred. It was certainly implied.

...R

All of the necessary components arrived late yesterday afternoon allowing me enough time to start debugging.

My first obstacle was to have the Arduino recognize an SD card. I had a 32gb card from my daughter's goPro (I know what you are thinking, and yes, I'll buy her another because the likelihood of me rendering this card useless is ever-present) which I formatted using SDFormatter V4.0. After several attempts to recognize the card, a few hours scouring this and similar forums, and running numerous example sketches to test the efficacy of the card itself I conceded to a trip to best buy for a replacement card. Voila, the new card does the trick. I'm still in the dark as to why the other card won't cut it whereas it works as it should in every other capacity...

With that out of the way I reconsidered the library I was using, the included SD library, and decided to give the SDFat library a go. The examples included in the SDFat library were more revealing to me and given that I don't have enough experience with this subject matter I'll just fall back on personal preference and the omniscient Google as to why I made this decision. After some more reading, editing, and serial.printing I finally arrived at the sketch that you will find attached to this post. The only gremlin that remains is one stray character of unknown origin at the beginning of the serial transmission that has to be edited out at the console of the machine receiving the code. Any suggestions as to how I can revise my sketch to eliminate said gremlin are much appreciated.

#include <SdFat.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>

SdFat sd;
int sendFile = 5;
char in_char = 0;
File myFile;
File nextFile;
LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {
  Serial.begin(9600, SERIAL_7E1);
//  Serial.begin(9600);

//  while (!Serial) {
//    SysCall::yield();
//  }
  
//  Serial.println("Type any character to start");
//  while (!Serial.available()) {
//    SysCall::yield();
//  }

  if (!sd.begin(4, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }

  lcd.begin();
  lcd.backlight();
  digitalWrite(sendFile, LOW);
  lcd.print("Initializing...");
//  Serial.print("Initializing...");
  if (!sd.begin(4)) {
    lcd.println("Card Not Found");
//    Serial.println("Card Not Found");
    return;
  }
//  Serial.println("Ready");
  lcd.println("Ready");
}

void loop(){
  if (sendFile == HIGH){    
      sd.vwd()->rewind();
  while(nextFile.openNext(sd.vwd(), O_READ)){
    in_char=nextFile.read();
    while(in_char >=0){
      Serial.print(in_char);
      in_char=nextFile.read();
      }
    nextFile.close();
    }
  }
}
1 Like

I'm still in the dark as to why the other card won't cut it whereas it works as it should in every other capacity...

Is the new card also a 32 G card? Is it the same brand?

Any suggestions as to how I can revise my sketch to eliminate said gremlin are much appreciated.

The usual solution is to add a small (say 10 milliseconds) delay() right after Serial.begin().

The new card is 16gb, both Sandisk cards.

Here is an example of the gibberish I am getting at the beginning of the transmission:

. ?%
O0124 (GIB HEAD PROFILE)
(T3 D=0.5 CR=0. - ZMIN=-1.25 - FLAT END MILL)

The text in red is what I am trying to avoid. Each program needs to end and begin with a % to signal the machine to start/stop listening for text in the body of each program. I can use serial.print("%(") before this line:

while(nextFile.openNext(sd.vwd(), O_READ)){

Followed by a serial.print(")"). This encapsulates the issue and adds the % in manually so I would just need to modify my post processor to eliminate the % at the beginning of the program. This is a very sloppy way to go about though and it really doesn't sit well with me.

Any idea why the while statement is generating this output?

rvaindustrial:
Any idea why the while statement is generating this output?

A single superfluous character would not qualify as gibberish in my dictionary.

Are you actually sure that it is your WHILE line that generates it?

When I have an Arduino running and open the Serial Monitor (which restarts the Arduino) some characters from the transmission prior to the restart will be visible before the new transmission of data starts. I usually have something like

Serial.println("Program nnn starting");

as the first thing in setup()

Is it possible that what you are seeing is a character that was produced prior to the restart?

As a more general solution, what does your receiving device do if it receives an invalid message? Maybe a solution is to deliberately provoke that response and only start sending the real data after that is out of the way.

...R