Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: Gcode Sender with a Second Arduino to untether Computer???
SomePolish-
Guy
Newbie
Posts: 9
Permalink
Post Gcode Sender with a Second Arduino to untether Computer???
on: November 2, 2017, 17:26
Quote

Hello,
I am looking for help to free up my computer from the long print times which require it. Assuming a permanant machine setup, I beleive you only need to set the machine settings once in the beginning, meaning the rest of the magic (after "set home") is gcode.

Would it be possible to add a second arduino to send gcode from an sd card?.

I propose creating an arduino program which can do the following
1) automatically find and connect to the first available arduino serial connection on startup (I'm not sure the best connection method, would a double ended arduino cable be optimal or can they be connected with one or two pins)
2) Button1 (pinx) activates "Set Home" feature sending the appropriate information to the polargraph.
3) Button2 (piny) activates a gcode sender to pull information from an SD card and begin sending it to the polargraph.

**Additional buttons can be added such as "toggle servo position" or "return home" but I feel these first two buttons ar what is necessary.

If anyone code savvy people would take this on, or assist me by answering questions and providing direction, I would be most appreciative as I am but a novice.

Here are the concepts I am looking which may make this possible:
1) cross arduino communication: https://www.arduino.cc/en/Tutorial/MasterWriter
2) perform an action with a button: https://www.arduino.cc/en/Tutorial/Button
3) reading info from an sd card: https://www.arduino.cc/en/Tutorial/DumpFile
Wiring an sd card reader:
https://learn.adafruit.com/adafruit-micro-sd-breakout-board-card-tutorial/wiring
example of a gcode sender designed for xcarve
https://github.com/bvenneker/Arduino-GCode-Sender

sandy
Administrator
Posts: 1340
Permalink
sandy
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: November 2, 2017, 20:27
Quote

What a good idea! The second arduino is purely concerned with waiting for the "ready" message and then retrieving one command at a time from the SD card and shipping it off over the serial port.

Only thing is that it's not really pure GCode, it's a special "polargraph" command sequence. Doesn't make much difference - except the commands must be generated by the Polargraph controller.

SomePolish-
Guy
Newbie
Posts: 9
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: November 8, 2017, 16:00
Quote

Haha, so it would be sending "PCode" then 😉

Shorn
Beginner
Posts: 35
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: November 26, 2017, 14:43
Quote

To untether my laptop I have had some success using a Raspberry Pi with the Standalone command queue runner. The Pi is connected to my home network and I can SSH into it from my laptop over wifi. May be an option for you if you can't get the second Arduino working like you want.

I use my laptop for the things the Raspberry Pi isn't good for like the heavy image preprocessing, generating and optimizing the text files.

