XYZ Da Vinci 3D

K tiskárně XYZ Da Vinci 3 v 1 si lze koupit dražší originální filamenty, které v sobě obsahují čip. Ten v sobě mimo jiné nese informaci o zbývající délce filamentu a tiskárna se tak může rozhodnout, zda má pro požadovaný výtisk na cívce dost filamentu. Neoriginální filamenty čip neobsahují, ale to nevadí. Lze použít čip z originálního filamentu a přeprogramovat ho podle potřeby. Budeme potřebovat Arduino, display, pár drátů a program. Jak vše zkombinovat se dozvíte v následujícím videu:

Níže si můžete zkopírovat kód pro programátor filamentových čipů.

/*
Da Vinci EEPROM update Copyright (C) 2014 by Oliver Fueckert <oliver@voltivo.com>
Increment Serial code - contributed by Matt
UNI/O Library Copyright (C) 2011 by Stephen Early <steve@greenend.org.uk>
User interface (LCD shield 16x2) - Filip VESELY
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */

/************************************************************
Pinout looking at the pads on the EEPROM board
-------------------\
|                   \
|  GND   SCIO   +5V  \
|                    | 
----------------------

Sample chip content:
Da Vinci EEPROM found...
Reading the Davinci EEPROM Contents...
(success)
00: 5A415A000037385180A9030080A90300 ZAZ..78Q........
10: D2005A005448504D3034363500000000 ..Z.THPM0465....
20: 000000003400000000000000AA55AA55 ....4........U.U
30: 883355AA000000000000000000000000 .3U.............
40: 5A415A000037385180A9030080A90300 ZAZ..78Q........
50: D2005A005448504D3034363500000000 ..Z.THPM0465....
60: 000000003400000000000000AA55AA55 ....4........U.U
70: 883355AA80A90300AA55AA55AF210B00 .3U......U.U.!..
(success)

https://wonderfulengineering.com/how-to-reset-the-da-vinci-1-0-filament-counter-using-an-arduino/
 
*************************************************************/

#ifndef _NANODEUNIO_LIB_H
#define _NANODEUNIO_LIB_H

#if ARDUINO >= 100
  #include <Arduino.h> // Arduino 1.0
#else
  #include <WProgram.h> // Arduino 0022
#endif

#define NANODE_MAC_DEVICE 0xa0
#define NANODE_MAC_ADDRESS 0xfa

#define CODE 0x00 //1 Byte
#define MATERIAL 0x01 //1 Byte
#define COLOR 0x02  //2 Bytes
#define DATE 0x05  //4 Bytes
#define TOTALLEN 0x08 //4 Bytes
#define NEWLEN 0x0C //4 Bytes
#define HEADTEMP 0x10 //2 Bytes
#define BEDTEMP 0x12  //2Bytes
#define MLOC 0x14 //2 Bytes
#define DLOC 0x16 //2 Bytes
#define SN 0x18   //12 Bytes
#define CRC 0x24  //2 Bytes
#define LEN2 0x34 //4 Bytes


//***************USER INTERFACE***********************

#include <LiquidCrystal.h> // Including a LCD control library ( 16 x 2 LCD Shield)
#define lcdBrightness 10 // pin for display brightness
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Initialize LCD display

String materials[] = {"ABS", "PETG", "PLA", "FLEX", "ASA", "TOUGH PLA", "UVCR", "WATER SOLUBLE", "NYLON"};
int materialsLength = 9;
int materialsIndex = 0;

String material = "ABS";
unsigned long filamentLength = 120;
unsigned long nozzleTemperature = 210;
unsigned long bedTemperature = 90;

//Variables used during chip programming 
byte x[4]; // filament length
byte et[4]; // nozzle temperature
byte bt[4]; // bed temperature
byte mt[4]; // material

// DISPLAY FUNCTIONS
void clearDisplay(){
   clearLine(0);
   clearLine(1);
}

void clearLine(int line){
  lcd.setCursor(0, line);
   lcd.print("                ");
}

void printText(String text, int line){
  clearLine(line);
  lcd.setCursor(0,line);
  lcd.print(text);
}

void printNumber(int number, int line){
  clearLine(line);
  lcd.setCursor(0,line);
  lcd.print(number, DEC);
}

// USER INTERFACE FUNCTIONS

