DS3231RTC in combin...
 
Notifications
Clear all

DS3231RTC in combination with 8 MAX7219

2 Posts
1 Users
0 Reactions
236 Views
(@michel)
Member
Joined: 1 month ago
Posts: 11
Topic starter  

Finally....:-).

After 'burning' two Nano's and a dozen MAX7219 I finally understood how to do proper wiring and coding. Got my self a clock now ;-). It's all fed by an old iPhone charger which provides a stable 5V.  Couldn't find an easy connector to connect the displays, so I had to use wiring. If anyone has a  suggestion, that would be very much appreciated.

Now that I understand how I can manipulate the clock output, I will use that knowledge for trend analysis on my first weather station.

Greetings to you all!

 

/*
This small project connects an Arduino Nano to an Adafruit DS3231 Real Time Clock and eight 8x8 LED matrices.
It's basic, no fancy shifting, it just does what it has to do: presenting time.
The DS3231 uses a back-up battery, so you can power it off, keeping its internal clock running.
Once switched on, it immediately shows accurate time.
Power consumption is 350 mW. At 5V input voltage the maximum measured current was never more than 70mA.
However, when powered up, the displays are initialized and most of the LEDS are briefly fired up at maximum intensity.
There might be a considerable power spike especially using eight matrices.
So always connect the matrices to a separte power supply or you will risc blowing up the ports on your Nano.
*/

#include <Wire.h>

#include <DS3231.h>
//Create the clock
DS3231 clock;
RTCDateTime dt;

#include "LedControl.h"
/*Basic set up for eight- 8x8 LED matrices and the MAX 7219 driver.
Pin 12 is connected to DataIn (orange).
Pin 11 is connected to CS (yellow).
Pin 10 is connected to CLK (purple).
Connecting the pins this way implies the same pin order on both the Nano and the LED modules.
For me this implied les 'thinking' (and faults) when wiring the project.
I even glued several jumper wires together for this purpose: orange-yellow-purple.
Works for me :-).
Pay attention when using the LedControl statement, since the expected sequence of the pins is: DataIn, CLK, CS!
'maxDisplay' indicates the number of 8x8 matrices, in this case 8.
*/
const int maxDisplay = 8;
LedControl lc=LedControl(12,10,11,maxDisplay);

//Variables
int baudrate = 9600;
int delayT=500;//Delaytime
int i;

int numDisplay;//Matrix to be switched on /off. The first matrix has number 0.
int intensDisplay=0;//Intensity of the display, even 0 will produce light!
int hour;
int hourdigit1;
int hourdigit2;
int minute;
int minutedigit1;
int minutedigit2;
int second;
int secondOld = 0;//used for convenience: only display new values each second
int seconddigit1;
int seconddigit2;

//Digits normal horizontal orientation
byte arrayDigit[10][8]=
{
{0x00, 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38}, // 0
{0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x18, 0x10}, // 1
{0x00, 0x7C, 0x08, 0x10, 0x20, 0x40, 0x44, 0x38}, // 2
{0x00, 0x38, 0x44, 0x40, 0x30, 0x40, 0x44, 0x38}, // 3
{0x00, 0x20, 0x20, 0x7C, 0x24, 0x28, 0x30, 0x20}, // 4
{0x00, 0x38, 0x44, 0x40, 0x7C, 0x04, 0x04, 0x7C}, // 5
{0x00, 0x38, 0x44, 0x44, 0x3C, 0x04, 0x44, 0x38}, // 6
{0x00, 0x08, 0x08, 0x08, 0x10, 0x20, 0x40, 0x7C}, // 7
{0x00, 0x38, 0x44, 0x44, 0x28, 0x44, 0x44, 0x38}, // 8
{0x00, 0x38, 0x44, 0x40, 0x78, 0x44, 0x44, 0x38} // 9
};