The process is basically this:
*Generate an 'image.txt' with my laptop using the Polargraph Controller.
*Run text file it through the Optimizer
*SSH into the Pi (I don't have to be in the same room which is the nice part)
*Transfer the text file into the "send py" folder
*Start the sender

I sit right next to the machine when I start the sender Image
(just in case it goes Terminator on me).

Still playing with the setup a bit and so I haven't left it to do a complete drawing yet, but so far it looks promising.

I am still not comfortable leaving it unattended, but at least I have my laptop available for other things.

If you are familiar with PuTTy, WinSCP or VNC I think just about anybody could set something like this up. I am hoping to finish it up over the holidays

-Shorn

Hardware:
*Running an Arduino Nano reflashed with an Uno bootloader
*Modified knockoff GRBL CNC shield with knockoff DRV8825 step drivers
*400mA -200 step motors set to 16x microstepping
*2mm belt with 36 tooth drive gears
*Machine set to 1500 Max speed and 5000 motor acceleration

Software:
*Stock Polargraph Controller to make command queues
*D2S version 2
*Send.py on remote Raspberry Pi

gamebox13
Newbie
Posts: 11
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: January 16, 2018, 19:50
Quote

I think it possible make through UART without any modification of working polargraph. Just need directly connect rx and tx to second arduino which can work with software UART (primary uart useful to debug from PC). Good option is LCD which show current command and answer from polargraph. And a lot buttons...

gamebox13
Newbie
Posts: 11
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: January 18, 2018, 19:23
Quote

Ok, I've tried to connect second arduino with SD and LCD, and it works!!!!Image

sandy
Administrator
Posts: 1340
Permalink
sandy
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: January 18, 2018, 21:54
Quote

Oh, ha ha! Nice work! That's a neat job - love the idea of decoupling the command readout from the movement. Updating the LCD has always been something that happens synchronously with the drawing, so it's always caused a pause.

gamebox13
Newbie
Posts: 11
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: January 19, 2018, 06:28
Quote

It works quick, but sometimes its stuck on "Basic command executed." It happens rarely and after drawing wave and receiving a lot SYNC. I dont know it freezes on polargraph or my controller skips READY command and wait next.
And i have a question - does a Ready command has a 10 symbol on end?

gamebox13
Newbie
Posts: 11
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: February 4, 2018, 09:54
Quote

I have tested it a lot and it works fine. In original Polargraph_server_a1 I change only 2 parametres:

int rebroadcastReadyInterval = 500;
boolean automaticPowerDown = false;

I'll post a code after editing it and adding comments.

Check my video:

sandy
Administrator
Posts: 1340
Permalink
sandy
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: February 4, 2018, 11:50
Quote

This is so cool gamebox!

gamebox13
Newbie
Posts: 11
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: March 1, 2018, 17:39
Quote

Sorry about delay, I was busy and forgot.
My sketch uses a simple PCD8544.h library by carlosefr (there is information how connect LCD to board) https://github.com/carlosefr/pcd8544 and SoftwareSerial.h to connect directly to RX and TX (D1 and D0) Polargraph's board.
SD connection described in sketch.

Before using this controller You need configure polargraph directly from PC through program Polargraphcontroller. Also I changed this parameters in Polargraph's original sketch:

int rebroadcastReadyInterval = 500;
boolean automaticPowerDown = false;

If your polargraph works fine with PC, you can connect it to second arduino - controller. Controller's D8 to Polargraph's TX(D0) and D9 to RX (D1). And now you must not connect Polargraph via Usb and power it by +5V and GND pins from controller which can power via USB but it not good idea. You can see debug information from controller in Serial terminal but it can reset arduino and drawing is broke.
Now you need run Proccesingcontroller software and make Queue file. After start your queue must contain 3 lines like C02.....C31.....C32
Its ok and contain pensize, speed and acceleration information.
Next step: press SET HOME.
And now you can make rendering commands as usual (load image file, select area, render pixels.... or another steps)
After rendering commands you can press RETURN TO HOME, its adds return home command after drawing.
Finally in QUEUE window press EXPORT QUEUE and save QUEUE.TXT file on your SD card (it must FAT32)
Put SD on controller slot, manually set gondola to home position and turn on power.
If SD and file OK screen show filesize (as you can see on video higher( and now you can press RUN button and it will start draw!!!

#include <SPI.h>
#include <SD.h>
#include <PCD8544.h>
#include <SoftwareSerial.h>
static PCD8544 lcd;
SoftwareSerial mySerial(8, 9); // RX, TX to polargraph 
File myFile;
char mode; //mode: 1=reading and send, 2=pause, 0=stop
char next; //flag reading next line in file
unsigned long pos; //position in file
unsigned long fsize; //filesize
unsigned long now;  //
unsigned long sec;
char rbf; //Read Byte from file
char rbs; //Read Byte  from serial
char buff[10]; //buffer 
char i;
boolean cls; //clear screen line; 
boolean SDok;

static const byte play[] = {0x7f, 0x7f, 0x3e, 0x1c, 0x08};
static const byte pause[] = {0x7f, 0x7f, 0x00, 0x7f, 0x7f};
static const byte stp[] = {0x7f, 0x7f, 0x7f, 0x7f, 0x7f};
//static const byte wait[] = {0x63, 0x75, 0x69, 0x75, 0x63};
//static const byte hom[] = {0x7c, 0x46, 0x57, 0x46, 0x7c};
//static const byte penup[] = {0x40, 0x47, 0x4e, 0x47, 0x40};
//static const byte pendown[] = {0x40, 0x5f, 0x78, 0x5f, 0x40};

//* SD card attached to SPI bus as follows:
//** MOSI - pin 11
//** MISO - pin 12
//** CLK - pin 13
//** CS - pin 10 

void setup() {
  // put your setup code here, to run once:
  // PCD8544-compatible displays may have a different resolution...
  lcd.begin(84, 48);
  lcd.setContrast(40);
  lcd.clear();
  lcd.createChar(1, play);
  lcd.createChar(2, pause);
  lcd.createChar(3, stp);
  //lcd.createChar(4, wait);
  //lcd.createChar(5, hom);
  //lcd.createChar(6, penup);
  //lcd.createChar(7, pendown);
  
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  mySerial.begin(57600);
  pinMode(10, OUTPUT);
  Serial.println(F("Init SD"));
  lcd.print(F("Init SD"));
  if (!SD.begin(10)) {
    Serial.println(F("init fail"));
    lcd.print(F("fail"));
    return;
  }
  Serial.println(F("init done."));
//open file
  myFile = SD.open("QUEUE.TXT");
  if (myFile) {
  fsize=myFile.size();
  Serial.println(fsize);
  lcd.setCursor(0, 1);
  lcd.print(F("QUEUE.TXT opened"));
  lcd.setCursor(0, 2);
  lcd.print(fsize);lcd.println(F(" bytes"));
  SDok=1;
} else {
// если файл не открылся, отображаем сообщение об ошибке:
Serial.println(F("error test.txt"));
lcd.println(F("QUEUE.TXT not found"));
}
delay(2000);
lcd.clear();
cls=1;
mode=0;
next=0;
pos=0;
}

void loop() {
  if (digitalRead(A0)) ///RUN/PAUSE button
    {
    if (mode==2) mode=10;
    if ((mode==1) && (next==0)) mode=2;
    if ((mode==0)&&(SDok==1))
      {
        mode=1;
        cls=1;
        sec=0;
      }
    if (mode==10) mode=1;
    Serial.println(F("Pressed RUN/PAUSE"));
    cls=1;
    delay(1000);
    }
  if ((digitalRead(A1)) && (next==0)) //STOP button
    {
    Serial.println(F("Pressed STOP"));  
    mode=0;
    pos=0;
    delay(1000);
    }
  /*
  if (digitalRead(A2) && (mode==0)) //HOME 
    {
    mode=3;
    cls=1;
    next=0;
    delay(1000);
    }
   */
  
if (mode==1)
  {
  if ((myFile.available())&&(next==1))
    {
    if (cls==1)
      {
      cls=0;
      lcd.setCursor(0, 2);
      lcd.clearLine();
      lcd.setCursor(0, 1);
      lcd.clearLine();
      lcd.setCursor(0, 1);
      myFile.seek(pos);
      }
     rbf=myFile.read(); 
    mySerial.write(rbf);
    lcd.write(rbf);
    Serial.print(rbf);
    if (rbf==10)
      {
        next=0;
        mySerial.listen();
        pos=myFile.position();
        cls=2;
        lcd.setCursor(0, 3);
        lcd.write(4); 
      }
    if (rbf==-1) next=0;
    
    }
  if (next==0)
    {
    rbs=mySerial.read(); //reading byte from polargraph serial
    if (rbs>-1)
      {
      //display.print(rbs);
     // Serial.print(char(rbs));
      lcd.write(rbs); 
      if (cls>0) ///clear lines on screen
        {
        cls=0;
        lcd.setCursor(0, 5);
        lcd.clearLine();
        lcd.setCursor(0, 4);
        lcd.clearLine();
        lcd.setCursor(0, 3);
        lcd.clearLine();
        lcd.setCursor(0, 3);
        }
      
      
      
      for (i=0;i<6;i++)  
        {
          buff[i]=buff[i+1];  
        }
       buff[5]=rbs;
      if ((buff[5]==char(10))&& (buff[4]==char(13))) lcd.setCursor(0, 3); //End of command 
      if (((buff[4]=='Y') && (buff[3]=='D') && (buff[2]=='A') && (buff[1]=='E') && (buff[0]='R')))   //Ready command
        {
          next=1;
          cls=2;
          Serial.print(char(10));
          if (pos==fsize) //if file is end then stop
            {
            mode=0;
            }
        }
      }
    }
  
  if (millis()>now+1000) //counting time in seconds
    {
      now=millis();
      sec=sec+1;
    }
  }
 if ((mode==0) || (mode==2))
    {
    rbs=mySerial.read();
    if (rbs>-1)
      {
      //display.print(rbs);
      if (cls>0)
        {
        cls=0;
        lcd.setCursor(0, 5);
        lcd.clearLine();
        lcd.setCursor(0, 4);
        lcd.clearLine();
        lcd.setCursor(0, 3);
        lcd.clearLine();
        lcd.setCursor(0, 3);
        }
      Serial.print(char(rbs));
      lcd.write(rbs);

      if (rbs==10) cls=1;
        }
      }
/*

if ((mode==3))
  {
  if (cls==1)
      {
      cls=0;
      lcd.setCursor(0, 5);
      lcd.clearLine();
      lcd.setCursor(0, 4);
      lcd.clearLine();
      lcd.setCursor(0, 3);
      lcd.clearLine();
      lcd.setCursor(0, 2);
      lcd.clearLine();
      lcd.setCursor(0, 1);
      lcd.clearLine();
      lcd.setCursor(0, 1);
      }
  if (next==0)
    {
      
    }
  
  }
*/

if ((cls==1)) //renew up line on screen
  {
    lcd.setCursor(0, 0); 
    //lcd.clearLine();
    if (mode==1) lcd.write(1);
    if (mode==2) lcd.write(2);
    if (mode==0) lcd.write(3);
    lcd.print(F(" ")); 
    lcd.print(100.0*pos/fsize,2);  lcd.print(F("%")); //drawing progress
    lcd.print(" "); 
    lcd.print(sec/60);  lcd.print(F("m  ")); //drawing time
    if (SDok==0) lcd.print(F("fail"));
    //if  (sec>0) lcd.print((sec*fsize/pos-sec)/60); lcd.print("m  ");  //remaining time
    //cls=1;
  }
}

EATYone
Advanced
Posts: 69
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: December 5, 2018, 20:44
Quote

Gamebox13 mega thanks.

EATYone
Advanced
Posts: 69
Permalink
Post Re: Gcode Sender with a Second Arduino to untether Computer???
on: December 7, 2018, 20:55
Quote

Simplified SD sender with a "cheap" Polargraph SD, really good results!

Image

Image

Pages: [1]
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.194 seconds.