Uploading Code to Nano For Max7219 7-Segment Clock Not Working

Hi everyone! I am trying to upload code that I got from “Electronoob” For a Digital clock I am making. Here is the Video I am following: DIY clock | Homemade 7 segments "nixie" tubes - YouTube

Here is his website that has his code and schematic: https://www.electronoobs.com/eng_arduino_tut47_code1.php

Here is the code I am having problems with: (I have to break it up into 2 parts because it wont let me upload the whole thing.)

#include <DS3231.h>

/*
Code by: ELECTRONOOBS, 16/10/2018
Tutorial webpage: https://www.electronoobs.com/eng_arduino_tut47.php
Scheamtic: https://www.electronoobs.com/eng_arduino_tut47_sch1.php
Youtube channel: https://www.youtube.com/c/ELECTRONOOBS
*/

//We include the DS3231 library for the real time module
#include <DS3231.h>   //Downlaod it here: https://www.electronoobs.com/eng_arduino_ds3231.php
DS3231  rtc(SDA, SCL);          


//Define the I/O
#define MAX7219_Clock 2         //CLK pin for the MAX7219
#define MAX7219_Chip_Select 3   //CS pin for the MAX7219
#define MAX7219_Data_IN 4       //D_in pin for the MAX7219
     
int LED = 8;                    //Pin for the two blinking LEDs
//int SET = 5;                  //Not used any more
int HOUR = 7;                   //Input for set hour button
int MINUTE = 6;                 //Input for set minute button



//Other variables for the code
int Delay=1000;                       //Variable used for the 1 second loop. Each 1s we change the LED state so it will blink    
bool LED_state = false;               //Here we save the LED state each loop, HIGH or LOW
unsigned long previousMillis = 0;     //Variable used to count the 1s loop time
String time_str = "";                 //Here we save the time in a string format from the ral time module
String prev_time_str = "";            //We save the last time value so we could compare it
String hr_1_str = "";                 //We divide the hours and minutes in separate variables first digit for hour
String hr_2_str = "";                 //We divide the hours and minutes in separate variables second digit of hour
String min_1_str = "";                //We divide the hours and minutes in separate variables first digit of minute
String min_2_str = "";                //We divide the hours and minutes in separate variables secodn digit of minute
int hr_1 = 0;                         //first digit for hour
int hr_2 = 0;                         //second digit for hour
int min_1 = 0;                        //first digit for minute
int min_2 = 0;                        //second digit for minute
int set_hour = 0;
int set_minute = 0;



//This function will shift the data to the MAX7219 driver. 
void shift(byte send_to_address, byte send_this_data)
{
  digitalWrite(MAX7219_Chip_Select, LOW);
  shiftOut(MAX7219_Data_IN, MAX7219_Clock, MSBFIRST, send_to_address);
  shiftOut(MAX7219_Data_IN, MAX7219_Clock, MSBFIRST, send_this_data);
  digitalWrite(MAX7219_Chip_Select, HIGH);
}


 
void setup() {
  //Serial.begin(9600);
  rtc.begin();                                  //We start the real time module
  pinMode(MAX7219_Data_IN, OUTPUT);             //Define the data pin for the MAX7219 as output
  pinMode(MAX7219_Chip_Select, OUTPUT);         //Define the cs pin for the MAX7219 as output
  pinMode(MAX7219_Clock, OUTPUT);               //Define the clock pin for the MAX7219 as output
  digitalWrite(MAX7219_Chip_Select, HIGH);      //We set the CS to high, CS is negative enabeled

  pinMode(LED,OUTPUT);                            
  //pinMode(SET,INPUT);                         //Not used any more
  pinMode(HOUR,INPUT);
  pinMode(MINUTE,INPUT);
  //digitalWrite(SET, HIGH);                    //Not used any more
  digitalWrite(HOUR, HIGH); 
  digitalWrite(MINUTE, HIGH);  
  digitalWrite(LED,LED_state);
  delay(200);

  //Setup
  shift(0x0f, 0x00); //display test register - test mode off
  shift(0x0c, 0x01); //shutdown register - normal operation
  shift(0x0b, 0x04); //scan limit register - display digits 0 thru 7
  shift(0x0a, 0x01); //intensity register - Min brightness: 0x01, Max brightness: 0x0f
  shift(0x09, 0xff); //decode mode register - CodeB decode all digits

  shift(0x01, 0xff); //Turn off all segments
  shift(0x02, 0xff); 
  shift(0x03, 0xff); 
  shift(0x04, 0xff);
  delay(100); //Small delay
}