/*
Digits with a separation mark in front of them.
Use these in addition to the normal digits if you want to use six in stead of eight matrices.
Use one of these digits as the first digit for minutes and seconds.
*/
/*
byte arrayDigitSpecial[10][8]=
{
{0x00, 0x38, 0x44, 0x45, 0x45, 0x44, 0x44, 0x38},
{0x00, 0x38, 0x10, 0x11, 0x11, 0x10, 0x18, 0x10},
{0x00, 0x7C, 0x08, 0x11, 0x21, 0x40, 0x44, 0x38},
{0x00, 0x38, 0x44, 0x41, 0x31, 0x40, 0x44, 0x38},
{0x00, 0x20, 0x20, 0x7D, 0x25, 0x28, 0x30, 0x20},
{0x00, 0x38, 0x44, 0x41, 0x7D, 0x04, 0x04, 0x7C},
{0x00, 0x38, 0x44, 0x44, 0x3D, 0x04, 0x44, 0x38},
{0x00, 0x08, 0x08, 0x09, 0x11, 0x20, 0x40, 0x7C},
{0x00, 0x38, 0x44, 0x45, 0x29, 0x44, 0x44, 0x38},
{0x00, 0x38, 0x44, 0x41, 0x79, 0x44, 0x44, 0x38}
};
*/

/*
Digits vertical orientation, hours on top, seconds at the bottom
Use these digits if you want a vertical clock display

byte arrayDigit[10][8]=
{
{0x00, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00},
{0x00, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00},
{0x00, 0x00, 0x42, 0x61, 0x51, 0x49, 0x46, 0x00},
{0x00, 0x00, 0x22, 0x41, 0x49, 0x49, 0x36, 0x00},
{0x00, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00},
{0x00, 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00},
{0x00, 0x00, 0x3E, 0x49, 0x49, 0x49, 0x30, 0x00},
{0x00, 0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00},
{0x00, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00},
{0x00, 0x00, 0x06, 0x49, 0x49, 0x49, 0x3E, 0x00}
};
*/

/*
Separte separtion marks between hours/minutes and minutes/seconds.
Use the one you like, or create your own.
*/

byte arrayDigitSeparation[5][8]=
{
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // no separate separtion marks
{0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00}, // one square dot
{0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00} // two square dots
};

void setup()
{
//Start serial monitor
Serial.begin(baudrate);

//Start DS3231
Serial.println("Initialize DS3231");;
clock.begin();

// Set sketch compiling time
//clock.setDateTime(__DATE__, __TIME__);

//Start MAX72XX
for(numDisplay=0; numDisplay<maxDisplay; numDisplay=numDisplay+1)
{
//Wake up MAX7219
lc.shutdown(numDisplay,false);
//Set intensity 0 en 1 are sufficient
lc.setIntensity(numDisplay,intensDisplay);
//Clear display
lc.clearDisplay(numDisplay);
}
delay(delayT);
}

void loop()
{
dt = clock.getDateTime();
hour=dt.hour;
hourdigit1=round(hour/10);
hourdigit2=hour%10;
minute=dt.minute;
minutedigit1=round(minute/10);
minutedigit2=minute%10;
second=dt.second;
seconddigit1=round(second/10);
seconddigit2=second%10;

/*
*/
if(second!=secondOld)
{
secondOld=second;
Serial.print("Raw data: ");
Serial.print(dt.year); Serial.print("-");
Serial.print(dt.month); Serial.print("-");
Serial.print(dt.day); Serial.print(" ");
Serial.print(dt.hour); Serial.print(":");
Serial.print(dt.minute); Serial.print(":");
Serial.print(dt.second); Serial.println("");

//Write values to matrices
writeDigit(hourdigit1,0);
writeDigit(hourdigit2,1);
writeDigitSeparation(2,2);
writeDigit(minutedigit1,3);
writeDigit(minutedigit2,4);
writeDigitSeparation(2,5);
writeDigit(seconddigit1,6);
writeDigit(seconddigit2,7);
}

}

void writeDigit(int j, int m)
{
for(i=0; i<=7; i=i+1)
{
lc.setRow(m,i,arrayDigit[j][i]);
}
}

//To be used for vertical orientation
/*
void writeDigitSpecial(int j, int m)
{
for(i=0; i<=7; i=i+1)
{
lc.setRow(m,i,arrayDigitSpecial[j][i]);
}
}
*/

void writeDigitSeparation(int j, int m)
{
for(i=0; i<=7; i=i+1)
{
lc.setRow(m,i,arrayDigitSeparation[j][i]);
}
}


This topic was modified 1 month ago 2 times by Michel

   
Quote
(@michel)
Member
Joined: 1 month ago
Posts: 11
Topic starter  

Don't know why, but somehow the pictures didn't show up. So I hope this will work...

Blue colour clock
Connection between two displays 2
Connection between two displays 1


   
ReplyQuote