void userInput(){

  int state = 0;

  printText("Typ materialu:",0); //material type
  printText(material, 1);

  while (state < 4){
  // Read analog pin A0 to variable. All buttons togeather changes voltage on this pin. 
  int analog = analogRead(0);

    switch(state){
      
      case 0:
      //Nahoru(UP)
      if ( (analog > 95) && (analog < 150) ){
        if (materialsIndex < materialsLength-1){
          materialsIndex++;
        }else{
          materialsIndex = 0;
        }
        material = materials[materialsIndex];
        printText(material, 1);
        delay(500);
        break;
      }
        
      //Dolu(DOWN)
      if ( (analog > 250) && (analog < 350) ){
        if (materialsIndex >= 1){
          materialsIndex--;
        }else{
          materialsIndex = materialsLength - 1;
        }
        material = materials[materialsIndex];
        printText(material, 1);
        delay(500);
        break;
      }
  
      //Vyber(SELECT)
      if ( (analog > 600) && (analog < 750) ){
        state = 1;
        clearDisplay();
        printText("Delka v metrech:", 0); //filament length in meters
        printNumber(filamentLength, 1);
        delay(500);
        break;
      }
      break;
  
      case 1:
      //Nahoru(UP)
      if ( (analog > 95) && (analog < 150) ){
        filamentLength++;
        printNumber(filamentLength, DEC);
        delay(500);
        break;
      }
        
      //Dolu(DOWN)
      if ( (analog > 250) && (analog < 350) ){
        if (filamentLength >= 1){
          filamentLength--;
          printNumber(filamentLength, DEC);
          delay(500);
          break;
        }
      }
        //Vlevo(LEFT)
      if ( (analog > 400) && (analog < 500) ){ 
          if (filamentLength >= 10){
          filamentLength = filamentLength - 10;
          printNumber(filamentLength, DEC);
          delay(500);
          break;
        }     
      }
  
      //Vpravo(RIGHT)
      if (analog < 50){
        filamentLength = filamentLength + 10;
        printNumber(filamentLength, DEC);
        delay(500);
        break;
      }
  
      //Vyber(SELECT)
      if ( (analog > 600) && (analog < 750) ){
        state = 2;
        clearDisplay();
        printText("Teplota trysky: ", 0); // Nozzle temperature
        printNumber(nozzleTemperature, 1);
        delay(500);
        break;
      }
      break;
   
      case 2:
      //Nahoru(UP)
      if ( (analog > 95) && (analog < 150) ){
        nozzleTemperature++;
        printNumber(nozzleTemperature, 1);
        delay(500);
        break;
      }
        
      //Dolu(DOWN)
      if ( (analog > 250) && (analog < 350) ){
        if (nozzleTemperature >= 1){
          nozzleTemperature--;
          printNumber(nozzleTemperature, 1);
          delay(500);
          break;
        }
      }
        //Vlevo(LEFT)
      if ( (analog > 400) && (analog < 500) ){ 
          if (nozzleTemperature >= 10){
          nozzleTemperature = nozzleTemperature - 10;
          printNumber(nozzleTemperature, 1);
          delay(500);
          break;
        }     
      }
  
      //Vpravo(RIGHT)
      if (analog < 50){
        nozzleTemperature = nozzleTemperature + 10;
        printNumber(nozzleTemperature, 1);
        delay(500);
        break;
      }
  
      //Vyber(SELECT)
      if ( (analog > 600) && (analog < 750) ){
        state = 3;
        clearDisplay();
        printText("Teplota podlozky", 0); // Bed temperature
        printNumber(bedTemperature, 1); 
        delay(500);
        break;
      }
      break;
  
    
      case 3: 
      //Nahoru(UP)
      if ( (analog > 95) && (analog < 150) ){
        bedTemperature++;
        printNumber(bedTemperature, 1); 
        delay(500);
        break;
      }
        
      //Dolu(DOWN)
      if ( (analog > 250) && (analog < 350) ){
        if (bedTemperature >= 1){
          bedTemperature--;
          printNumber(bedTemperature, 1); 
          delay(500);
          break;
        }
      }
        //Vlevo(LEFT)
      if ( (analog > 400) && (analog < 500) ){ 
          if (bedTemperature >= 10){
          bedTemperature = bedTemperature - 10;
          printNumber(bedTemperature, 1); 
          delay(500);
          break;
        }     
      }
  
      //Vpravo(RIGHT)
      if (analog < 50){
        bedTemperature = bedTemperature + 10;
        printNumber(bedTemperature, 1); 
        delay(500);
        break;
      }
  
      //Vyber(SELECT)
      if ( (analog > 600) && (analog < 750) ){
        state = 4;
        clearDisplay();
        printText("Hledam cip....", 0); // Searching chip...
        delay(500);
        break;
      }
      break;

    }
  }
}

