Welcome! Log In Create A New Profile

Advanced

lib to parse text file from SDCard, for config of RepRap printers

Posted by casainho 
lib to parse text file from SDCard, for config of RepRap printers
December 11, 2010 09:52AM
Regarding this work, I am working to put an SDCard to work with my ARM board. SDCard will be as the "board internal memory", able to store at least to 1Gbytes.

For now, I am looking to put on SDCard a "config.txt" file were will be stored configuration values, as example:

steps_per_mm_x = 80
steps_per_mm_y = 80
steps_per_mm_z = 6400
steps_per_mm_e = 36 /* Wades extruder, NEMA 17 geared extruder (1/39 * 6.5mm) */

maximum_feedrate_x = 1800 /* 30mm / second */
maximum_feedrate_y = 1800
maximum_feedrate_z = 60 /* 1mm / second */
maximum_feedrate_e = 40000

This will make easy for users configure his machine -- no need to download Arduino IDE, install it, download firmware source code, build it and program. Users will be able to quick edit the TXT file on any OS, changing the configuration.

Now I am looking for:

1. what values should the configuration file store?

2. how to organize the data inside the file?

3. any Open Source library for microcontrollers, to parse the file and save/record the values.


---
New cutting edge RepRap electronics, ARM 32 bits @ 100MHz runs RepRap @ 725mm/s:

[www.3dprinting-r2c2.com]
Hello casainho, I have an arduino One, with a ethernet shield, and i wrote this code using the sdfat lib.

// Function to clear a string
void clearStr (char* str) {
  int len = strlen(str);
  for (int c = 0; c < len; c++) {
    str[c] = 0;
  }
}
// Function for parse varibales in a config.txt file stored in sdcard
int getconfig(char* str) {
  int valor=0;
  char configfile[]="CONFIG.TXT"; // definim fitxer configuracio
  if (!file.open(&root, configfile, O_READ)) {
    Serial.println("NO TROB CONFIG.TXT!!!");
    Serial.println();
  }
  else{
    boolean flag_comando = false;
    char configcomando[100];
    char comana[6]; // pot guardar fins a 99999 (darrera posiciĆ³ reservada per 0;
    int indexconfig=0;
    int16_t c;
      while ((c = file.read()) > 0) {
      configcomando[indexconfig]=(char)c;
      indexconfig++;
      if(strstr(configcomando,str)){
        indexconfig=0;
        clearStr(configcomando);
        flag_comando = true;
      }

      if(c==59){
        int llarga = strlen(configcomando);
        int i2=0; // index de 2on string
        for(int cont=1;cont0 ;i--){
      voltes++;
      if(voltes==5){ 
        valor=valor+((comana[i-1]-48)*10000);            
      }
      if(voltes==4){ 
        valor=valor+((comana[i-1]-48)*1000);            
      }
      if(voltes==3){ 
        valor=valor+((comana[i-1]-48)*100);            
      }
      if(voltes==2){ 
        valor=valor+((comana[i-1]-48)*10);            
      }
      if(voltes==1){ 
        valor=valor+(comana[i-1]-48);          
      }
    
    }
  }
  return valor;
}

The format are the CONFIG.TXT file are this:
temps=10;
tmax=25;
tmin=10;
hmax=9000;
hmin=1234;

and in the program of the arduino, this is the code:

int temps = getconfig("temps")
int tmax = getconfig("tmax")
int tmin = getconfig("tmin")

etc...

I'm a beginner with arduino, but I hope this function help you.
See you. winking smiley
Re: lib to parse text file from SDCard, for config of RepRap printers
March 27, 2011 06:30PM
Hello.

Thank you for sharing ;-)

Well, after a few days, I got the "config.txt" file working, and here it is: [reprap.org]

I am using this code to read each line:
uint16_t read_u16 (FIL *file, uint8_t *line)
{
  f_gets(line, 80, file); /* read one line */
  uint8_t *p_pos = strchr(line, '='); /* find the '=' position */
  return (atoi(p_pos+1));
}

Edited 1 time(s). Last edit at 03/27/2011 06:34PM by casainho.


---
New cutting edge RepRap electronics, ARM 32 bits @ 100MHz runs RepRap @ 725mm/s:

[www.3dprinting-r2c2.com]
Hi,
thanx for your example code... smiling smiley


#include 
#include 

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void error_P(const char *str)
{
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}
void setup(void)
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("type any character to start");
  while (!Serial.available());
  Serial.println();
  
  // initialize the SD card
  if (!card.init()) error("card.init");
  
  // initialize a FAT volume
  if (!volume.init(card)) error("volume.init");

  
  Serial.println();
  
int cytime=getconfig("temps");

 
  Serial.println(cytime);  

  
}

void loop(void) {

}



// Function to clear a string
void clearStr (char* str) {
  int len = strlen(str);
  for (int c = 0; c < len; c++) {
    str[c] = 0;
  }
}
// Function for parse varibales in a config.txt file stored in sdcard
int getconfig(char* str) {
  int valor=0;
  char configfile[]="CONFIG.TXT"; // definim fitxer configuracio
  if (!file.open(&root, configfile, O_READ)) {
    Serial.println("NO TROB CONFIG.TXT!!!");
    Serial.println();
  }
  else{
    boolean flag_comando = false;
    char configcomando[100];
    char comana[6]; // pot guardar fins a 99999 (darrera posiciĆ³ reservada per 0;
    int indexconfig=0;
    int16_t c;
      while ((c = file.read()) > 0) {
      configcomando[indexconfig]=(char)c;
      indexconfig++;
      }
      
     /*
     if(strstr(configcomando,str)){
        indexconfig=0;
        clearStr(configcomando);
        flag_comando = true;
      }
      */
      
  }
      
  return valor;
}



but i only get empty variables back ?

Can you please help or post code ?

thanx XOR
Sorry, only registered users may post in this forum.

Click here to login