void loop() {
  //This loop will execute each Delay=1000ms, so 1 second
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= Delay)
  {
    previousMillis += Delay;          
    time_str = rtc.getTimeStr();      //First,we get the real time, hour, minute, second
    hr_1_str += (char)time_str[0];    //We separate the first digit hour value
    hr_1 = hr_1_str.toInt();          //Pass the hour value from String to int format
    hr_2_str += (char)time_str[1];    //We separate the second digit hour value
    hr_2 = hr_2_str.toInt();          //Pass the hour value from String to int format
    min_1_str += (char)time_str[3];   //We separate the first digit minute value 
    min_1 = min_1_str.toInt();        //Pass the minute value from String to int format
    min_2_str += (char)time_str[4];   //We separate the second digit minute value 
    min_2 = min_2_str.toInt();        //Pass the minute value from String to int format
    LED_state = !LED_state;           //Invert the blinking LED state each loop, so each 1 second.
    digitalWrite(LED,LED_state);      //Turn the LEDs on or off
    if(prev_time_str != time_str)     //If the time is not the same, we print the new value to the 7-seg display
    {
      print_time_to_7_seg(time_str);
    }
    prev_time_str = time_str;         //Save the last time value
   }//end of timer

    hr_1_str = "";                    //Reset the digits String valuew for hours and minutes
    hr_2_str = "";
    min_1_str = "";
    min_2_str = "";

   if(!digitalRead(HOUR))             //If the hour button is pressed, we increase hour by one
   {
     set_hour = hr_1*10+hr_2;         //get total hour value in int format 
     set_minute = min_1*10+min_2;     //get total minuter value in int forma
     set_hour = set_hour + 1;         //Increase hour by 1
     if(set_hour == 24)               //If we get to hour 24, we start from 0
     {
       set_hour = 0;
     }
     rtc.setTime(set_hour, set_minute, 0);     // Write the new time to the RTC module
     //delay(50);
     time_str = rtc.getTimeStr(); 
     print_time_to_7_seg(time_str);            //Print the new time value to the 7-seg dispaly
   }

    //We do the same for the minute push button
   if(!digitalRead(MINUTE))
   {
     set_hour = hr_1*10+hr_2;
     set_minute = min_1*10+min_2;
     set_minute = set_minute + 1;
     if(set_minute == 60)
     {
       set_minute = 1;
     }
     rtc.setTime(set_hour, set_minute, 0);     // Set the time to 12:00:00 (24hr format)
     //delay(50);
     time_str = rtc.getTimeStr(); 
     print_time_to_7_seg(time_str);
   }
}//end of void loop
//This function will shift the numbers to the MAX7219 driver
void print_time_to_7_seg(String the_time)
{

  if(hr_1 == 0)
  {
    shift(0x01, 0); 
  }
  if(hr_1 == 1)
  {
    shift(0x01, 1); 
  }
  if(hr_1 == 2)
  {
    shift(0x01, 2); 
  }
  if(hr_1 == 3)
  {
    shift(0x01, 3); 
  }
  if(hr_1 == 4)
  {
    shift(0x01, 4); 
  }
  if(hr_1== 5)
  {
    shift(0x01, 5); 
  }
  if(hr_1 == 6)
  {
    shift(0x01, 6); 
  }
  if(hr_1 == 7)
  {
    shift(0x01, 7); 
  }
  if(hr_1 == 8)
  {
    shift(0x01, 8); 
  }
  if(hr_1 == 9)
  {
    shift(0x01, 9); 
  }/////////////////////////////////////end of first digit for hour  
  

  if(hr_2 == 0)
  {
    shift(0x02, 0); 
  }
  if(hr_2== 1)
  {
    shift(0x02, 1); 
  }
  if(hr_2 == 2)
  {
    shift(0x02, 2); 
  }
  if(hr_2 == 3)
  {
    shift(0x02, 3); 
  }
  if(hr_2 == 4)
  {
    shift(0x02, 4); 
  }
  if(hr_2 == 5)
  {
    shift(0x02, 5); 
  }
  if(hr_2 == 6)
  {
    shift(0x02, 6); 
  }
  if(hr_2 == 7)
  {
    shift(0x02, 7); 
  }
  if(hr_2 == 8)
  {
    shift(0x02, 8); 
  }
  if(hr_2 == 9)
  {
    shift(0x02, 9); 
  }/////////////////////////////////////end of second digit for hour
    

  if(min_1 == 0)
  {
    shift(0x03, 0); 
  }
  if(min_1 == 1)
  {
    shift(0x03, 1); 
  }
  if(min_1 == 2)
  {
    shift(0x03, 2); 
  }
  if(min_1 == 3)
  {
    shift(0x03, 3); 
  }
  if(min_1 == 4)
  {
    shift(0x03, 4); 
  }
  if(min_1== 5)
  {
    shift(0x03, 5); 
  }
  if(min_1 == 6)
  {
    shift(0x03, 6); 
  }
  if(min_1 == 7)
  {
    shift(0x03, 7); 
  }
  if(min_1 == 8)
  {
    shift(0x03, 8); 
  }
  if(min_1 == 9)
  {
    shift(0x03, 9); 
  }/////////////////////////////////////end of first digit for minute
  

  if(min_2 == 0)
  {
    shift(0x04, 0); 
  }
  if(min_2== 1)
  {
    shift(0x04, 1); 
  }
  if(min_2 == 2)
  {
    shift(0x04, 2); 
  }
  if(min_2 == 3)
  {
    shift(0x04, 3); 
  }
  if(min_2 == 4)
  {
    shift(0x04, 4); 
  }
  if(min_2 == 5)
  {
    shift(0x04, 5); 
  }
  if(min_2 == 6)
  {
    shift(0x04, 6); 
  }
  if(min_2 == 7)
  {
    shift(0x04, 7); 
  }
  if(min_2 == 8)
  {
    shift(0x04, 8); 
  }
  if(min_2 == 9)
  {
    shift(0x04, 9); 
  }/////////////////////////////////////end of first digit for minute
  
}