void convertNumberToBytes(unsigned long myInt, byte* bytes){ //unsigned long = 32 bits

  bytes[3] = (myInt >> 24) & 0xFF;
  bytes[2] = (myInt >> 16) & 0xFF;
  bytes[1] = (myInt >> 8) & 0xFF;
  bytes[0] = myInt & 0xFF;
  
  return;
}

void userInputEncoding(){

  Serial.println("Coding inputs...");  // Inputs encoding

  // FILAMENT LENGTH
  convertNumberToBytes(filamentLength*1000, x); // meters -> mm
  // less significant byte first
  //120 000 mm => {0xc0,0xd4,0x01,0x00} => 1100 0000| 1101 0100 | 0000 0001 | 0000 0000 (reverse) => 0000 0000 | 0000 0001 | 1101 0100 | 1100 0000
  Serial.print("x = "); 
  Serial.print(x[0], HEX);  
  Serial.print(" ");
  Serial.print(x[1], HEX);  
  Serial.print(" ");
  Serial.print(x[2], HEX);  
  Serial.print(" ");
  Serial.print(x[3], HEX); 
  Serial.print("\n"); 

  // NOZZLE TEMPERATURE
  convertNumberToBytes(nozzleTemperature, et);
  Serial.print("et = "); 
  Serial.print(et[0], HEX); 
  Serial.print(" "); 
  Serial.print(et[1], HEX);  
  Serial.print("\n"); 
  
  // BED TEMPERATURE
  convertNumberToBytes(bedTemperature, bt);
  Serial.print("bt = "); 
  Serial.print(bt[0], HEX);  
  Serial.print(" ");
  Serial.print(bt[1], HEX);  
  Serial.print("\n"); 


  // MATERIAL
  // appears that they use ascii letters for their entries, 0x41 = A = ABS
  //  41-A ABS  46-F FLEX  47-G PETG  50-P PLA    51-Q PLA
  //  53-S ASA  54-T TOUGH PLA  55-U UVCR   56-V WATER SOLUBLE
  //  59-Y NYLON 

  int material_hash = (char)material[0] *(char)material[1]; // To be able to use switch
  
  switch(material_hash){
    case 4290: //"ABS":
      mt[0] = 0x41;
    break;
    case 5520: //"PETG":
      mt[0] = 0x47;
    break;
    case 6080: //"PLA":
      mt[0] = 0x50;
    break;
    case 5320: //"FLEX":
      mt[0] = 0x46;
    break;
    case 5395: //"ASA":
      mt[0] = 0x53;
    break;
    case 6636: //"TOUGH PLA":
      mt[0] = 0x54;
    break;
    case 7310: //"UVCR":
      mt[0] = 0x55;
    break;
    case 5655: //"WATER SOLUBLE":
      mt[0] = 0x56;
    break;
    case 6942: //"NYLON":
      mt[0] = 0x59;
    break;
    default:
      mt[0] = 0x41; 
    break;
  }

  Serial.print("mt = "); 
  Serial.print(mt[0], HEX); 
  Serial.print("\n"); 

}

//***********COMMUNICATION, PROGRAMMING FUNCTIONS***********************

void IncrementSerial(unsigned char * cArray, long lAddress, long lSize)
{
  unsigned char szTempBuffer[20] = {0};
  memcpy(szTempBuffer,&cArray[lAddress],lSize);
  long lSerial = atol((char *)szTempBuffer);
  lSerial++;
  sprintf((char *)szTempBuffer,"%04d",lSerial);
  memcpy(&cArray[lAddress],szTempBuffer,lSize);
}

class NanodeUNIO {
 private:
  byte addr;
 public:
  NanodeUNIO(byte address);

  boolean read(byte *buffer,word address,word length);
  boolean start_write(const byte *buffer,word address,word length);
  boolean enable_write(void);
  boolean disable_write(void);
  boolean read_status(byte *status);
  boolean write_status(byte status);
  boolean await_write_complete(void);
  boolean simple_write(const byte *buffer,word address,word length);
};

#endif /* _NANODEUNIO_LIB_H */

#define UNIO_STARTHEADER 0x55
#define UNIO_READ        0x03
#define UNIO_CRRD        0x06
#define UNIO_WRITE       0x6c
#define UNIO_WREN        0x96
#define UNIO_WRDI        0x91
#define UNIO_RDSR        0x05
#define UNIO_WRSR        0x6e
#define UNIO_ERAL        0x6d
#define UNIO_SETAL       0x67

