Error compiling for board Arduino Leonardo & an RTC issue

Hello. I have had some trouble compiling the NWatch firmware. I have set up the libraries and they all work fine. Can someone help me out what I am doing wrong here? Here is the whole error:

Arduino: 1.8.10 (Mac OS X), Board: "Arduino Leonardo"

/var/folders/rc/hpl1rsgd2h7bg45b04my1c280000gn/T//ccoFxOvs.ltrans0.ltrans.o: In function `oled_flush':
sketch/oled.c:108: undefined reference to `spi_transfer_nr'
sketch/oled.c:109: undefined reference to `spi_transfer_nr'
sketch/oled.c:110: undefined reference to `spi_transfer_nr'
sketch/oled.c:112: undefined reference to `spi_transfer_nr'
sketch/oled.c:113: undefined reference to `spi_transfer_nr'
/var/folders/rc/hpl1rsgd2h7bg45b04my1c280000gn/T//ccoFxOvs.ltrans0.ltrans.o:sketch/oled.c:114: more undefined references to `spi_transfer_nr' follow
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Leonardo.

For the time I was not able to upload the firmware, I have been working on my own software, and after the battery of the watch has died, the real-time clock has fallen behind for the amount of time that the watch was uncharged. How can I fix this issue? Can I fix it by a few lines of code, do I have to do a full restart on the watch, or do I have to recalibrate it manually? Here is my code:

#include <SPI.h>
#include <Wire.h>
//timer
#include "RTClib.h"
//oled
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_DC     A3
#define OLED_CS     A5
#define OLED_RESET  A4
Adafruit_SSD1306 oled(OLED_DC, OLED_RESET, OLED_CS);

#define BUTTON_1 10
#define BUTTON_2 8
#define BUTTON_3 11

//timer instance 
RTC_DS3231 rtc;

int display_count = 0;

//battery indicator variables
float percent = 0;
float prev_percent = -1;
static byte bPin = A11;
static byte battEn = 4;
float R1 = 10000;
float R2 = 10000;
float voltage;
float vDivider = (R2 / (R1 + R2));

//time and date variables
DateTime now;
DateTime prev_time;
int charPixel = 12; //for double sized text on the display
int offset = (128 - charPixel * 8)/2;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup() {
  // put your setup code here, to run once:
  pinMode(BUTTON_1, INPUT_PULLUP);
  pinMode(BUTTON_2, INPUT_PULLUP);
  pinMode(BUTTON_3, INPUT_PULLUP);
  
  Serial.begin(9600);
  oled_setup();
  delay(3000);
  timer_setup();
  
  prev_time = rtc.now();
  now = prev_time;
  
  display_current_time();
  display_current_date(true);
}

void loop() {
  if (display_count < 10){
    
    display_battery();
    display_date();
    display_time();  
  }
  if (digitalRead(BUTTON_1) == LOW || digitalRead(BUTTON_2) == LOW || digitalRead(BUTTON_3) == LOW){
    prev_time = rtc.now();
    now = prev_time;
    prev_percent = 0;
    display_battery();
    display_current_time();
    display_current_date(true);
    display_count = 0;
    oled.display();
  }
  
}

void oled_setup(){
  oled.begin();
  oled.clearDisplay();
}

void timer_setup(){
  rtc.begin();
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void display_time(){
  now = rtc.now();
  if(display_count < 10 && prev_time.hour() != now.hour()){
    oled.setTextSize(2);
    
    oled.setCursor(offset, 32 - 6);
    oled.setTextColor(BLACK);

    print_double_digit(prev_time.hour());
    oled.print(":");
    print_double_digit(prev_time.minute());
    oled.print(":");
    print_double_digit(prev_time.second());
    oled.display();
    
    display_current_time();
    if (++display_count >= 10){
      clear_display();
    }
    prev_time = now;
  }else if(display_count < 10 && prev_time.minute() != now.minute()){
    oled.setTextSize(2);
    
    oled.setCursor(36 + offset, 32 - 6);
    oled.setTextColor(BLACK);

    
    print_double_digit(prev_time.minute());
    oled.print(":");
    print_double_digit(prev_time.second());
    oled.display();
    
    display_current_time();
    if (++display_count >= 10){
      clear_display();
    }    
    prev_time = now;
  } else if(display_count < 10 && prev_time.second() != now.second()){
    oled.setTextSize(2);
    
    oled.setCursor(72 + offset, 32 - 6);
    oled.setTextColor(BLACK);

    print_double_digit(prev_time.second());
    oled.display();
    
    display_current_time();
    if (++display_count >= 10){
      clear_display();
    }
    prev_time = now;
  }
}

void display_current_time(){
  oled.setTextSize(2);
  oled.setCursor(offset, 32 - 6);
  oled.setTextColor(WHITE);
    
  print_double_digit(now.hour());
  oled.print(":");
  print_double_digit(now.minute());
  oled.print(":");
  print_double_digit(now.second());
  oled.display();
}

void display_battery(){
  digitalWrite(battEn, HIGH);
  delay(50);
  voltage = analogRead(bPin);
  voltage = (voltage / 1024) * 3.35;
  voltage = voltage / vDivider;
  delay(50);
  digitalWrite(battEn, LOW);

  if (voltage > 4.2){
    percent = 100;
  }else if(voltage < 3.0){
    percent = 0;
  }else{
    percent = (((voltage - 3.0) / 1.2)) * 100;
  }
  if (prev_percent + 0.7 < percent || prev_percent - 0.7 > percent){
    oled.setTextSize(1);
    
    oled.setCursor(0, 0);
    oled.setTextColor(BLACK);
    oled.print((int)ceil(prev_percent));
    oled.print("%");
    oled.display();
    
    oled.setCursor(0, 0);
    oled.setTextColor(WHITE);
    oled.print((int)ceil(percent));
    oled.print("%");
    oled.display();
    
    prev_percent = percent;
  }
}

void display_date(){
  
  if (prev_time.day() != now.day() || prev_time.month() || prev_time.year() != now.year()){
    display_current_date(false);
    display_current_date(true);
  }
  
}

void display_current_date(bool white){
  oled.setTextSize(1);
  DateTime date;
  if (white){
    oled.setTextColor(WHITE);
    date = now;
  }else{
    oled.setTextColor(BLACK);
    date = prev_time;
  }
  oled.setCursor(0, 56);
  print_double_digit(date.day());
  oled.print('/');
  print_double_digit(date.month());
  oled.print('/');
  oled.print(date.year());
    
  oled.print("   ");
  oled.print(daysOfTheWeek[date.dayOfTheWeek()]);
}

void print_double_digit(int num){
  if(num < 10){
    oled.print("0");
  }
  oled.print(num);
}

void clear_display(){
  oled.clearDisplay();
  oled.display();
}

I would appreciate the help :smiley:

Hi @sertcast You should calibrate the time manually, there are a couple of examples here https://community.watchx.io/c/projects/watch-faces that you set the time from the menu as an option.

Regarding to NWatch firmware, please try to compile on different versions of Arduino, or a different PC. This error may be related with arduino compiler.

Let us know your progress!

Hello,

You can look here for the solution of the problem. Problems with Nwatch-Master