But, When I upload other code, it uploads like it should and works.

I have all the correct settings to upload, but I keep getting "Arduino: 1.8.11 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\DS3231_Serial_Easy2 (3).ino:14:13: error: redefinition of 'DS3231 rtc'

DS3231 rtc(SDA, SCL);

^~~

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\Nixie_tube_7_seg_clock.ino:12:9: note: 'DS3231 rtc' previously declared here

DS3231 rtc(SDA, SCL);

^~~

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\DS3231_Serial_Easy2 (3).ino: In function 'void setup()':

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\DS3231_Serial_Easy2 (3).ino:16:6: error: redefinition of 'void setup()'

void setup()

^~~~~

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\Nixie_tube_7_seg_clock.ino:57:6: note: 'void setup()' previously defined here

void setup() {

^~~~~

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\DS3231_Serial_Easy2 (3).ino: In function 'void loop()':

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\DS3231_Serial_Easy2 (3).ino:32:6: error: redefinition of 'void loop()'

void loop()

^~~~

C:\Users\RapidBoss08\Downloads\Nixie_tube_7_seg_clock (1)\Nixie_tube_7_seg_clock\Nixie_tube_7_seg_clock.ino:89:6: note: 'void loop()' previously defined here

void loop() {

^~~~

exit status 1
Error compiling for board Arduino Nano.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
"

Is it a problem with the code? Am I doing something wrong? I don't believe I have a clone, but I wouldn't know how to check. Here is where I bought my Nano: https://www.amazon.com/gp/product/B07C7WKCCV/ref=ppx_yo_dt_b_asin_image_o04_s00?ie=UTF8&psc=1

I bought it January 5th, 2020 and I could upload the ds3231 code (Second code) when I had it on the Atmega328p (Old Bootloader) setting. I really appreciate your help. Let me know if I didn't include something. Thanks so much!

Are you attempting to compile all the code in your downloads directory:
C:\Users\RapidBoss08\Downloads. . .
Which has probably got lots of duplicates in it.

Thanks for the reply! I went into my downloads and cleared all duplicates of code and zips of code. I extracted from the original, and made a completely new folder and put the code in there. It still didn’t compile, and I got this message:

Arduino: 1.8.11 (Windows 10), Board: “Arduino Nano, ATmega328P (Old Bootloader)”

c:\program files (x86)\arduino\hardware\tools\avr\bin…/lib/gcc/avr/7.3.0/…/…/…/…/avr/bin/ar.exe: unable to rename ‘core\core.a’; reason: Permission denied

exit status 1
Error compiling for board Arduino Nano.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

I verified it and tried again, and it worked!

Thanks so much dude! You are the best!

Ok, so it uploads, but I have another question: Can I upload more than one script (2 in my case) to the Nano? I have to upload the first script that runs the leds and the max7219 and all that, but I also have to run the ds3231 script so it can feed the time to the first script. Is this possible? Do I have to combine the scripts? Thanks again! I seriously appreciate you guys!

You have to combine them.

One of the 2 scripts (The DS3231 Time Script) is part of a library. Here it is:

// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS3231-library to 
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231:  SDA pin   -> Arduino Analog 4 or the dedicated SDA pin
//          SCL pin   -> Arduino Analog 5 or the dedicated SCL pin
//
// Arduino Leonardo:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 2 or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 3 or the dedicated SCL pin
//
// Arduino Mega:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 21 (SCL) or the dedicated SCL pin
//
// Arduino Due:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
//          SCL pin   -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
//
// The internal pull-up resistors will be activated when using the 
// hardware I2C interfaces.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access 
// to the pins used, and you will also have to use appropriate, external
// pull-up resistors on the data and clock signals.
//

#include <DS3231.h>

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}
  
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(SUNDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(17, 55, 55);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(19, 4, 2020);   // Set the date to January 1st, 2014
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

Is that an issue? The first line of actual code says to include that library, and the other script isn’t part of the library… I probably don’t know what I am talking about at all, but does it matter if one is part of a library?

It is not very clear what you mean here.
You have a file Nixie_tube_7_seg_clock.ino and you are talking about a library. Have you also been supplied with a .h file and a .cpp file ? In that case, all 3 files should be in the same sketch folder and the compiler (linker) will automatically combine them.
If not, or you have further problems, then attach to your next post (as files) all the code you are attempting to combine so it is clearer what you want to do.

Here is what I have:

https://www.electronoobs.com/images/Arduino/tut_47/Nixie_tube_7_seg_clock.zip

https://www.electronoobs.com/eng_arduino_ds3231.php

The first is the script for the leds. The second is for the Real Time Clock. If you go into the zip for the second, the actual script I am using is DS3231.zip>DS3231>examples>Arduino>DS3231_Serial_Easy>DS3231_Serial_Easy.ino (The RTC Script) The code in that script says that I have to include the library, and the whole zip is the library, I think. So I am confused as to how I put everything in a folder. If you go to DS3231.zip>DS3231 and then in there are is a .h and a .cpp file. Do I take those out of there and then put in the folder where the actual script is, and then put in the first script for the leds, the Nixie tube one? That would make both scripts be in a folder and it would have .h and .cpp files. I hope everything I just said makes sense...I think I may be getting it a little, but I'm unsure. Thanks!

This:
https://www.electronoobs.com/images/Arduino/tut_47/Nixie_tube_7_seg_clock.zip
contains the sketch: Nixie_tube_7_seg_clock.ino and nothing else.

This:
https://www.electronoobs.com/eng_arduino_ds3231.php
references a zip file which has to be added to your standard Arduino library folder and makes the DS3231 functions available to your sketch. Now when then a sketch has the statement #include <DS3231.h>, the IDE knows where to find it.

The instructions for installing this DS3231 library are here:

  1. Open Arduino IDE
  2. click on Sketch in the top menu bar
  3. click on the menu point include library
  4. click on the menu point add .zip library
  5. locate the .zip file that you have just downloaded from https://www.electronoobs.com/eng_arduino_ds3231.php and open it.
    Now the DS3231 library should be installed.

I have the library installed, but I still need to upload the .ino code in Serial Easy because that code sets the time. I also have to upload the nixie tube code. So how do I put those in a sketch folder? In electronoobs video, he just uploaded the ds3231 code, and then just went right over and uploaded the nixie tube code. I'm pretty sure uploading code after uploading code overwrites the first code. I am so confused. Sorry.

OK. Good that you have that DS3231 library installed.

Now it looks like you have to load this sketch onto your device. You have to hack the times so that it updates the real time clock with the correct time. Here is the URL but the results look odd: https://www.electronoobs.com/eng_arduino_tut47_code2.php

Anyway, once you have set the time on the realtime clock module, you then overwrite that time setting sketch (you don't need it anymore) with the final sketch: Nixie_tube_7_seg_clock.ino which drives the Nixies.

To better understand what I mean, watch his video from about 7:44 to about 9:14.

Video: DIY clock | Homemade 7 segments "nixie" tubes - YouTube

Based on what he did, I guess maybe they dont have to be together? Idk.

OHHHH. ok. Ill try that. I understand now. THANKS!!!

It worked great! Thank you so so much! My project is really coming together!

Publish a picture of it in the forum's exhibition gallery when it is finished. I've also been interested in making a 7 segment type clock using those elements out of standard household LED light bulbs. I'm curious about the choice of light bulbs and the current consumption.

As in, 120VAC household lights? (or maybe 220V)

I will definitely do that. I will also post a video of it showing all its features. Cant wait! :slight_smile: I could also show you my setup and all that if you need it if you make a clock as well.

If you would be using ac bulbs you would probably need some sort of transformer or actual power supply, mosfets, relays, and other stuff like that, but I am not sure.