#define UNIO_TSTBY 600
#define UNIO_TSS    10
#define UNIO_THDR    5
#define UNIO_QUARTER_BIT 10
#define UNIO_FUDGE_FACTOR 5

//ADAPT HERE TO USE ANOTHER PIN
#if defined(__AVR__) // my  case
  #define UNIO_OUTPUT() do { DDRD |= 0x04; } while (0)  // Data Direction Register, D2 output =>  + 0000 0100 = + 0x04
  #define UNIO_INPUT() do { DDRD &= 0xfb; } while (0)  // Data Direction Register, D2 input =>  * 1111 1011 = * 0xFB
#else
  #define UNIO_PIN  2
  #define UNIO_OUTPUT() pinMode(UNIO_PIN, OUTPUT)
  #define UNIO_INPUT() pinMode(UNIO_PIN, INPUT);

void sei() {
  enableInterrupts();
}
void cli() {
  disableInterrupts();
}
#endif

//ADAPT HERE TO USE ANOTHER PIN
static void set_bus(boolean state) {
#if defined(__AVR__)
  PORTD=(PORTD&0xfb)|(!!state)<<2; // Two exclamations makes from any number 1 and from 0 -> zero. 1111 1011 = 0xfb. Write in the output.
  //PORTD=(PORTD&0x7f)|(!!state)<<7;
#else
  digitalWrite(UNIO_PIN, state);
#endif
}

//ADAPT HERE TO USE ANOTHER PIN
static boolean read_bus(void) {
#if defined(__AVR__)
  return !!(PIND&0x04); // Reading bit => PORTD * 0000 0100
  //return !!(PIND&0x80);
#else
  return digitalRead(UNIO_PIN);
#endif
}
static void unio_inter_command_gap(void) {
  set_bus(1);
  delayMicroseconds(UNIO_TSS+UNIO_FUDGE_FACTOR);
}

static void unio_standby_pulse(void) {
  set_bus(0);
  UNIO_OUTPUT();
  delayMicroseconds(UNIO_TSS+UNIO_FUDGE_FACTOR);
  set_bus(1);
  delayMicroseconds(UNIO_TSTBY+UNIO_FUDGE_FACTOR);
}

static volatile boolean rwbit(boolean w) {
  boolean a,b;
  set_bus(!w);
  delayMicroseconds(UNIO_QUARTER_BIT);
  a=read_bus();
  delayMicroseconds(UNIO_QUARTER_BIT);
  set_bus(w);
  delayMicroseconds(UNIO_QUARTER_BIT);
  b=read_bus();
  delayMicroseconds(UNIO_QUARTER_BIT);
  return b&&!a;
}

static boolean read_bit(void) {
  boolean b;
  UNIO_INPUT();
  b=rwbit(1);
  UNIO_OUTPUT();
  return b;
}

static boolean send_byte(byte b, boolean mak) {
  for (int i=0; i<8; i++) {
    rwbit(b&0x80);
    b<<=1;
  }
  rwbit(mak);
  return read_bit();
}

static boolean read_byte(byte *b, boolean mak) {
  byte data=0;
  UNIO_INPUT();
  for (int i=0; i<8; i++) {
    data = (data << 1) | rwbit(1);
  }
  UNIO_OUTPUT();
  *b=data;
  rwbit(mak);
  return read_bit();
}

static boolean unio_send(const byte *data,word length,boolean end) {
  for (word i=0; i<length; i++) {
    if (!send_byte(data[i],!(((i+1)==length) && end))) return false;
  }
  return true;
}

static boolean unio_read(byte *data,word length)  {
  for (word i=0; i<length; i++) {
    if (!read_byte(data+i,!((i+1)==length))) return false;
  }
  return true;
}

static void unio_start_header(void) {
  set_bus(0);
  delayMicroseconds(UNIO_THDR+UNIO_FUDGE_FACTOR);
  send_byte(UNIO_STARTHEADER,true);
}

NanodeUNIO::NanodeUNIO(byte address) {
  addr=address;
}

#define fail() do { sei(); return false; } while (0)

boolean NanodeUNIO::read(byte *buffer,word address,word length) {
  byte cmd[4];
  cmd[0]=addr;
  cmd[1]=UNIO_READ;
  cmd[2]=(byte)(address>>8);
  cmd[3]=(byte)(address&0xff);
  unio_standby_pulse();
  cli();
  unio_start_header();
  if (!unio_send(cmd,4,false)) fail();
  if (!unio_read(buffer,length)) fail();
  sei();
  return true;
}

