GCODE Arduino Nano / RaspberryPi Pico

  arduino, arduino-nano, c++, g-code, raspberry-pi-pico

Hey there i have the following problem: i want to read the x and y coordinates from my .gcode file from my sd card. I already tried to use the example of the G-Code-Arduino-Library , but also to use different boards (Arduino Nano, RaspberryPi Pico). Here is the code i used for the Arduino Nano (same for the Raspberry Pi, but using the RP2040_SD library instead SD.h):

    #include <gcode.h>
#include <SPI.h>
#include <SD.h>

void homing();
commandscallback commands[1] = {{"g28",homing}};
gcode Commands(1,commands);

double X;
double Y;

void setup()
{
  Commands.begin();
  Serial.begin(115200);
  if (!SD.begin(10)) 
  {
    Commands.comment("Card failed");
    while (1);
  }

  File dataFile = SD.open("PxCg.ngc");

  if (dataFile) 
  {
    while (dataFile.available()) 
    {
      if(Commands.available(dataFile.read()))
      {
        double newXValue = X;
        double newYValue = Y;
        
        if(Commands.availableValue('X') != false)
          newXValue = Commands.GetValue('X');
        if(Commands.availableValue('Y') != false)
          newXValue = Commands.GetValue('Y');

        gotoLocation(newXValue,newYValue);
      }
    }
    dataFile.close();
  }
  else
  {
    Commands.comment("error opening file");
  }
}

void loop() 
{
}

void homing()
{
  // code to home machine
}

void gotoLocation(double x,double y)
{
  // code to run machine to location
  Serial.println(String(x) + "    |   " + String(y));
}

And here is a snapshot of the output of the Serial Monitor too

13:49:34.967 -> 0.00    |   0.00
13:49:35.008 -> 0.00    |   0.00
13:49:35.008 -> 0.00    |   0.00
13:49:35.008 -> 0.00    |   0.00
13:49:35.008 -> 0.00    |   0.00

Any ideas? I dont think that the wiring is the problem, becuase both, SDCardinfo and Listfiles examples work on both boards.

Source: Windows Questions C++

LEAVE A COMMENT