boolean NanodeUNIO::start_write(const byte *buffer,word address,word length) {
  byte cmd[4];
  if (((address&0x0f)+length)>16) return false; // would cross page boundary
  cmd[0]=addr;
  cmd[1]=UNIO_WRITE;
  cmd[2]=(byte)(address>>8);
  cmd[3]=(byte)(address&0xff);
  unio_standby_pulse();
  cli();
  unio_start_header();
  if (!unio_send(cmd,4,false)) fail();
  if (!unio_send(buffer,length,true)) fail();
  sei();
  return true;
}

boolean NanodeUNIO::enable_write(void) {
  byte cmd[2];
  cmd[0]=addr;
  cmd[1]=UNIO_WREN;
  unio_standby_pulse();
  cli();
  unio_start_header();
  if (!unio_send(cmd,2,true)) fail();
  sei();
  return true;
}

boolean NanodeUNIO::disable_write(void) {
  byte cmd[2];
  cmd[0]=addr;
  cmd[1]=UNIO_WRDI;
  unio_standby_pulse();
  cli();
  unio_start_header();
  if (!unio_send(cmd,2,true)) fail();
  sei();
  return true;
}

boolean NanodeUNIO::read_status(byte *status) {
  byte cmd[2];
  cmd[0]=addr;
  cmd[1]=UNIO_RDSR;
  unio_standby_pulse();
  cli();
  unio_start_header();
  if (!unio_send(cmd,2,false)) fail();
  if (!unio_read(status,1)) fail();
  sei();
  return true;
}

boolean NanodeUNIO::write_status(byte status) {
  byte cmd[3];
  cmd[0]=addr;
  cmd[1]=UNIO_WRSR;
  cmd[2]=status;
  unio_standby_pulse();
  cli();
  unio_start_header();
  if (!unio_send(cmd,3,true)) fail();
  sei();
  return true;
}

boolean NanodeUNIO::await_write_complete(void) {
  byte cmd[2];
  byte status;
  cmd[0]=addr;
  cmd[1]=UNIO_RDSR;
  unio_standby_pulse();
  do {
    unio_inter_command_gap();
    cli();
    unio_start_header();
    if (!unio_send(cmd,2,false)) fail();
    if (!unio_read(&status,1)) fail();
    sei();
  } while (status&0x01);
  return true;
}

boolean NanodeUNIO::simple_write(const byte *buffer,word address,word length) {
  word wlen;
  while (length>0) {
    wlen=length;
    if (((address&0x0f)+wlen)>16) {
      wlen=16-(address&0x0f);
    }
    if (!enable_write()) return false;
    if (!start_write(buffer,address,wlen)) return false;
    if (!await_write_complete()) return false;
    buffer+=wlen;
    address+=wlen;
    length-=wlen;
  }
  return true;
}

static void status(boolean r)
{
  if (r) Serial.println("(success)");
  else Serial.println("(failure)");
}

static void dump_eeprom(word address,word length)
{
  byte buf[128];
  char lbuf[80];
  char *x;
  int i,j;

  NanodeUNIO unio(NANODE_MAC_DEVICE);
  
  memset(buf,0,128);
  status(unio.read(buf,address,length));
  
  for (i=0; i<128; i+=16) {
    x=lbuf;
    sprintf(x,"%02X: ",i);
    x+=4;
    for (j=0; j<16; j++) {
      sprintf(x,"%02X",buf[i+j]);
      x+=2;
    }
    *x=32;
    x+=1;
    for (j=0; j<16; j++) {
      if (buf[i+j]>=32 && buf[i+j]<127) *x=buf[i+j];
      else *x=46;
      x++;
    }
    *x=0;
    Serial.println(lbuf);
  }
}

int led = LED_BUILTIN;

/*
These are the values to be written to the EEPROM
Make sure only one is uncommented.
By default its set for the starter ABS cartdridge with 120m of filament 
Verified with firmware 1.1.I
*/

/*
// Value to write to the EEPROM for remaining filament lenght
// Default Starter Cartdridge is 120m
char x[] = {0xc0,0xd4,0x01,0x00}; //120m
//char x[] = {0x80,0xa9,0x03,0x00}; //240m
//char x[] = {0x80,0x1a,0x06,0x00}; //400m

// extruder temp, default is 210 C for ABS
char et[] = {0xd2,0x00}; // 210 C 
//char et[] = {0xe6,0x00}; // 230 C
//char et[] = {0xf5,0x00}; // 245 C
//char et[] = {0xfa,0x00}; // 250 C

// bed temp 90 degrees, default ABS
char bt[] = {0x5a,0x00}; //90C
//char bt[] = {0x32,0x00}; //50C
//char bt[] = {0x28,0x00}; //40C

//Materials
// appears that they use ascii letters for their entries, 0x41 = A = ABS
//  41-A ABS  46-F FLEX  47-G PETG  50-P PLA    51-Q PLA
//  53-S ASA  54-T TOUGH PLA  55-U UVCR   56-V WATER SOLUBLE
//  59-Y NYLON 

//char mt[] = {0x41}; //ABS
//char mt[] = {0x50}; //PLA
char mt[] = {0x46}; //Flex
*/

byte sr;
NanodeUNIO unio(NANODE_MAC_DEVICE);
  
void setup() {

  pinMode(led, OUTPUT);
  Serial.begin(115200);
  while(!Serial);
  delay(250);

  //START OF COMMUNICATION WITH DISPLAY
  // 16 characters, 2 rows
  lcd.begin(16, 2);
  // LCD brightness pin will be output
  pinMode(lcdBrightness, OUTPUT);

  // torn on display light
  digitalWrite(lcdBrightness, HIGH);
  delay(500);
  // torn off display light
  digitalWrite(lcdBrightness, LOW);
  delay(500);
  // torn on display light
  digitalWrite(lcdBrightness, HIGH);

}

void loop() {

  // user interface
  userInput();
  userInputEncoding();
  delay(5000);
  
  do {
    digitalWrite(led, LOW); 
    Serial.println("Testing connection to Da Vinci EEPROM CHIP\n");    
    delay(500);
    digitalWrite(led, HIGH);
  } while(!unio.read_status(&sr));
  
  Serial.println("Da Vinci EEPROM found...");
  Serial.println("Reading the Davinci EEPROM Contents...");
  dump_eeprom(0,128);
  //dump_eeprom(116,4);
  
  //Read the serial number - added by Matt
  byte buf[20];
  memset(buf,0,20);
  status(unio.read(buf,SN,12));
  //Increment the serial number
  IncrementSerial(&buf[0], 0, 12);  

  //Serial.println("Press enter to update EEPROM...");
  //while(!Serial.available());
  //while(Serial.available()) Serial.read();

  printText("Programovat?", 0); // Programm?

  int analog = analogRead(0);

  //Vyber(SELECT)
  while (1){
    if ( (analog > 600) && (analog < 750) ){
    clearDisplay();
    printText("Updating EEPROM...", 0);
    break;
    }

    analog = analogRead(0);
    delay(200);
  }

  printText("Hledam cip....", 0); // Searching chip...

  do {
    digitalWrite(led, LOW); 
    Serial.println("Testing connection to Da Vinci EEPROM CHIP\n");    
    delay(500);
    digitalWrite(led, HIGH);
  } while(!unio.read_status(&sr));
   
  Serial.println("Updating EEPROM...");
  status(unio.simple_write((const byte *)x,TOTALLEN,4));
  status(unio.simple_write((const byte *)x,NEWLEN,4));
  status(unio.simple_write((const byte *)et,HEADTEMP,2)); // extruder temp
  status(unio.simple_write((const byte *)bt,BEDTEMP,2)); // bed temp
  status(unio.simple_write((const byte *)mt,MATERIAL,1)); // Material
  
  //Write the serial number
  status(unio.simple_write((const byte *)buf,SN,12)); //Serial Number
  status(unio.simple_write((const byte *)x,LEN2,4));
  // same block from offset 0 is offset 64 bytes
  status(unio.simple_write((const byte *)x,64 + TOTALLEN,4));
  status(unio.simple_write((const byte *)x,64 + NEWLEN,4));
  status(unio.simple_write((const byte *)et,64 + HEADTEMP,2)); // extruder temp
  status(unio.simple_write((const byte *)bt,64 + BEDTEMP,2)); // bed temp
  status(unio.simple_write((const byte *)mt,64 + MATERIAL,1)); // Material
   //Write the serial number
  status(unio.simple_write((const byte *)buf,64 + SN,12)); //Serial Number
  status(unio.simple_write((const byte *)x,64 + LEN2,4));

  printText("Hotovo!", 0); // Done!

  Serial.println("Dumping Content after modification...");
  dump_eeprom(0,128);
 
  digitalWrite(led, HIGH);   // turn the LED on
  delay(1000);              // wait for 1 second
}